Rename _ol_source_TileUTFGrid_ to UTFGrid
This commit is contained in:
@@ -3,7 +3,7 @@ import _ol_Overlay_ from '../src/ol/Overlay.js';
|
|||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
import TileLayer from '../src/ol/layer/Tile.js';
|
import TileLayer from '../src/ol/layer/Tile.js';
|
||||||
import TileJSON from '../src/ol/source/TileJSON.js';
|
import TileJSON from '../src/ol/source/TileJSON.js';
|
||||||
import _ol_source_TileUTFGrid_ from '../src/ol/source/TileUTFGrid.js';
|
import UTFGrid from '../src/ol/source/TileUTFGrid.js';
|
||||||
|
|
||||||
var key = 'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
var key = 'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ var mapLayer = new TileLayer({
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var gridSource = new _ol_source_TileUTFGrid_({
|
var gridSource = new UTFGrid({
|
||||||
url: 'https://api.tiles.mapbox.com/v4/mapbox.geography-class.json?secure&access_token=' + key
|
url: 'https://api.tiles.mapbox.com/v4/mapbox.geography-class.json?secure&access_token=' + key
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import _ol_tilegrid_ from '../tilegrid.js';
|
|||||||
* @param {olx.source.TileUTFGridOptions} options Source options.
|
* @param {olx.source.TileUTFGridOptions} options Source options.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
var _ol_source_TileUTFGrid_ = function(options) {
|
var UTFGrid = function(options) {
|
||||||
TileSource.call(this, {
|
TileSource.call(this, {
|
||||||
projection: getProjection('EPSG:3857'),
|
projection: getProjection('EPSG:3857'),
|
||||||
state: SourceState.LOADING
|
state: SourceState.LOADING
|
||||||
@@ -74,14 +74,14 @@ var _ol_source_TileUTFGrid_ = function(options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inherits(_ol_source_TileUTFGrid_, TileSource);
|
inherits(UTFGrid, TileSource);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {Event} event The load event.
|
* @param {Event} event The load event.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.onXHRLoad_ = function(event) {
|
UTFGrid.prototype.onXHRLoad_ = function(event) {
|
||||||
var client = /** @type {XMLHttpRequest} */ (event.target);
|
var client = /** @type {XMLHttpRequest} */ (event.target);
|
||||||
// status will be 0 for file:// urls
|
// status will be 0 for file:// urls
|
||||||
if (!client.status || client.status >= 200 && client.status < 300) {
|
if (!client.status || client.status >= 200 && client.status < 300) {
|
||||||
@@ -103,7 +103,7 @@ _ol_source_TileUTFGrid_.prototype.onXHRLoad_ = function(event) {
|
|||||||
* @private
|
* @private
|
||||||
* @param {Event} event The error event.
|
* @param {Event} event The error event.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.onXHRError_ = function(event) {
|
UTFGrid.prototype.onXHRError_ = function(event) {
|
||||||
this.handleTileJSONError();
|
this.handleTileJSONError();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ _ol_source_TileUTFGrid_.prototype.onXHRError_ = function(event) {
|
|||||||
* @return {string|undefined} The template from TileJSON.
|
* @return {string|undefined} The template from TileJSON.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.getTemplate = function() {
|
UTFGrid.prototype.getTemplate = function() {
|
||||||
return this.template_;
|
return this.template_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ _ol_source_TileUTFGrid_.prototype.getTemplate = function() {
|
|||||||
* The tile data is requested if not yet loaded.
|
* The tile data is requested if not yet loaded.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.forDataAtCoordinateAndResolution = function(
|
UTFGrid.prototype.forDataAtCoordinateAndResolution = function(
|
||||||
coordinate, resolution, callback, opt_request) {
|
coordinate, resolution, callback, opt_request) {
|
||||||
if (this.tileGrid) {
|
if (this.tileGrid) {
|
||||||
var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
|
var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
|
||||||
@@ -152,7 +152,7 @@ _ol_source_TileUTFGrid_.prototype.forDataAtCoordinateAndResolution = function(
|
|||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.handleTileJSONError = function() {
|
UTFGrid.prototype.handleTileJSONError = function() {
|
||||||
this.setState(SourceState.ERROR);
|
this.setState(SourceState.ERROR);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ _ol_source_TileUTFGrid_.prototype.handleTileJSONError = function() {
|
|||||||
* @protected
|
* @protected
|
||||||
* @param {TileJSON} tileJSON Tile JSON.
|
* @param {TileJSON} tileJSON Tile JSON.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.handleTileJSONResponse = function(tileJSON) {
|
UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
|
||||||
|
|
||||||
var epsg4326Projection = getProjection('EPSG:4326');
|
var epsg4326Projection = getProjection('EPSG:4326');
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ _ol_source_TileUTFGrid_.prototype.handleTileJSONResponse = function(tileJSON) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
||||||
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||||
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
||||||
@@ -222,7 +222,7 @@ _ol_source_TileUTFGrid_.prototype.getTile = function(z, x, y, pixelRatio, projec
|
|||||||
var urlTileCoord =
|
var urlTileCoord =
|
||||||
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
||||||
var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
||||||
var tile = new _ol_source_TileUTFGrid_.Tile_(
|
var tile = new UTFGrid.Tile_(
|
||||||
tileCoord,
|
tileCoord,
|
||||||
tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY,
|
tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY,
|
||||||
tileUrl !== undefined ? tileUrl : '',
|
tileUrl !== undefined ? tileUrl : '',
|
||||||
@@ -238,7 +238,7 @@ _ol_source_TileUTFGrid_.prototype.getTile = function(z, x, y, pixelRatio, projec
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.useTile = function(z, x, y) {
|
UTFGrid.prototype.useTile = function(z, x, y) {
|
||||||
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
||||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||||
this.tileCache.get(tileCoordKey);
|
this.tileCache.get(tileCoordKey);
|
||||||
@@ -257,7 +257,7 @@ _ol_source_TileUTFGrid_.prototype.useTile = function(z, x, y) {
|
|||||||
* @param {boolean} jsonp Load the tile as a script.
|
* @param {boolean} jsonp Load the tile as a script.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_ = function(tileCoord, state, src, extent, preemptive, jsonp) {
|
UTFGrid.Tile_ = function(tileCoord, state, src, extent, preemptive, jsonp) {
|
||||||
|
|
||||||
_ol_Tile_.call(this, tileCoord, state);
|
_ol_Tile_.call(this, tileCoord, state);
|
||||||
|
|
||||||
@@ -305,14 +305,14 @@ _ol_source_TileUTFGrid_.Tile_ = function(tileCoord, state, src, extent, preempti
|
|||||||
this.jsonp_ = jsonp;
|
this.jsonp_ = jsonp;
|
||||||
|
|
||||||
};
|
};
|
||||||
inherits(_ol_source_TileUTFGrid_.Tile_, _ol_Tile_);
|
inherits(UTFGrid.Tile_, _ol_Tile_);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the image element for this tile.
|
* Get the image element for this tile.
|
||||||
* @return {Image} Image.
|
* @return {Image} Image.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.getImage = function() {
|
UTFGrid.Tile_.prototype.getImage = function() {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.getImage = function() {
|
|||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @return {*} The data.
|
* @return {*} The data.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.getData = function(coordinate) {
|
UTFGrid.Tile_.prototype.getData = function(coordinate) {
|
||||||
if (!this.grid_ || !this.keys_) {
|
if (!this.grid_ || !this.keys_) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.getData = function(coordinate) {
|
|||||||
* The tile data is requested if not yet loaded.
|
* The tile data is requested if not yet loaded.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
|
UTFGrid.Tile_.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
|
||||||
if (this.state == TileState.IDLE && opt_request === true) {
|
if (this.state == TileState.IDLE && opt_request === true) {
|
||||||
_ol_events_.listenOnce(this, EventType.CHANGE, function(e) {
|
_ol_events_.listenOnce(this, EventType.CHANGE, function(e) {
|
||||||
callback.call(opt_this, this.getData(coordinate));
|
callback.call(opt_this, this.getData(coordinate));
|
||||||
@@ -390,7 +390,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.forDataAtCoordinate = function(coordinat
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.getKey = function() {
|
UTFGrid.Tile_.prototype.getKey = function() {
|
||||||
return this.src_;
|
return this.src_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.getKey = function() {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.handleError_ = function() {
|
UTFGrid.Tile_.prototype.handleError_ = function() {
|
||||||
this.state = TileState.ERROR;
|
this.state = TileState.ERROR;
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
};
|
||||||
@@ -408,7 +408,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.handleError_ = function() {
|
|||||||
* @param {!UTFGridJSON} json UTFGrid data.
|
* @param {!UTFGridJSON} json UTFGrid data.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.handleLoad_ = function(json) {
|
UTFGrid.Tile_.prototype.handleLoad_ = function(json) {
|
||||||
this.grid_ = json.grid;
|
this.grid_ = json.grid;
|
||||||
this.keys_ = json.keys;
|
this.keys_ = json.keys;
|
||||||
this.data_ = json.data;
|
this.data_ = json.data;
|
||||||
@@ -421,7 +421,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.handleLoad_ = function(json) {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.loadInternal_ = function() {
|
UTFGrid.Tile_.prototype.loadInternal_ = function() {
|
||||||
if (this.state == TileState.IDLE) {
|
if (this.state == TileState.IDLE) {
|
||||||
this.state = TileState.LOADING;
|
this.state = TileState.LOADING;
|
||||||
if (this.jsonp_) {
|
if (this.jsonp_) {
|
||||||
@@ -442,7 +442,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.loadInternal_ = function() {
|
|||||||
* @private
|
* @private
|
||||||
* @param {Event} event The load event.
|
* @param {Event} event The load event.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.onXHRLoad_ = function(event) {
|
UTFGrid.Tile_.prototype.onXHRLoad_ = function(event) {
|
||||||
var client = /** @type {XMLHttpRequest} */ (event.target);
|
var client = /** @type {XMLHttpRequest} */ (event.target);
|
||||||
// status will be 0 for file:// urls
|
// status will be 0 for file:// urls
|
||||||
if (!client.status || client.status >= 200 && client.status < 300) {
|
if (!client.status || client.status >= 200 && client.status < 300) {
|
||||||
@@ -464,7 +464,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.onXHRLoad_ = function(event) {
|
|||||||
* @private
|
* @private
|
||||||
* @param {Event} event The error event.
|
* @param {Event} event The error event.
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.onXHRError_ = function(event) {
|
UTFGrid.Tile_.prototype.onXHRError_ = function(event) {
|
||||||
this.handleError_();
|
this.handleError_();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -472,9 +472,9 @@ _ol_source_TileUTFGrid_.Tile_.prototype.onXHRError_ = function(event) {
|
|||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.Tile_.prototype.load = function() {
|
UTFGrid.Tile_.prototype.load = function() {
|
||||||
if (this.preemptive_) {
|
if (this.preemptive_) {
|
||||||
this.loadInternal_();
|
this.loadInternal_();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export default _ol_source_TileUTFGrid_;
|
export default UTFGrid;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js';
|
import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js';
|
||||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||||
import _ol_source_TileUTFGrid_ from '../../../../src/ol/source/TileUTFGrid.js';
|
import UTFGrid from '../../../../src/ol/source/TileUTFGrid.js';
|
||||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ describe('ol.source.TileUTFGrid', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function getTileUTFGrid() {
|
function getTileUTFGrid() {
|
||||||
return new _ol_source_TileUTFGrid_({
|
return new UTFGrid({
|
||||||
url: url
|
url: url
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -37,28 +37,28 @@ describe('ol.source.TileUTFGrid', function() {
|
|||||||
|
|
||||||
it('needs to be constructed with url option', function() {
|
it('needs to be constructed with url option', function() {
|
||||||
|
|
||||||
var source = new _ol_source_TileUTFGrid_({url: url});
|
var source = new UTFGrid({url: url});
|
||||||
expect(source).to.be.an(_ol_source_TileUTFGrid_);
|
expect(source).to.be.an(UTFGrid);
|
||||||
expect(source).to.be.an(TileSource);
|
expect(source).to.be.an(TileSource);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
// no options: will throw
|
// no options: will throw
|
||||||
return new _ol_source_TileUTFGrid_();
|
return new UTFGrid();
|
||||||
}).to.throwException();
|
}).to.throwException();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
// no url-option: will throw
|
// no url-option: will throw
|
||||||
return new _ol_source_TileUTFGrid_({});
|
return new UTFGrid({});
|
||||||
}).to.throwException();
|
}).to.throwException();
|
||||||
|
|
||||||
expect(getTileUTFGrid()).to.be.an(_ol_source_TileUTFGrid_);
|
expect(getTileUTFGrid()).to.be.an(UTFGrid);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('change event (ready)', function() {
|
describe('change event (ready)', function() {
|
||||||
it('is fired when the source is ready', function(done) {
|
it('is fired when the source is ready', function(done) {
|
||||||
var source = new _ol_source_TileUTFGrid_({
|
var source = new UTFGrid({
|
||||||
url: url
|
url: url
|
||||||
});
|
});
|
||||||
expect(source.getState()).to.be('loading');
|
expect(source.getState()).to.be('loading');
|
||||||
@@ -75,7 +75,7 @@ describe('ol.source.TileUTFGrid', function() {
|
|||||||
|
|
||||||
describe('change event (error)', function(done) {
|
describe('change event (error)', function(done) {
|
||||||
it('is fired when the source fails to initialize', function(done) {
|
it('is fired when the source fails to initialize', function(done) {
|
||||||
var source = new _ol_source_TileUTFGrid_({
|
var source = new UTFGrid({
|
||||||
url: 'Bogus UTFGrid URL'
|
url: 'Bogus UTFGrid URL'
|
||||||
});
|
});
|
||||||
expect(source.getState()).to.be('loading');
|
expect(source.getState()).to.be('loading');
|
||||||
@@ -228,7 +228,7 @@ describe('ol.source.TileUTFGrid', function() {
|
|||||||
var urlTileCoord =
|
var urlTileCoord =
|
||||||
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
||||||
var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
||||||
var tile = new _ol_source_TileUTFGrid_.Tile_(
|
var tile = new UTFGrid.Tile_(
|
||||||
tileCoord,
|
tileCoord,
|
||||||
tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY
|
tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY
|
||||||
tileUrl !== undefined ? tileUrl : '',
|
tileUrl !== undefined ? tileUrl : '',
|
||||||
|
|||||||
Reference in New Issue
Block a user