Merge pull request #8489 from ahocevar/prototype
Use .prototype. only where necessary
This commit is contained in:
+16
-14
@@ -1,13 +1,22 @@
|
|||||||
/**
|
/**
|
||||||
* @module ol/Disposable
|
* @module ol/Disposable
|
||||||
*/
|
*/
|
||||||
import {VOID} from './functions.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* Objects that need to clean up after themselves.
|
* Objects that need to clean up after themselves.
|
||||||
*/
|
*/
|
||||||
class Disposable {
|
class Disposable {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
/**
|
||||||
|
* The object has already been disposed.
|
||||||
|
* @type {boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.disposed_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up.
|
* Clean up.
|
||||||
*/
|
*/
|
||||||
@@ -17,19 +26,12 @@ class Disposable {
|
|||||||
this.disposeInternal();
|
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;
|
export default Disposable;
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ class GeometryCollection extends Geometry {
|
|||||||
*/
|
*/
|
||||||
disposeInternal() {
|
disposeInternal() {
|
||||||
this.unlistenGeometriesChange_();
|
this.unlistenGeometriesChange_();
|
||||||
Geometry.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ class PointerEventHandler extends EventTarget {
|
|||||||
*/
|
*/
|
||||||
disposeInternal() {
|
disposeInternal() {
|
||||||
this.unregister_();
|
this.unregister_();
|
||||||
EventTarget.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class CanvasLineStringReplay extends CanvasReplay {
|
|||||||
state.lastStroke = this.coordinates.length;
|
state.lastStroke = this.coordinates.length;
|
||||||
}
|
}
|
||||||
state.lastStroke = 0;
|
state.lastStroke = 0;
|
||||||
CanvasReplay.prototype.applyStroke.call(this, state);
|
super.applyStroke(state);
|
||||||
this.instructions.push(beginPathInstruction);
|
this.instructions.push(beginPathInstruction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class WebGLImageReplay extends WebGLTextureReplay {
|
|||||||
|
|
||||||
this.images_ = null;
|
this.images_ = null;
|
||||||
this.hitDetectionImages_ = 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.images_ = null;
|
||||||
this.atlases_ = {};
|
this.atlases_ = {};
|
||||||
this.currAtlas_ = undefined;
|
this.currAtlas_ = undefined;
|
||||||
WebGLTextureReplay.prototype.finish.call(this, context);
|
super.finish(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class CanvasImageLayerRenderer extends IntermediateCanvasRenderer {
|
|||||||
if (this.vectorRenderer_) {
|
if (this.vectorRenderer_) {
|
||||||
this.vectorRenderer_.dispose();
|
this.vectorRenderer_.dispose();
|
||||||
}
|
}
|
||||||
IntermediateCanvasRenderer.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,7 +184,7 @@ class CanvasImageLayerRenderer extends IntermediateCanvasRenderer {
|
|||||||
if (this.vectorRenderer_) {
|
if (this.vectorRenderer_) {
|
||||||
return this.vectorRenderer_.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg);
|
return this.vectorRenderer_.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg);
|
||||||
} else {
|
} 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) {
|
if (this.getLayer().getSource().forEachFeatureAtCoordinate !== VOID) {
|
||||||
// for ImageCanvas sources use the original hit-detection logic,
|
// for ImageCanvas sources use the original hit-detection logic,
|
||||||
// so that for example also transparent polygons are detected
|
// so that for example also transparent polygons are detected
|
||||||
return CanvasLayerRenderer.prototype.forEachLayerAtCoordinate.apply(this, arguments);
|
return super.forEachLayerAtCoordinate(arguments);
|
||||||
} else {
|
} else {
|
||||||
const pixel = applyTransform(this.coordinateToCanvasPixelTransform, coordinate.slice());
|
const pixel = applyTransform(this.coordinateToCanvasPixelTransform, coordinate.slice());
|
||||||
scaleCoordinate(pixel, frameState.viewState.resolution / this.renderedResolution);
|
scaleCoordinate(pixel, frameState.viewState.resolution / this.renderedResolution);
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ class CanvasMapRenderer extends MapRenderer {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
registerLayerRenderers(constructors) {
|
registerLayerRenderers(constructors) {
|
||||||
MapRenderer.prototype.registerLayerRenderers.call(this, constructors);
|
super.registerLayerRenderers(constructors);
|
||||||
for (let i = 0, ii = constructors.length; i < ii; ++i) {
|
for (let i = 0, ii = constructors.length; i < ii; ++i) {
|
||||||
const ctor = constructors[i];
|
const ctor = constructors[i];
|
||||||
if (!includes(layerRendererConstructors, ctor)) {
|
if (!includes(layerRendererConstructors, ctor)) {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
|||||||
*/
|
*/
|
||||||
disposeInternal() {
|
disposeInternal() {
|
||||||
unlisten(labelCache, EventType.CLEAR, this.handleFontsChanged_, this);
|
unlisten(labelCache, EventType.CLEAR, this.handleFontsChanged_, this);
|
||||||
CanvasLayerRenderer.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -97,14 +97,14 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
|||||||
*/
|
*/
|
||||||
disposeInternal() {
|
disposeInternal() {
|
||||||
unlisten(labelCache, EventType.CLEAR, this.handleFontsChanged_, this);
|
unlisten(labelCache, EventType.CLEAR, this.handleFontsChanged_, this);
|
||||||
CanvasTileLayerRenderer.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
getTile(z, x, y, pixelRatio, projection) {
|
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) {
|
if (tile.getState() === TileState.LOADED) {
|
||||||
this.createReplayGroup_(tile, pixelRatio, projection);
|
this.createReplayGroup_(tile, pixelRatio, projection);
|
||||||
if (this.context) {
|
if (this.context) {
|
||||||
@@ -131,7 +131,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.renderedLayerRevision_ = layerRevision;
|
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));
|
/** @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();
|
this.context_.dispose();
|
||||||
MapRenderer.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
|
|||||||
disposeInternal() {
|
disposeInternal() {
|
||||||
const context = this.mapRenderer.getContext();
|
const context = this.mapRenderer.getContext();
|
||||||
context.deleteBuffer(this.renderArrayBuffer_);
|
context.deleteBuffer(this.renderArrayBuffer_);
|
||||||
WebGLLayerRenderer.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,7 +135,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
handleWebGLContextLost() {
|
handleWebGLContextLost() {
|
||||||
WebGLLayerRenderer.prototype.handleWebGLContextLost.call(this);
|
super.handleWebGLContextLost();
|
||||||
this.locations_ = null;
|
this.locations_ = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
|||||||
replayGroup.getDeleteResourcesFunction(context)();
|
replayGroup.getDeleteResourcesFunction(context)();
|
||||||
this.replayGroup_ = null;
|
this.replayGroup_ = null;
|
||||||
}
|
}
|
||||||
WebGLLayerRenderer.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class ReprojImage extends ImageBase {
|
|||||||
if (this.state == ImageState.LOADING) {
|
if (this.state == ImageState.LOADING) {
|
||||||
this.unlistenSource_();
|
this.unlistenSource_();
|
||||||
}
|
}
|
||||||
ImageBase.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ class ReprojTile extends Tile {
|
|||||||
if (this.state == TileState.LOADING) {
|
if (this.state == TileState.LOADING) {
|
||||||
this.unlistenSources_();
|
this.unlistenSources_();
|
||||||
}
|
}
|
||||||
Tile.prototype.disposeInternal.call(this);
|
super.disposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class Cluster extends VectorSource {
|
|||||||
this.clear();
|
this.clear();
|
||||||
this.cluster();
|
this.cluster();
|
||||||
this.addFeatures(this.features);
|
this.addFeatures(this.features);
|
||||||
VectorSource.prototype.refresh.call(this);
|
super.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class Static extends ImageSource {
|
|||||||
this.image_.setImage(canvas);
|
this.image_.setImage(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImageSource.prototype.handleImageChange.call(this, evt);
|
super.handleImageChange(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class TileImage extends UrlTile {
|
|||||||
*/
|
*/
|
||||||
canExpireCache() {
|
canExpireCache() {
|
||||||
if (!ENABLE_RASTER_REPROJECTION) {
|
if (!ENABLE_RASTER_REPROJECTION) {
|
||||||
return UrlTile.prototype.canExpireCache.call(this);
|
return super.canExpireCache();
|
||||||
}
|
}
|
||||||
if (this.tileCache.canExpireCache()) {
|
if (this.tileCache.canExpireCache()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -149,7 +149,7 @@ class TileImage extends UrlTile {
|
|||||||
*/
|
*/
|
||||||
expireCache(projection, usedTiles) {
|
expireCache(projection, usedTiles) {
|
||||||
if (!ENABLE_RASTER_REPROJECTION) {
|
if (!ENABLE_RASTER_REPROJECTION) {
|
||||||
UrlTile.prototype.expireCache.call(this, projection, usedTiles);
|
super.expireCache(projection, usedTiles);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const usedTileCache = this.getTileCacheForProjection(projection);
|
const usedTileCache = this.getTileCacheForProjection(projection);
|
||||||
@@ -188,7 +188,7 @@ class TileImage extends UrlTile {
|
|||||||
this.getProjection() && projection && !equivalent(this.getProjection(), projection)) {
|
this.getProjection() && projection && !equivalent(this.getProjection(), projection)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return UrlTile.prototype.getOpaque.call(this, projection);
|
return super.getOpaque(projection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+308
-311
@@ -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;
|
||||||
|
|||||||
+666
-666
File diff suppressed because it is too large
Load Diff
+78
-78
@@ -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;
|
||||||
|
|||||||
+110
-112
@@ -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;
|
|
||||||
|
|||||||
+23
-24
@@ -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