diff --git a/examples/tileutfgrid.js b/examples/tileutfgrid.js index 5b5cd0af8f..95ed229faf 100644 --- a/examples/tileutfgrid.js +++ b/examples/tileutfgrid.js @@ -3,7 +3,7 @@ import _ol_Overlay_ from '../src/ol/Overlay.js'; import View from '../src/ol/View.js'; import TileLayer from '../src/ol/layer/Tile.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'; @@ -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 }); diff --git a/src/ol/source/TileUTFGrid.js b/src/ol/source/TileUTFGrid.js index 9533bd4ad5..fd44237902 100644 --- a/src/ol/source/TileUTFGrid.js +++ b/src/ol/source/TileUTFGrid.js @@ -25,7 +25,7 @@ import _ol_tilegrid_ from '../tilegrid.js'; * @param {olx.source.TileUTFGridOptions} options Source options. * @api */ -var _ol_source_TileUTFGrid_ = function(options) { +var UTFGrid = function(options) { TileSource.call(this, { projection: getProjection('EPSG:3857'), state: SourceState.LOADING @@ -74,14 +74,14 @@ var _ol_source_TileUTFGrid_ = function(options) { } }; -inherits(_ol_source_TileUTFGrid_, TileSource); +inherits(UTFGrid, TileSource); /** * @private * @param {Event} event The load event. */ -_ol_source_TileUTFGrid_.prototype.onXHRLoad_ = function(event) { +UTFGrid.prototype.onXHRLoad_ = function(event) { var client = /** @type {XMLHttpRequest} */ (event.target); // status will be 0 for file:// urls if (!client.status || client.status >= 200 && client.status < 300) { @@ -103,7 +103,7 @@ _ol_source_TileUTFGrid_.prototype.onXHRLoad_ = function(event) { * @private * @param {Event} event The error event. */ -_ol_source_TileUTFGrid_.prototype.onXHRError_ = function(event) { +UTFGrid.prototype.onXHRError_ = function(event) { this.handleTileJSONError(); }; @@ -113,7 +113,7 @@ _ol_source_TileUTFGrid_.prototype.onXHRError_ = function(event) { * @return {string|undefined} The template from TileJSON. * @api */ -_ol_source_TileUTFGrid_.prototype.getTemplate = function() { +UTFGrid.prototype.getTemplate = function() { return this.template_; }; @@ -129,7 +129,7 @@ _ol_source_TileUTFGrid_.prototype.getTemplate = function() { * The tile data is requested if not yet loaded. * @api */ -_ol_source_TileUTFGrid_.prototype.forDataAtCoordinateAndResolution = function( +UTFGrid.prototype.forDataAtCoordinateAndResolution = function( coordinate, resolution, callback, opt_request) { if (this.tileGrid) { var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution( @@ -152,7 +152,7 @@ _ol_source_TileUTFGrid_.prototype.forDataAtCoordinateAndResolution = function( /** * @protected */ -_ol_source_TileUTFGrid_.prototype.handleTileJSONError = function() { +UTFGrid.prototype.handleTileJSONError = function() { this.setState(SourceState.ERROR); }; @@ -162,7 +162,7 @@ _ol_source_TileUTFGrid_.prototype.handleTileJSONError = function() { * @protected * @param {TileJSON} tileJSON Tile JSON. */ -_ol_source_TileUTFGrid_.prototype.handleTileJSONResponse = function(tileJSON) { +UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) { var epsg4326Projection = getProjection('EPSG:4326'); @@ -213,7 +213,7 @@ _ol_source_TileUTFGrid_.prototype.handleTileJSONResponse = function(tileJSON) { /** * @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); if (this.tileCache.containsKey(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 = this.getTileCoordForTileUrlFunction(tileCoord, projection); var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); - var tile = new _ol_source_TileUTFGrid_.Tile_( + var tile = new UTFGrid.Tile_( tileCoord, tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY, tileUrl !== undefined ? tileUrl : '', @@ -238,7 +238,7 @@ _ol_source_TileUTFGrid_.prototype.getTile = function(z, x, y, pixelRatio, projec /** * @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); if (this.tileCache.containsKey(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. * @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); @@ -305,14 +305,14 @@ _ol_source_TileUTFGrid_.Tile_ = function(tileCoord, state, src, extent, preempti this.jsonp_ = jsonp; }; -inherits(_ol_source_TileUTFGrid_.Tile_, _ol_Tile_); +inherits(UTFGrid.Tile_, _ol_Tile_); /** * Get the image element for this tile. * @return {Image} Image. */ -_ol_source_TileUTFGrid_.Tile_.prototype.getImage = function() { +UTFGrid.Tile_.prototype.getImage = function() { return null; }; @@ -322,7 +322,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.getImage = function() { * @param {ol.Coordinate} coordinate Coordinate. * @return {*} The data. */ -_ol_source_TileUTFGrid_.Tile_.prototype.getData = function(coordinate) { +UTFGrid.Tile_.prototype.getData = function(coordinate) { if (!this.grid_ || !this.keys_) { return null; } @@ -369,7 +369,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.getData = function(coordinate) { * The tile data is requested if not yet loaded. * @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) { _ol_events_.listenOnce(this, EventType.CHANGE, function(e) { callback.call(opt_this, this.getData(coordinate)); @@ -390,7 +390,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.forDataAtCoordinate = function(coordinat /** * @inheritDoc */ -_ol_source_TileUTFGrid_.Tile_.prototype.getKey = function() { +UTFGrid.Tile_.prototype.getKey = function() { return this.src_; }; @@ -398,7 +398,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.getKey = function() { /** * @private */ -_ol_source_TileUTFGrid_.Tile_.prototype.handleError_ = function() { +UTFGrid.Tile_.prototype.handleError_ = function() { this.state = TileState.ERROR; this.changed(); }; @@ -408,7 +408,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.handleError_ = function() { * @param {!UTFGridJSON} json UTFGrid data. * @private */ -_ol_source_TileUTFGrid_.Tile_.prototype.handleLoad_ = function(json) { +UTFGrid.Tile_.prototype.handleLoad_ = function(json) { this.grid_ = json.grid; this.keys_ = json.keys; this.data_ = json.data; @@ -421,7 +421,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.handleLoad_ = function(json) { /** * @private */ -_ol_source_TileUTFGrid_.Tile_.prototype.loadInternal_ = function() { +UTFGrid.Tile_.prototype.loadInternal_ = function() { if (this.state == TileState.IDLE) { this.state = TileState.LOADING; if (this.jsonp_) { @@ -442,7 +442,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.loadInternal_ = function() { * @private * @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); // status will be 0 for file:// urls if (!client.status || client.status >= 200 && client.status < 300) { @@ -464,7 +464,7 @@ _ol_source_TileUTFGrid_.Tile_.prototype.onXHRLoad_ = function(event) { * @private * @param {Event} event The error event. */ -_ol_source_TileUTFGrid_.Tile_.prototype.onXHRError_ = function(event) { +UTFGrid.Tile_.prototype.onXHRError_ = function(event) { this.handleError_(); }; @@ -472,9 +472,9 @@ _ol_source_TileUTFGrid_.Tile_.prototype.onXHRError_ = function(event) { /** * @override */ -_ol_source_TileUTFGrid_.Tile_.prototype.load = function() { +UTFGrid.Tile_.prototype.load = function() { if (this.preemptive_) { this.loadInternal_(); } }; -export default _ol_source_TileUTFGrid_; +export default UTFGrid; diff --git a/test/spec/ol/source/tileutfgrid.test.js b/test/spec/ol/source/tileutfgrid.test.js index 99b40ee2f7..c122e8ffd1 100644 --- a/test/spec/ol/source/tileutfgrid.test.js +++ b/test/spec/ol/source/tileutfgrid.test.js @@ -1,6 +1,6 @@ import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.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'; @@ -28,7 +28,7 @@ describe('ol.source.TileUTFGrid', function() { }); function getTileUTFGrid() { - return new _ol_source_TileUTFGrid_({ + return new UTFGrid({ url: url }); } @@ -37,28 +37,28 @@ describe('ol.source.TileUTFGrid', function() { it('needs to be constructed with url option', function() { - var source = new _ol_source_TileUTFGrid_({url: url}); - expect(source).to.be.an(_ol_source_TileUTFGrid_); + var source = new UTFGrid({url: url}); + expect(source).to.be.an(UTFGrid); expect(source).to.be.an(TileSource); expect(function() { // no options: will throw - return new _ol_source_TileUTFGrid_(); + return new UTFGrid(); }).to.throwException(); expect(function() { // no url-option: will throw - return new _ol_source_TileUTFGrid_({}); + return new UTFGrid({}); }).to.throwException(); - expect(getTileUTFGrid()).to.be.an(_ol_source_TileUTFGrid_); + expect(getTileUTFGrid()).to.be.an(UTFGrid); }); }); describe('change event (ready)', function() { it('is fired when the source is ready', function(done) { - var source = new _ol_source_TileUTFGrid_({ + var source = new UTFGrid({ url: url }); expect(source.getState()).to.be('loading'); @@ -75,7 +75,7 @@ describe('ol.source.TileUTFGrid', function() { describe('change event (error)', 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' }); expect(source.getState()).to.be('loading'); @@ -228,7 +228,7 @@ describe('ol.source.TileUTFGrid', function() { var urlTileCoord = this.getTileCoordForTileUrlFunction(tileCoord, projection); var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); - var tile = new _ol_source_TileUTFGrid_.Tile_( + var tile = new UTFGrid.Tile_( tileCoord, tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY tileUrl !== undefined ? tileUrl : '',