Merge pull request #8489 from ahocevar/prototype
Use .prototype. only where necessary
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
/**
|
||||
* @module ol/Disposable
|
||||
*/
|
||||
import {VOID} from './functions.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Objects that need to clean up after themselves.
|
||||
*/
|
||||
class Disposable {
|
||||
|
||||
constructor() {
|
||||
/**
|
||||
* The object has already been disposed.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.disposed_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
*/
|
||||
@@ -17,19 +26,12 @@ class Disposable {
|
||||
this.disposeInternal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension point for disposable objects.
|
||||
* @protected
|
||||
*/
|
||||
disposeInternal() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* The object has already been disposed.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
Disposable.prototype.disposed_ = false;
|
||||
|
||||
/**
|
||||
* Extension point for disposable objects.
|
||||
* @protected
|
||||
*/
|
||||
Disposable.prototype.disposeInternal = VOID;
|
||||
|
||||
export default Disposable;
|
||||
|
||||
@@ -274,7 +274,7 @@ class GeometryCollection extends Geometry {
|
||||
*/
|
||||
disposeInternal() {
|
||||
this.unlistenGeometriesChange_();
|
||||
Geometry.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -411,7 +411,7 @@ class PointerEventHandler extends EventTarget {
|
||||
*/
|
||||
disposeInternal() {
|
||||
this.unregister_();
|
||||
EventTarget.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class CanvasLineStringReplay extends CanvasReplay {
|
||||
state.lastStroke = this.coordinates.length;
|
||||
}
|
||||
state.lastStroke = 0;
|
||||
CanvasReplay.prototype.applyStroke.call(this, state);
|
||||
super.applyStroke(state);
|
||||
this.instructions.push(beginPathInstruction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class WebGLImageReplay extends WebGLTextureReplay {
|
||||
|
||||
this.images_ = null;
|
||||
this.hitDetectionImages_ = null;
|
||||
WebGLTextureReplay.prototype.finish.call(this, context);
|
||||
super.finish(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -338,7 +338,7 @@ class WebGLTextReplay extends WebGLTextureReplay {
|
||||
this.images_ = null;
|
||||
this.atlases_ = {};
|
||||
this.currAtlas_ = undefined;
|
||||
WebGLTextureReplay.prototype.finish.call(this, context);
|
||||
super.finish(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,7 @@ class CanvasImageLayerRenderer extends IntermediateCanvasRenderer {
|
||||
if (this.vectorRenderer_) {
|
||||
this.vectorRenderer_.dispose();
|
||||
}
|
||||
IntermediateCanvasRenderer.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +184,7 @@ class CanvasImageLayerRenderer extends IntermediateCanvasRenderer {
|
||||
if (this.vectorRenderer_) {
|
||||
return this.vectorRenderer_.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg);
|
||||
} else {
|
||||
return IntermediateCanvasRenderer.prototype.forEachFeatureAtCoordinate.call(this, coordinate, frameState, hitTolerance, callback, thisArg);
|
||||
return super.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class IntermediateCanvasRenderer extends CanvasLayerRenderer {
|
||||
if (this.getLayer().getSource().forEachFeatureAtCoordinate !== VOID) {
|
||||
// for ImageCanvas sources use the original hit-detection logic,
|
||||
// so that for example also transparent polygons are detected
|
||||
return CanvasLayerRenderer.prototype.forEachLayerAtCoordinate.apply(this, arguments);
|
||||
return super.forEachLayerAtCoordinate(arguments);
|
||||
} else {
|
||||
const pixel = applyTransform(this.coordinateToCanvasPixelTransform, coordinate.slice());
|
||||
scaleCoordinate(pixel, frameState.viewState.resolution / this.renderedResolution);
|
||||
|
||||
@@ -209,7 +209,7 @@ class CanvasMapRenderer extends MapRenderer {
|
||||
* @inheritDoc
|
||||
*/
|
||||
registerLayerRenderers(constructors) {
|
||||
MapRenderer.prototype.registerLayerRenderers.call(this, constructors);
|
||||
super.registerLayerRenderers(constructors);
|
||||
for (let i = 0, ii = constructors.length; i < ii; ++i) {
|
||||
const ctor = constructors[i];
|
||||
if (!includes(layerRendererConstructors, ctor)) {
|
||||
|
||||
@@ -91,7 +91,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
||||
*/
|
||||
disposeInternal() {
|
||||
unlisten(labelCache, EventType.CLEAR, this.handleFontsChanged_, this);
|
||||
CanvasLayerRenderer.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -97,14 +97,14 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
*/
|
||||
disposeInternal() {
|
||||
unlisten(labelCache, EventType.CLEAR, this.handleFontsChanged_, this);
|
||||
CanvasTileLayerRenderer.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getTile(z, x, y, pixelRatio, projection) {
|
||||
const tile = CanvasTileLayerRenderer.prototype.getTile.call(this, z, x, y, pixelRatio, projection);
|
||||
const tile = super.getTile(z, x, y, pixelRatio, projection);
|
||||
if (tile.getState() === TileState.LOADED) {
|
||||
this.createReplayGroup_(tile, pixelRatio, projection);
|
||||
if (this.context) {
|
||||
@@ -131,7 +131,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
}
|
||||
}
|
||||
this.renderedLayerRevision_ = layerRevision;
|
||||
return CanvasTileLayerRenderer.prototype.prepareFrame.apply(this, arguments);
|
||||
return super.prepareFrame(frameState, layerState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,7 +404,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
/** @type {number} */ (offsetX), /** @type {number} */ (offsetY));
|
||||
}
|
||||
}
|
||||
CanvasTileLayerRenderer.prototype.postCompose.apply(this, arguments);
|
||||
super.postCompose(context, frameState, layerState);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -291,7 +291,7 @@ class WebGLMapRenderer extends MapRenderer {
|
||||
});
|
||||
}
|
||||
this.context_.dispose();
|
||||
MapRenderer.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,7 +100,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
|
||||
disposeInternal() {
|
||||
const context = this.mapRenderer.getContext();
|
||||
context.deleteBuffer(this.renderArrayBuffer_);
|
||||
WebGLLayerRenderer.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +135,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleWebGLContextLost() {
|
||||
WebGLLayerRenderer.prototype.handleWebGLContextLost.call(this);
|
||||
super.handleWebGLContextLost();
|
||||
this.locations_ = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
||||
replayGroup.getDeleteResourcesFunction(context)();
|
||||
this.replayGroup_ = null;
|
||||
}
|
||||
WebGLLayerRenderer.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,7 +121,7 @@ class ReprojImage extends ImageBase {
|
||||
if (this.state == ImageState.LOADING) {
|
||||
this.unlistenSource_();
|
||||
}
|
||||
ImageBase.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -210,7 +210,7 @@ class ReprojTile extends Tile {
|
||||
if (this.state == TileState.LOADING) {
|
||||
this.unlistenSources_();
|
||||
}
|
||||
Tile.prototype.disposeInternal.call(this);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -143,7 +143,7 @@ class Cluster extends VectorSource {
|
||||
this.clear();
|
||||
this.cluster();
|
||||
this.addFeatures(this.features);
|
||||
VectorSource.prototype.refresh.call(this);
|
||||
super.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -132,7 +132,7 @@ class Static extends ImageSource {
|
||||
this.image_.setImage(canvas);
|
||||
}
|
||||
}
|
||||
ImageSource.prototype.handleImageChange.call(this, evt);
|
||||
super.handleImageChange(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ class TileImage extends UrlTile {
|
||||
*/
|
||||
canExpireCache() {
|
||||
if (!ENABLE_RASTER_REPROJECTION) {
|
||||
return UrlTile.prototype.canExpireCache.call(this);
|
||||
return super.canExpireCache();
|
||||
}
|
||||
if (this.tileCache.canExpireCache()) {
|
||||
return true;
|
||||
@@ -149,7 +149,7 @@ class TileImage extends UrlTile {
|
||||
*/
|
||||
expireCache(projection, usedTiles) {
|
||||
if (!ENABLE_RASTER_REPROJECTION) {
|
||||
UrlTile.prototype.expireCache.call(this, projection, usedTiles);
|
||||
super.expireCache(projection, usedTiles);
|
||||
return;
|
||||
}
|
||||
const usedTileCache = this.getTileCacheForProjection(projection);
|
||||
@@ -188,7 +188,7 @@ class TileImage extends UrlTile {
|
||||
this.getProjection() && projection && !equivalent(this.getProjection(), projection)) {
|
||||
return false;
|
||||
} else {
|
||||
return UrlTile.prototype.getOpaque.call(this, projection);
|
||||
return super.getOpaque(projection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,178 +76,176 @@ export class CustomTile extends Tile {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the image element for this tile.
|
||||
* @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') {
|
||||
/**
|
||||
* Get the image element for this tile.
|
||||
* @return {HTMLImageElement} Image.
|
||||
*/
|
||||
getImage() {
|
||||
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;
|
||||
/**
|
||||
* Synchronously returns data at given coordinate (if available).
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @return {*} The data.
|
||||
*/
|
||||
getData(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;
|
||||
}
|
||||
|
||||
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
|
||||
* for given coordinate (or `null` if not yet loaded).
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @param {function(this: T, *)} callback 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.
|
||||
* The tile data is requested if not yet loaded.
|
||||
* @template T
|
||||
*/
|
||||
CustomTile.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
|
||||
if (this.state == TileState.IDLE && opt_request === true) {
|
||||
listenOnce(this, EventType.CHANGE, function(e) {
|
||||
callback.call(opt_this, this.getData(coordinate));
|
||||
}, this);
|
||||
this.loadInternal_();
|
||||
} else {
|
||||
if (opt_request === true) {
|
||||
setTimeout(function() {
|
||||
/**
|
||||
* Calls the callback (synchronously by default) with the available data
|
||||
* for given coordinate (or `null` if not yet loaded).
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @param {function(this: T, *)} callback 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.
|
||||
* The tile data is requested if not yet loaded.
|
||||
* @template T
|
||||
*/
|
||||
forDataAtCoordinate(coordinate, callback, opt_this, opt_request) {
|
||||
if (this.state == TileState.IDLE && opt_request === true) {
|
||||
listenOnce(this, EventType.CHANGE, function(e) {
|
||||
callback.call(opt_this, this.getData(coordinate));
|
||||
}.bind(this), 0);
|
||||
}, this);
|
||||
this.loadInternal_();
|
||||
} 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
|
||||
*/
|
||||
CustomTile.prototype.getKey = function() {
|
||||
return this.src_;
|
||||
};
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getKey() {
|
||||
return this.src_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
CustomTile.prototype.handleError_ = function() {
|
||||
this.state = TileState.ERROR;
|
||||
this.changed();
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleError_() {
|
||||
this.state = TileState.ERROR;
|
||||
this.changed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {!UTFGridJSON} json UTFGrid data.
|
||||
* @private
|
||||
*/
|
||||
CustomTile.prototype.handleLoad_ = function(json) {
|
||||
this.grid_ = json.grid;
|
||||
this.keys_ = json.keys;
|
||||
this.data_ = json.data;
|
||||
/**
|
||||
* @param {!UTFGridJSON} json UTFGrid data.
|
||||
* @private
|
||||
*/
|
||||
handleLoad_(json) {
|
||||
this.grid_ = json.grid;
|
||||
this.keys_ = json.keys;
|
||||
this.data_ = json.data;
|
||||
|
||||
this.state = TileState.EMPTY;
|
||||
this.changed();
|
||||
};
|
||||
this.state = TileState.EMPTY;
|
||||
this.changed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
CustomTile.prototype.loadInternal_ = function() {
|
||||
if (this.state == TileState.IDLE) {
|
||||
this.state = TileState.LOADING;
|
||||
if (this.jsonp_) {
|
||||
requestJSONP(this.src_, this.handleLoad_.bind(this),
|
||||
this.handleError_.bind(this));
|
||||
} else {
|
||||
const client = new XMLHttpRequest();
|
||||
client.addEventListener('load', this.onXHRLoad_.bind(this));
|
||||
client.addEventListener('error', this.onXHRError_.bind(this));
|
||||
client.open('GET', this.src_);
|
||||
client.send();
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
loadInternal_() {
|
||||
if (this.state == TileState.IDLE) {
|
||||
this.state = TileState.LOADING;
|
||||
if (this.jsonp_) {
|
||||
requestJSONP(this.src_, this.handleLoad_.bind(this),
|
||||
this.handleError_.bind(this));
|
||||
} else {
|
||||
const client = new XMLHttpRequest();
|
||||
client.addEventListener('load', this.onXHRLoad_.bind(this));
|
||||
client.addEventListener('error', this.onXHRError_.bind(this));
|
||||
client.open('GET', this.src_);
|
||||
client.send();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The load event.
|
||||
*/
|
||||
CustomTile.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 {!UTFGridJSON} */(JSON.parse(client.responseText));
|
||||
} catch (err) {
|
||||
/**
|
||||
* @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 {!UTFGridJSON} */(JSON.parse(client.responseText));
|
||||
} catch (err) {
|
||||
this.handleError_();
|
||||
return;
|
||||
}
|
||||
this.handleLoad_(response);
|
||||
} else {
|
||||
this.handleError_();
|
||||
return;
|
||||
}
|
||||
this.handleLoad_(response);
|
||||
} else {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The error event.
|
||||
*/
|
||||
onXHRError_(event) {
|
||||
this.handleError_();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event The error event.
|
||||
*/
|
||||
CustomTile.prototype.onXHRError_ = function(event) {
|
||||
this.handleError_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
CustomTile.prototype.load = function() {
|
||||
if (this.preemptive_) {
|
||||
this.loadInternal_();
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
load() {
|
||||
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;
|
||||
|
||||
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
|
||||
* tile.setExtent(format.getLastExtent());
|
||||
* };
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
* @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;
|
||||
|
||||
@@ -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_());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_());
|
||||
};
|
||||
|
||||
export default WMTS;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
CustomTile.prototype.getImage = function() {
|
||||
if (this.zoomifyImage_) {
|
||||
return this.zoomifyImage_;
|
||||
}
|
||||
const image = ImageTile.prototype.getImage.call(this);
|
||||
if (this.state == TileState.LOADED) {
|
||||
const tileSize = this.tileSize_;
|
||||
if (image.width == tileSize[0] && image.height == tileSize[1]) {
|
||||
this.zoomifyImage_ = image;
|
||||
return image;
|
||||
} else {
|
||||
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
|
||||
context.drawImage(image, 0, 0);
|
||||
this.zoomifyImage_ = context.canvas;
|
||||
return context.canvas;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getImage() {
|
||||
if (this.zoomifyImage_) {
|
||||
return this.zoomifyImage_;
|
||||
}
|
||||
const image = super.getImage();
|
||||
if (this.state == TileState.LOADED) {
|
||||
const tileSize = this.tileSize_;
|
||||
if (image.width == tileSize[0] && image.height == tileSize[1]) {
|
||||
this.zoomifyImage_ = image;
|
||||
return image;
|
||||
} else {
|
||||
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
|
||||
context.drawImage(image, 0, 0);
|
||||
this.zoomifyImage_ = context.canvas;
|
||||
return context.canvas;
|
||||
}
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user