Use class method syntax instead of .prototype.method = function
This commit is contained in:
@@ -76,178 +76,176 @@ export class CustomTile extends Tile {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Get the image element for this tile.
|
||||||
|
* @return {HTMLImageElement} Image.
|
||||||
/**
|
*/
|
||||||
* Get the image element for this tile.
|
getImage() {
|
||||||
* @return {HTMLImageElement} Image.
|
|
||||||
*/
|
|
||||||
CustomTile.prototype.getImage = function() {
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously returns data at given coordinate (if available).
|
|
||||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
|
||||||
* @return {*} The data.
|
|
||||||
*/
|
|
||||||
CustomTile.prototype.getData = function(coordinate) {
|
|
||||||
if (!this.grid_ || !this.keys_) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const xRelative = (coordinate[0] - this.extent_[0]) /
|
|
||||||
(this.extent_[2] - this.extent_[0]);
|
|
||||||
const yRelative = (coordinate[1] - this.extent_[1]) /
|
|
||||||
(this.extent_[3] - this.extent_[1]);
|
|
||||||
|
|
||||||
const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)];
|
|
||||||
|
|
||||||
if (typeof row !== 'string') {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = row.charCodeAt(Math.floor(xRelative * row.length));
|
|
||||||
if (code >= 93) {
|
|
||||||
code--;
|
|
||||||
}
|
|
||||||
if (code >= 35) {
|
|
||||||
code--;
|
|
||||||
}
|
|
||||||
code -= 32;
|
|
||||||
|
|
||||||
let data = null;
|
/**
|
||||||
if (code in this.keys_) {
|
* Synchronously returns data at given coordinate (if available).
|
||||||
const id = this.keys_[code];
|
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||||
if (this.data_ && id in this.data_) {
|
* @return {*} The data.
|
||||||
data = this.data_[id];
|
*/
|
||||||
} else {
|
getData(coordinate) {
|
||||||
data = id;
|
if (!this.grid_ || !this.keys_) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
const xRelative = (coordinate[0] - this.extent_[0]) /
|
||||||
|
(this.extent_[2] - this.extent_[0]);
|
||||||
|
const yRelative = (coordinate[1] - this.extent_[1]) /
|
||||||
|
(this.extent_[3] - this.extent_[1]);
|
||||||
|
|
||||||
|
const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)];
|
||||||
|
|
||||||
|
if (typeof row !== 'string') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let code = row.charCodeAt(Math.floor(xRelative * row.length));
|
||||||
|
if (code >= 93) {
|
||||||
|
code--;
|
||||||
|
}
|
||||||
|
if (code >= 35) {
|
||||||
|
code--;
|
||||||
|
}
|
||||||
|
code -= 32;
|
||||||
|
|
||||||
|
let data = null;
|
||||||
|
if (code in this.keys_) {
|
||||||
|
const id = this.keys_[code];
|
||||||
|
if (this.data_ && id in this.data_) {
|
||||||
|
data = this.data_[id];
|
||||||
|
} else {
|
||||||
|
data = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the callback (synchronously by default) with the available data
|
* Calls the callback (synchronously by default) with the available data
|
||||||
* for given coordinate (or `null` if not yet loaded).
|
* for given coordinate (or `null` if not yet loaded).
|
||||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||||
* @param {function(this: T, *)} callback Callback.
|
* @param {function(this: T, *)} callback Callback.
|
||||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
* @param {T=} opt_this The object to use as `this` in the callback.
|
||||||
* @param {boolean=} opt_request If `true` the callback is always async.
|
* @param {boolean=} opt_request If `true` the callback is always async.
|
||||||
* The tile data is requested if not yet loaded.
|
* The tile data is requested if not yet loaded.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
CustomTile.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
|
forDataAtCoordinate(coordinate, callback, opt_this, opt_request) {
|
||||||
if (this.state == TileState.IDLE && opt_request === true) {
|
if (this.state == TileState.IDLE && opt_request === true) {
|
||||||
listenOnce(this, EventType.CHANGE, function(e) {
|
listenOnce(this, EventType.CHANGE, function(e) {
|
||||||
callback.call(opt_this, this.getData(coordinate));
|
|
||||||
}, this);
|
|
||||||
this.loadInternal_();
|
|
||||||
} else {
|
|
||||||
if (opt_request === true) {
|
|
||||||
setTimeout(function() {
|
|
||||||
callback.call(opt_this, this.getData(coordinate));
|
callback.call(opt_this, this.getData(coordinate));
|
||||||
}.bind(this), 0);
|
}, this);
|
||||||
|
this.loadInternal_();
|
||||||
} else {
|
} else {
|
||||||
callback.call(opt_this, this.getData(coordinate));
|
if (opt_request === true) {
|
||||||
|
setTimeout(function() {
|
||||||
|
callback.call(opt_this, this.getData(coordinate));
|
||||||
|
}.bind(this), 0);
|
||||||
|
} else {
|
||||||
|
callback.call(opt_this, this.getData(coordinate));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
CustomTile.prototype.getKey = function() {
|
getKey() {
|
||||||
return this.src_;
|
return this.src_;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
CustomTile.prototype.handleError_ = function() {
|
handleError_() {
|
||||||
this.state = TileState.ERROR;
|
this.state = TileState.ERROR;
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!UTFGridJSON} json UTFGrid data.
|
* @param {!UTFGridJSON} json UTFGrid data.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
CustomTile.prototype.handleLoad_ = function(json) {
|
handleLoad_(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;
|
||||||
|
|
||||||
this.state = TileState.EMPTY;
|
this.state = TileState.EMPTY;
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
CustomTile.prototype.loadInternal_ = function() {
|
loadInternal_() {
|
||||||
if (this.state == TileState.IDLE) {
|
if (this.state == TileState.IDLE) {
|
||||||
this.state = TileState.LOADING;
|
this.state = TileState.LOADING;
|
||||||
if (this.jsonp_) {
|
if (this.jsonp_) {
|
||||||
requestJSONP(this.src_, this.handleLoad_.bind(this),
|
requestJSONP(this.src_, this.handleLoad_.bind(this),
|
||||||
this.handleError_.bind(this));
|
this.handleError_.bind(this));
|
||||||
} else {
|
} else {
|
||||||
const client = new XMLHttpRequest();
|
const client = new XMLHttpRequest();
|
||||||
client.addEventListener('load', this.onXHRLoad_.bind(this));
|
client.addEventListener('load', this.onXHRLoad_.bind(this));
|
||||||
client.addEventListener('error', this.onXHRError_.bind(this));
|
client.addEventListener('error', this.onXHRError_.bind(this));
|
||||||
client.open('GET', this.src_);
|
client.open('GET', this.src_);
|
||||||
client.send();
|
client.send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {Event} event The load event.
|
* @param {Event} event The load event.
|
||||||
*/
|
*/
|
||||||
CustomTile.prototype.onXHRLoad_ = function(event) {
|
onXHRLoad_(event) {
|
||||||
const client = /** @type {XMLHttpRequest} */ (event.target);
|
const 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) {
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText));
|
response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
this.handleError_();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.handleLoad_(response);
|
||||||
|
} else {
|
||||||
this.handleError_();
|
this.handleError_();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
this.handleLoad_(response);
|
}
|
||||||
} else {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {Event} event The error event.
|
||||||
|
*/
|
||||||
|
onXHRError_(event) {
|
||||||
this.handleError_();
|
this.handleError_();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @override
|
||||||
* @param {Event} event The error event.
|
*/
|
||||||
*/
|
load() {
|
||||||
CustomTile.prototype.onXHRError_ = function(event) {
|
if (this.preemptive_) {
|
||||||
this.handleError_();
|
this.loadInternal_();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
CustomTile.prototype.load = function() {
|
|
||||||
if (this.preemptive_) {
|
|
||||||
this.loadInternal_();
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,178 +324,177 @@ class UTFGrid extends TileSource {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {Event} event The load event.
|
||||||
|
*/
|
||||||
|
onXHRLoad_(event) {
|
||||||
|
const client = /** @type {XMLHttpRequest} */ (event.target);
|
||||||
|
// status will be 0 for file:// urls
|
||||||
|
if (!client.status || client.status >= 200 && client.status < 300) {
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = /** @type {TileJSON} */(JSON.parse(client.responseText));
|
||||||
|
} catch (err) {
|
||||||
|
this.handleTileJSONError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.handleTileJSONResponse(response);
|
||||||
|
} else {
|
||||||
|
this.handleTileJSONError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {Event} event The error event.
|
||||||
|
*/
|
||||||
|
onXHRError_(event) {
|
||||||
|
this.handleTileJSONError();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the template from TileJSON.
|
||||||
|
* @return {string|undefined} The template from TileJSON.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getTemplate() {
|
||||||
|
return this.template_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the callback (synchronously by default) with the available data
|
||||||
|
* for given coordinate and resolution (or `null` if not yet loaded or
|
||||||
|
* in case of an error).
|
||||||
|
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||||
|
* @param {number} resolution Resolution.
|
||||||
|
* @param {function(*)} callback Callback.
|
||||||
|
* @param {boolean=} opt_request If `true` the callback is always async.
|
||||||
|
* The tile data is requested if not yet loaded.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
forDataAtCoordinateAndResolution(
|
||||||
|
coordinate, resolution, callback, opt_request) {
|
||||||
|
if (this.tileGrid) {
|
||||||
|
const tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
|
||||||
|
coordinate, resolution);
|
||||||
|
const tile = /** @type {!module:ol/source/UTFGrid~CustomTile} */(this.getTile(
|
||||||
|
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
|
||||||
|
tile.forDataAtCoordinate(coordinate, callback, null, opt_request);
|
||||||
|
} else {
|
||||||
|
if (opt_request === true) {
|
||||||
|
setTimeout(function() {
|
||||||
|
callback(null);
|
||||||
|
}, 0);
|
||||||
|
} else {
|
||||||
|
callback(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
handleTileJSONError() {
|
||||||
|
this.setState(SourceState.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: very similar to ol/source/TileJSON#handleTileJSONResponse
|
||||||
|
* @protected
|
||||||
|
* @param {TileJSON} tileJSON Tile JSON.
|
||||||
|
*/
|
||||||
|
handleTileJSONResponse(tileJSON) {
|
||||||
|
|
||||||
|
const epsg4326Projection = getProjection('EPSG:4326');
|
||||||
|
|
||||||
|
const sourceProjection = this.getProjection();
|
||||||
|
let extent;
|
||||||
|
if (tileJSON.bounds !== undefined) {
|
||||||
|
const transform = getTransformFromProjections(
|
||||||
|
epsg4326Projection, sourceProjection);
|
||||||
|
extent = applyTransform(tileJSON.bounds, transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
const minZoom = tileJSON.minzoom || 0;
|
||||||
|
const maxZoom = tileJSON.maxzoom || 22;
|
||||||
|
const tileGrid = createXYZ({
|
||||||
|
extent: extentFromProjection(sourceProjection),
|
||||||
|
maxZoom: maxZoom,
|
||||||
|
minZoom: minZoom
|
||||||
|
});
|
||||||
|
this.tileGrid = tileGrid;
|
||||||
|
|
||||||
|
this.template_ = tileJSON.template;
|
||||||
|
|
||||||
|
const grids = tileJSON.grids;
|
||||||
|
if (!grids) {
|
||||||
|
this.setState(SourceState.ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tileUrlFunction_ = createFromTemplates(grids, tileGrid);
|
||||||
|
|
||||||
|
if (tileJSON.attribution !== undefined) {
|
||||||
|
const attributionExtent = extent !== undefined ?
|
||||||
|
extent : epsg4326Projection.getExtent();
|
||||||
|
|
||||||
|
this.setAttributions(function(frameState) {
|
||||||
|
if (intersects(attributionExtent, frameState.extent)) {
|
||||||
|
return [tileJSON.attribution];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState(SourceState.READY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
getTile(z, x, y, pixelRatio, projection) {
|
||||||
|
const tileCoordKey = getKeyZXY(z, x, y);
|
||||||
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||||
|
return (
|
||||||
|
/** @type {!module:ol/Tile} */ (this.tileCache.get(tileCoordKey))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const tileCoord = [z, x, y];
|
||||||
|
const urlTileCoord =
|
||||||
|
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
||||||
|
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
||||||
|
const tile = new CustomTile(
|
||||||
|
tileCoord,
|
||||||
|
tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY,
|
||||||
|
tileUrl !== undefined ? tileUrl : '',
|
||||||
|
this.tileGrid.getTileCoordExtent(tileCoord),
|
||||||
|
this.preemptive_,
|
||||||
|
this.jsonp_);
|
||||||
|
this.tileCache.set(tileCoordKey, tile);
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
useTile(z, x, y) {
|
||||||
|
const tileCoordKey = getKeyZXY(z, x, y);
|
||||||
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||||
|
this.tileCache.get(tileCoordKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @param {Event} event The load event.
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.onXHRLoad_ = function(event) {
|
|
||||||
const client = /** @type {XMLHttpRequest} */ (event.target);
|
|
||||||
// status will be 0 for file:// urls
|
|
||||||
if (!client.status || client.status >= 200 && client.status < 300) {
|
|
||||||
let response;
|
|
||||||
try {
|
|
||||||
response = /** @type {TileJSON} */(JSON.parse(client.responseText));
|
|
||||||
} catch (err) {
|
|
||||||
this.handleTileJSONError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.handleTileJSONResponse(response);
|
|
||||||
} else {
|
|
||||||
this.handleTileJSONError();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @param {Event} event The error event.
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.onXHRError_ = function(event) {
|
|
||||||
this.handleTileJSONError();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the template from TileJSON.
|
|
||||||
* @return {string|undefined} The template from TileJSON.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.getTemplate = function() {
|
|
||||||
return this.template_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls the callback (synchronously by default) with the available data
|
|
||||||
* for given coordinate and resolution (or `null` if not yet loaded or
|
|
||||||
* in case of an error).
|
|
||||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
|
||||||
* @param {number} resolution Resolution.
|
|
||||||
* @param {function(*)} callback Callback.
|
|
||||||
* @param {boolean=} opt_request If `true` the callback is always async.
|
|
||||||
* The tile data is requested if not yet loaded.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.forDataAtCoordinateAndResolution = function(
|
|
||||||
coordinate, resolution, callback, opt_request) {
|
|
||||||
if (this.tileGrid) {
|
|
||||||
const tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, resolution);
|
|
||||||
const tile = /** @type {!module:ol/source/UTFGrid~CustomTile} */(this.getTile(
|
|
||||||
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
|
|
||||||
tile.forDataAtCoordinate(coordinate, callback, null, opt_request);
|
|
||||||
} else {
|
|
||||||
if (opt_request === true) {
|
|
||||||
setTimeout(function() {
|
|
||||||
callback(null);
|
|
||||||
}, 0);
|
|
||||||
} else {
|
|
||||||
callback(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.handleTileJSONError = function() {
|
|
||||||
this.setState(SourceState.ERROR);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: very similar to ol/source/TileJSON#handleTileJSONResponse
|
|
||||||
* @protected
|
|
||||||
* @param {TileJSON} tileJSON Tile JSON.
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
|
|
||||||
|
|
||||||
const epsg4326Projection = getProjection('EPSG:4326');
|
|
||||||
|
|
||||||
const sourceProjection = this.getProjection();
|
|
||||||
let extent;
|
|
||||||
if (tileJSON.bounds !== undefined) {
|
|
||||||
const transform = getTransformFromProjections(
|
|
||||||
epsg4326Projection, sourceProjection);
|
|
||||||
extent = applyTransform(tileJSON.bounds, transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
const minZoom = tileJSON.minzoom || 0;
|
|
||||||
const maxZoom = tileJSON.maxzoom || 22;
|
|
||||||
const tileGrid = createXYZ({
|
|
||||||
extent: extentFromProjection(sourceProjection),
|
|
||||||
maxZoom: maxZoom,
|
|
||||||
minZoom: minZoom
|
|
||||||
});
|
|
||||||
this.tileGrid = tileGrid;
|
|
||||||
|
|
||||||
this.template_ = tileJSON.template;
|
|
||||||
|
|
||||||
const grids = tileJSON.grids;
|
|
||||||
if (!grids) {
|
|
||||||
this.setState(SourceState.ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tileUrlFunction_ = createFromTemplates(grids, tileGrid);
|
|
||||||
|
|
||||||
if (tileJSON.attribution !== undefined) {
|
|
||||||
const attributionExtent = extent !== undefined ?
|
|
||||||
extent : epsg4326Projection.getExtent();
|
|
||||||
|
|
||||||
this.setAttributions(function(frameState) {
|
|
||||||
if (intersects(attributionExtent, frameState.extent)) {
|
|
||||||
return [tileJSON.attribution];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState(SourceState.READY);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
|
||||||
const tileCoordKey = getKeyZXY(z, x, y);
|
|
||||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
||||||
return (
|
|
||||||
/** @type {!module:ol/Tile} */ (this.tileCache.get(tileCoordKey))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const tileCoord = [z, x, y];
|
|
||||||
const urlTileCoord =
|
|
||||||
this.getTileCoordForTileUrlFunction(tileCoord, projection);
|
|
||||||
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
|
|
||||||
const tile = new CustomTile(
|
|
||||||
tileCoord,
|
|
||||||
tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY,
|
|
||||||
tileUrl !== undefined ? tileUrl : '',
|
|
||||||
this.tileGrid.getTileCoordExtent(tileCoord),
|
|
||||||
this.preemptive_,
|
|
||||||
this.jsonp_);
|
|
||||||
this.tileCache.set(tileCoordKey, tile);
|
|
||||||
return tile;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
UTFGrid.prototype.useTile = function(z, x, y) {
|
|
||||||
const tileCoordKey = getKeyZXY(z, x, y);
|
|
||||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
||||||
this.tileCache.get(tileCoordKey);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export default UTFGrid;
|
export default UTFGrid;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,7 @@ import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.
|
|||||||
* }));
|
* }));
|
||||||
* // the line below is only required for ol/format/MVT
|
* // the line below is only required for ol/format/MVT
|
||||||
* tile.setExtent(format.getLastExtent());
|
* tile.setExtent(format.getLastExtent());
|
||||||
* };
|
* }
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
* @property {module:ol/Tile~UrlFunction} [tileUrlFunction] Optional function to get tile URL given a tile coordinate and the projection.
|
* @property {module:ol/Tile~UrlFunction} [tileUrlFunction] Optional function to get tile URL given a tile coordinate and the projection.
|
||||||
@@ -136,84 +136,84 @@ class VectorTile extends UrlTile {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean} The source can have overlapping geometries.
|
||||||
|
*/
|
||||||
|
getOverlaps() {
|
||||||
|
return this.overlaps_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clear {@link module:ol/TileCache~TileCache} and delete all source tiles
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
clear() {
|
||||||
|
this.tileCache.clear();
|
||||||
|
this.sourceTiles_ = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
getTile(z, x, y, pixelRatio, projection) {
|
||||||
|
const tileCoordKey = getKeyZXY(z, x, y);
|
||||||
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||||
|
return (
|
||||||
|
/** @type {!module:ol/Tile} */ (this.tileCache.get(tileCoordKey))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const tileCoord = [z, x, y];
|
||||||
|
const urlTileCoord = this.getTileCoordForTileUrlFunction(
|
||||||
|
tileCoord, projection);
|
||||||
|
const tile = new VectorImageTile(
|
||||||
|
tileCoord,
|
||||||
|
urlTileCoord !== null ? TileState.IDLE : TileState.EMPTY,
|
||||||
|
this.getRevision(),
|
||||||
|
this.format_, this.tileLoadFunction, urlTileCoord, this.tileUrlFunction,
|
||||||
|
this.tileGrid, this.getTileGridForProjection(projection),
|
||||||
|
this.sourceTiles_, pixelRatio, projection, this.tileClass,
|
||||||
|
this.handleTileChange.bind(this), tileCoord[0]);
|
||||||
|
|
||||||
|
this.tileCache.set(tileCoordKey, tile);
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
getTileGridForProjection(projection) {
|
||||||
|
const code = projection.getCode();
|
||||||
|
let tileGrid = this.tileGrids_[code];
|
||||||
|
if (!tileGrid) {
|
||||||
|
// A tile grid that matches the tile size of the source tile grid is more
|
||||||
|
// likely to have 1:1 relationships between source tiles and rendered tiles.
|
||||||
|
const sourceTileGrid = this.tileGrid;
|
||||||
|
tileGrid = this.tileGrids_[code] = createForProjection(projection, undefined,
|
||||||
|
sourceTileGrid ? sourceTileGrid.getTileSize(sourceTileGrid.getMinZoom()) : undefined);
|
||||||
|
}
|
||||||
|
return tileGrid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
getTilePixelRatio(pixelRatio) {
|
||||||
|
return pixelRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
getTilePixelSize(z, pixelRatio, projection) {
|
||||||
|
const tileGrid = this.getTileGridForProjection(projection);
|
||||||
|
const tileSize = toSize(tileGrid.getTileSize(z), this.tmpSize);
|
||||||
|
return [Math.round(tileSize[0] * pixelRatio), Math.round(tileSize[1] * pixelRatio)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {boolean} The source can have overlapping geometries.
|
|
||||||
*/
|
|
||||||
VectorTile.prototype.getOverlaps = function() {
|
|
||||||
return this.overlaps_;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clear {@link module:ol/TileCache~TileCache} and delete all source tiles
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
VectorTile.prototype.clear = function() {
|
|
||||||
this.tileCache.clear();
|
|
||||||
this.sourceTiles_ = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
|
||||||
const tileCoordKey = getKeyZXY(z, x, y);
|
|
||||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
||||||
return (
|
|
||||||
/** @type {!module:ol/Tile} */ (this.tileCache.get(tileCoordKey))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const tileCoord = [z, x, y];
|
|
||||||
const urlTileCoord = this.getTileCoordForTileUrlFunction(
|
|
||||||
tileCoord, projection);
|
|
||||||
const tile = new VectorImageTile(
|
|
||||||
tileCoord,
|
|
||||||
urlTileCoord !== null ? TileState.IDLE : TileState.EMPTY,
|
|
||||||
this.getRevision(),
|
|
||||||
this.format_, this.tileLoadFunction, urlTileCoord, this.tileUrlFunction,
|
|
||||||
this.tileGrid, this.getTileGridForProjection(projection),
|
|
||||||
this.sourceTiles_, pixelRatio, projection, this.tileClass,
|
|
||||||
this.handleTileChange.bind(this), tileCoord[0]);
|
|
||||||
|
|
||||||
this.tileCache.set(tileCoordKey, tile);
|
|
||||||
return tile;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
VectorTile.prototype.getTileGridForProjection = function(projection) {
|
|
||||||
const code = projection.getCode();
|
|
||||||
let tileGrid = this.tileGrids_[code];
|
|
||||||
if (!tileGrid) {
|
|
||||||
// A tile grid that matches the tile size of the source tile grid is more
|
|
||||||
// likely to have 1:1 relationships between source tiles and rendered tiles.
|
|
||||||
const sourceTileGrid = this.tileGrid;
|
|
||||||
tileGrid = this.tileGrids_[code] = createForProjection(projection, undefined,
|
|
||||||
sourceTileGrid ? sourceTileGrid.getTileSize(sourceTileGrid.getMinZoom()) : undefined);
|
|
||||||
}
|
|
||||||
return tileGrid;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
VectorTile.prototype.getTilePixelRatio = function(pixelRatio) {
|
|
||||||
return pixelRatio;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
VectorTile.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
|
|
||||||
const tileGrid = this.getTileGridForProjection(projection);
|
|
||||||
const tileSize = toSize(tileGrid.getTileSize(z), this.tmpSize);
|
|
||||||
return [Math.round(tileSize[0] * pixelRatio), Math.round(tileSize[1] * pixelRatio)];
|
|
||||||
};
|
|
||||||
export default VectorTile;
|
export default VectorTile;
|
||||||
|
|||||||
@@ -151,117 +151,118 @@ class WMTS extends TileImage {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the URLs to use for requests.
|
||||||
|
* URLs may contain OCG conform URL Template Variables: {TileMatrix}, {TileRow}, {TileCol}.
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
setUrls(urls) {
|
||||||
|
this.urls = urls;
|
||||||
|
const key = urls.join('\n');
|
||||||
|
this.setTileUrlFunction(this.fixedTileUrlFunction ?
|
||||||
|
this.fixedTileUrlFunction.bind(this) :
|
||||||
|
createFromTileUrlFunctions(urls.map(createFromWMTSTemplate.bind(this))), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dimensions, i.e. those passed to the constructor through the
|
||||||
|
* "dimensions" option, and possibly updated using the updateDimensions
|
||||||
|
* method.
|
||||||
|
* @return {!Object} Dimensions.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getDimensions() {
|
||||||
|
return this.dimensions_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the image format of the WMTS source.
|
||||||
|
* @return {string} Format.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getFormat() {
|
||||||
|
return this.format_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the layer of the WMTS source.
|
||||||
|
* @return {string} Layer.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getLayer() {
|
||||||
|
return this.layer_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the matrix set of the WMTS source.
|
||||||
|
* @return {string} MatrixSet.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getMatrixSet() {
|
||||||
|
return this.matrixSet_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the request encoding, either "KVP" or "REST".
|
||||||
|
* @return {module:ol/source/WMTSRequestEncoding} Request encoding.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getRequestEncoding() {
|
||||||
|
return this.requestEncoding_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the style of the WMTS source.
|
||||||
|
* @return {string} Style.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getStyle() {
|
||||||
|
return this.style_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the version of the WMTS source.
|
||||||
|
* @return {string} Version.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getVersion() {
|
||||||
|
return this.version_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @return {string} The key for the current dimensions.
|
||||||
|
*/
|
||||||
|
getKeyForDimensions_() {
|
||||||
|
let i = 0;
|
||||||
|
const res = [];
|
||||||
|
for (const key in this.dimensions_) {
|
||||||
|
res[i++] = key + '-' + this.dimensions_[key];
|
||||||
|
}
|
||||||
|
return res.join('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the dimensions.
|
||||||
|
* @param {Object} dimensions Dimensions.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
updateDimensions(dimensions) {
|
||||||
|
assign(this.dimensions_, dimensions);
|
||||||
|
this.setKey(this.getKeyForDimensions_());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export default WMTS;
|
||||||
* Set the URLs to use for requests.
|
|
||||||
* URLs may contain OCG conform URL Template Variables: {TileMatrix}, {TileRow}, {TileCol}.
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
WMTS.prototype.setUrls = function(urls) {
|
|
||||||
this.urls = urls;
|
|
||||||
const key = urls.join('\n');
|
|
||||||
this.setTileUrlFunction(this.fixedTileUrlFunction ?
|
|
||||||
this.fixedTileUrlFunction.bind(this) :
|
|
||||||
createFromTileUrlFunctions(urls.map(createFromWMTSTemplate.bind(this))), key);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the dimensions, i.e. those passed to the constructor through the
|
|
||||||
* "dimensions" option, and possibly updated using the updateDimensions
|
|
||||||
* method.
|
|
||||||
* @return {!Object} Dimensions.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getDimensions = function() {
|
|
||||||
return this.dimensions_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the image format of the WMTS source.
|
|
||||||
* @return {string} Format.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getFormat = function() {
|
|
||||||
return this.format_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the layer of the WMTS source.
|
|
||||||
* @return {string} Layer.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getLayer = function() {
|
|
||||||
return this.layer_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the matrix set of the WMTS source.
|
|
||||||
* @return {string} MatrixSet.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getMatrixSet = function() {
|
|
||||||
return this.matrixSet_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the request encoding, either "KVP" or "REST".
|
|
||||||
* @return {module:ol/source/WMTSRequestEncoding} Request encoding.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getRequestEncoding = function() {
|
|
||||||
return this.requestEncoding_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the style of the WMTS source.
|
|
||||||
* @return {string} Style.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getStyle = function() {
|
|
||||||
return this.style_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the version of the WMTS source.
|
|
||||||
* @return {string} Version.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getVersion = function() {
|
|
||||||
return this.version_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @return {string} The key for the current dimensions.
|
|
||||||
*/
|
|
||||||
WMTS.prototype.getKeyForDimensions_ = function() {
|
|
||||||
let i = 0;
|
|
||||||
const res = [];
|
|
||||||
for (const key in this.dimensions_) {
|
|
||||||
res[i++] = key + '-' + this.dimensions_[key];
|
|
||||||
}
|
|
||||||
return res.join('/');
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the dimensions.
|
|
||||||
* @param {Object} dimensions Dimensions.
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
WMTS.prototype.updateDimensions = function(dimensions) {
|
|
||||||
assign(this.dimensions_, dimensions);
|
|
||||||
this.setKey(this.getKeyForDimensions_());
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate source options from a capabilities object.
|
* Generate source options from a capabilities object.
|
||||||
@@ -523,6 +524,3 @@ function createFromWMTSTemplate(template) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default WMTS;
|
|
||||||
|
|||||||
@@ -52,32 +52,31 @@ export class CustomTile extends ImageTile {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
/**
|
getImage() {
|
||||||
* @inheritDoc
|
if (this.zoomifyImage_) {
|
||||||
*/
|
return this.zoomifyImage_;
|
||||||
CustomTile.prototype.getImage = function() {
|
}
|
||||||
if (this.zoomifyImage_) {
|
const image = super.getImage();
|
||||||
return this.zoomifyImage_;
|
if (this.state == TileState.LOADED) {
|
||||||
}
|
const tileSize = this.tileSize_;
|
||||||
const image = ImageTile.prototype.getImage.call(this);
|
if (image.width == tileSize[0] && image.height == tileSize[1]) {
|
||||||
if (this.state == TileState.LOADED) {
|
this.zoomifyImage_ = image;
|
||||||
const tileSize = this.tileSize_;
|
return image;
|
||||||
if (image.width == tileSize[0] && image.height == tileSize[1]) {
|
} else {
|
||||||
this.zoomifyImage_ = image;
|
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
|
||||||
return image;
|
context.drawImage(image, 0, 0);
|
||||||
} else {
|
this.zoomifyImage_ = context.canvas;
|
||||||
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
|
return context.canvas;
|
||||||
context.drawImage(image, 0, 0);
|
}
|
||||||
this.zoomifyImage_ = context.canvas;
|
} else {
|
||||||
return context.canvas;
|
return image;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return image;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user