Use class method syntax instead of .prototype.method = function

This commit is contained in:
ahocevar
2018-08-06 15:23:09 +02:00
parent 2f92e48e93
commit 1eeea2aa4d
5 changed files with 1185 additions and 1191 deletions
+56 -59
View File
@@ -76,24 +76,21 @@ export class CustomTile extends Tile {
}
}
/**
/**
* Get the image element for this tile.
* @return {HTMLImageElement} Image.
*/
CustomTile.prototype.getImage = function() {
getImage() {
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) {
getData(coordinate) {
if (!this.grid_ || !this.keys_) {
return null;
}
@@ -127,10 +124,10 @@ CustomTile.prototype.getData = function(coordinate) {
}
}
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.
@@ -140,7 +137,7 @@ CustomTile.prototype.getData = function(coordinate) {
* The tile data is requested if not yet loaded.
* @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) {
listenOnce(this, EventType.CHANGE, function(e) {
callback.call(opt_this, this.getData(coordinate));
@@ -155,44 +152,44 @@ CustomTile.prototype.forDataAtCoordinate = function(coordinate, callback, opt_th
callback.call(opt_this, this.getData(coordinate));
}
}
};
}
/**
/**
* @inheritDoc
*/
CustomTile.prototype.getKey = function() {
getKey() {
return this.src_;
};
}
/**
/**
* @private
*/
CustomTile.prototype.handleError_ = function() {
handleError_() {
this.state = TileState.ERROR;
this.changed();
};
}
/**
/**
* @param {!UTFGridJSON} json UTFGrid data.
* @private
*/
CustomTile.prototype.handleLoad_ = function(json) {
handleLoad_(json) {
this.grid_ = json.grid;
this.keys_ = json.keys;
this.data_ = json.data;
this.state = TileState.EMPTY;
this.changed();
};
}
/**
/**
* @private
*/
CustomTile.prototype.loadInternal_ = function() {
loadInternal_() {
if (this.state == TileState.IDLE) {
this.state = TileState.LOADING;
if (this.jsonp_) {
@@ -206,14 +203,14 @@ CustomTile.prototype.loadInternal_ = function() {
client.send();
}
}
};
}
/**
/**
* @private
* @param {Event} event The load event.
*/
CustomTile.prototype.onXHRLoad_ = function(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) {
@@ -228,26 +225,27 @@ CustomTile.prototype.onXHRLoad_ = function(event) {
} else {
this.handleError_();
}
};
}
/**
/**
* @private
* @param {Event} event The error event.
*/
CustomTile.prototype.onXHRError_ = function(event) {
onXHRError_(event) {
this.handleError_();
};
}
/**
/**
* @override
*/
CustomTile.prototype.load = function() {
load() {
if (this.preemptive_) {
this.loadInternal_();
}
};
}
}
/**
@@ -326,14 +324,12 @@ class UTFGrid extends TileSource {
}
}
/**
/**
* @private
* @param {Event} event The load event.
*/
UTFGrid.prototype.onXHRLoad_ = function(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) {
@@ -348,29 +344,29 @@ UTFGrid.prototype.onXHRLoad_ = function(event) {
} else {
this.handleTileJSONError();
}
};
}
/**
/**
* @private
* @param {Event} event The error event.
*/
UTFGrid.prototype.onXHRError_ = function(event) {
onXHRError_(event) {
this.handleTileJSONError();
};
}
/**
/**
* Return the template from TileJSON.
* @return {string|undefined} The template from TileJSON.
* @api
*/
UTFGrid.prototype.getTemplate = function() {
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).
@@ -381,7 +377,7 @@ UTFGrid.prototype.getTemplate = function() {
* The tile data is requested if not yet loaded.
* @api
*/
UTFGrid.prototype.forDataAtCoordinateAndResolution = function(
forDataAtCoordinateAndResolution(
coordinate, resolution, callback, opt_request) {
if (this.tileGrid) {
const tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
@@ -398,23 +394,23 @@ UTFGrid.prototype.forDataAtCoordinateAndResolution = function(
callback(null);
}
}
};
}
/**
/**
* @protected
*/
UTFGrid.prototype.handleTileJSONError = function() {
handleTileJSONError() {
this.setState(SourceState.ERROR);
};
}
/**
/**
* TODO: very similar to ol/source/TileJSON#handleTileJSONResponse
* @protected
* @param {TileJSON} tileJSON Tile JSON.
*/
UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
handleTileJSONResponse(tileJSON) {
const epsg4326Projection = getProjection('EPSG:4326');
@@ -459,13 +455,13 @@ UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
this.setState(SourceState.READY);
};
}
/**
/**
* @inheritDoc
*/
UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
getTile(z, x, y, pixelRatio, projection) {
const tileCoordKey = getKeyZXY(z, x, y);
if (this.tileCache.containsKey(tileCoordKey)) {
return (
@@ -486,18 +482,19 @@ UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
this.tileCache.set(tileCoordKey, tile);
return tile;
}
};
}
/**
/**
* @inheritDoc
*/
UTFGrid.prototype.useTile = function(z, x, y) {
useTile(z, x, y) {
const tileCoordKey = getKeyZXY(z, x, y);
if (this.tileCache.containsKey(tileCoordKey)) {
this.tileCache.get(tileCoordKey);
}
};
}
}
export default UTFGrid;
+98 -98
View File
@@ -276,10 +276,7 @@ class VectorSource extends Source {
}
}
/**
/**
* Add a single feature to the source. If you want to add a batch of features
* at once, call {@link module:ol/source/Vector~VectorSource#addFeatures #addFeatures()}
* instead. A feature will not be added to the source if feature with
@@ -288,18 +285,18 @@ class VectorSource extends Source {
* @param {module:ol/Feature} feature Feature to add.
* @api
*/
VectorSource.prototype.addFeature = function(feature) {
addFeature(feature) {
this.addFeatureInternal(feature);
this.changed();
};
}
/**
/**
* Add a feature without firing a `change` event.
* @param {module:ol/Feature} feature Feature.
* @protected
*/
VectorSource.prototype.addFeatureInternal = function(feature) {
addFeatureInternal(feature) {
const featureKey = getUid(feature).toString();
if (!this.addToIndex_(featureKey, feature)) {
@@ -320,32 +317,32 @@ VectorSource.prototype.addFeatureInternal = function(feature) {
this.dispatchEvent(
new VectorSourceEvent(VectorEventType.ADDFEATURE, feature));
};
}
/**
/**
* @param {string} featureKey Unique identifier for the feature.
* @param {module:ol/Feature} feature The feature.
* @private
*/
VectorSource.prototype.setupChangeEvents_ = function(featureKey, feature) {
setupChangeEvents_(featureKey, feature) {
this.featureChangeKeys_[featureKey] = [
listen(feature, EventType.CHANGE,
this.handleFeatureChange_, this),
listen(feature, ObjectEventType.PROPERTYCHANGE,
this.handleFeatureChange_, this)
];
};
}
/**
/**
* @param {string} featureKey Unique identifier for the feature.
* @param {module:ol/Feature} feature The feature.
* @return {boolean} The feature is "valid", in the sense that it is also a
* candidate for insertion into the Rtree.
* @private
*/
VectorSource.prototype.addToIndex_ = function(featureKey, feature) {
addToIndex_(featureKey, feature) {
let valid = true;
const id = feature.getId();
if (id !== undefined) {
@@ -360,26 +357,26 @@ VectorSource.prototype.addToIndex_ = function(featureKey, feature) {
this.undefIdIndex_[featureKey] = feature;
}
return valid;
};
}
/**
/**
* Add a batch of features to the source.
* @param {Array<module:ol/Feature>} features Features to add.
* @api
*/
VectorSource.prototype.addFeatures = function(features) {
addFeatures(features) {
this.addFeaturesInternal(features);
this.changed();
};
}
/**
/**
* Add features without firing a `change` event.
* @param {Array<module:ol/Feature>} features Features.
* @protected
*/
VectorSource.prototype.addFeaturesInternal = function(features) {
addFeaturesInternal(features) {
const extents = [];
const newFeatures = [];
const geometryFeatures = [];
@@ -413,14 +410,14 @@ VectorSource.prototype.addFeaturesInternal = function(features) {
for (let i = 0, length = newFeatures.length; i < length; i++) {
this.dispatchEvent(new VectorSourceEvent(VectorEventType.ADDFEATURE, newFeatures[i]));
}
};
}
/**
/**
* @param {!module:ol/Collection<module:ol/Feature>} collection Collection.
* @private
*/
VectorSource.prototype.bindFeaturesCollection_ = function(collection) {
bindFeaturesCollection_(collection) {
let modifyingCollection = false;
listen(this, VectorEventType.ADDFEATURE,
function(evt) {
@@ -455,15 +452,15 @@ VectorSource.prototype.bindFeaturesCollection_ = function(collection) {
}
}, this);
this.featuresCollection_ = collection;
};
}
/**
/**
* Remove all features from the source.
* @param {boolean=} opt_fast Skip dispatching of {@link module:ol/source/Vector~VectorSourceEvent#removefeature} events.
* @api
*/
VectorSource.prototype.clear = function(opt_fast) {
clear(opt_fast) {
if (opt_fast) {
for (const featureId in this.featureChangeKeys_) {
const keys = this.featureChangeKeys_[featureId];
@@ -495,10 +492,10 @@ VectorSource.prototype.clear = function(opt_fast) {
const clearEvent = new VectorSourceEvent(VectorEventType.CLEAR);
this.dispatchEvent(clearEvent);
this.changed();
};
}
/**
/**
* Iterate through all features on the source, calling the provided callback
* with each one. If the callback returns any "truthy" value, iteration will
* stop and the function will return the same value.
@@ -510,16 +507,16 @@ VectorSource.prototype.clear = function(opt_fast) {
* @template T
* @api
*/
VectorSource.prototype.forEachFeature = function(callback) {
forEachFeature(callback) {
if (this.featuresRtree_) {
return this.featuresRtree_.forEach(callback);
} else if (this.featuresCollection_) {
return this.featuresCollection_.forEach(callback);
}
};
}
/**
/**
* Iterate through all features whose geometries contain the provided
* coordinate, calling the callback with each feature. If the callback returns
* a "truthy" value, iteration will stop and the function will return the same
@@ -531,7 +528,7 @@ VectorSource.prototype.forEachFeature = function(callback) {
* @return {T|undefined} The return value from the last call to the callback.
* @template T
*/
VectorSource.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, callback) {
forEachFeatureAtCoordinateDirect(coordinate, callback) {
const extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
return this.forEachFeatureInExtent(extent, function(feature) {
const geometry = feature.getGeometry();
@@ -541,10 +538,10 @@ VectorSource.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, c
return undefined;
}
});
};
}
/**
/**
* Iterate through all features whose bounding box intersects the provided
* extent (note that the feature's geometry may not intersect the extent),
* calling the callback with each feature. If the callback returns a "truthy"
@@ -563,16 +560,16 @@ VectorSource.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, c
* @template T
* @api
*/
VectorSource.prototype.forEachFeatureInExtent = function(extent, callback) {
forEachFeatureInExtent(extent, callback) {
if (this.featuresRtree_) {
return this.featuresRtree_.forEachInExtent(extent, callback);
} else if (this.featuresCollection_) {
return this.featuresCollection_.forEach(callback);
}
};
}
/**
/**
* Iterate through all features whose geometry intersects the provided extent,
* calling the callback with each feature. If the callback returns a "truthy"
* value, iteration will stop and the function will return the same value.
@@ -587,7 +584,7 @@ VectorSource.prototype.forEachFeatureInExtent = function(extent, callback) {
* @template T
* @api
*/
VectorSource.prototype.forEachFeatureIntersectingExtent = function(extent, callback) {
forEachFeatureIntersectingExtent(extent, callback) {
return this.forEachFeatureInExtent(extent,
/**
* @param {module:ol/Feature} feature Feature.
@@ -603,27 +600,27 @@ VectorSource.prototype.forEachFeatureIntersectingExtent = function(extent, callb
}
}
});
};
}
/**
/**
* Get the features collection associated with this source. Will be `null`
* unless the source was configured with `useSpatialIndex` set to `false`, or
* with an {@link module:ol/Collection} as `features`.
* @return {module:ol/Collection<module:ol/Feature>} The collection of features.
* @api
*/
VectorSource.prototype.getFeaturesCollection = function() {
getFeaturesCollection() {
return this.featuresCollection_;
};
}
/**
/**
* Get all features on the source in random order.
* @return {Array<module:ol/Feature>} Features.
* @api
*/
VectorSource.prototype.getFeatures = function() {
getFeatures() {
let features;
if (this.featuresCollection_) {
features = this.featuresCollection_.getArray();
@@ -636,25 +633,25 @@ VectorSource.prototype.getFeatures = function() {
return (
/** @type {Array<module:ol/Feature>} */ (features)
);
};
}
/**
/**
* Get all features whose geometry intersects the provided coordinate.
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
* @return {Array<module:ol/Feature>} Features.
* @api
*/
VectorSource.prototype.getFeaturesAtCoordinate = function(coordinate) {
getFeaturesAtCoordinate(coordinate) {
const features = [];
this.forEachFeatureAtCoordinateDirect(coordinate, function(feature) {
features.push(feature);
});
return features;
};
}
/**
/**
* Get all features in the provided extent. Note that this returns an array of
* all features intersecting the given extent in random order (so it may include
* features whose geometries do not intersect the extent).
@@ -665,12 +662,12 @@ VectorSource.prototype.getFeaturesAtCoordinate = function(coordinate) {
* @return {Array<module:ol/Feature>} Features.
* @api
*/
VectorSource.prototype.getFeaturesInExtent = function(extent) {
getFeaturesInExtent(extent) {
return this.featuresRtree_.getInExtent(extent);
};
}
/**
/**
* Get the closest feature to the provided coordinate.
*
* This method is not available when the source is configured with
@@ -682,7 +679,7 @@ VectorSource.prototype.getFeaturesInExtent = function(extent) {
* @return {module:ol/Feature} Closest feature.
* @api
*/
VectorSource.prototype.getClosestFeatureToCoordinate = function(coordinate, opt_filter) {
getClosestFeatureToCoordinate(coordinate, opt_filter) {
// Find the closest feature using branch and bound. We start searching an
// infinite extent, and find the distance from the first feature found. This
// becomes the closest feature. We then compute a smaller extent which any
@@ -722,10 +719,10 @@ VectorSource.prototype.getClosestFeatureToCoordinate = function(coordinate, opt_
}
});
return closestFeature;
};
}
/**
/**
* Get the extent of the features currently in the source.
*
* This method is not available when the source is configured with
@@ -735,12 +732,12 @@ VectorSource.prototype.getClosestFeatureToCoordinate = function(coordinate, opt_
* @return {module:ol/extent~Extent} Extent.
* @api
*/
VectorSource.prototype.getExtent = function(opt_extent) {
getExtent(opt_extent) {
return this.featuresRtree_.getExtent(opt_extent);
};
}
/**
/**
* Get a feature by its identifier (the value returned by feature.getId()).
* Note that the index treats string and numeric identifiers as the same. So
* `source.getFeatureById(2)` will return a feature with id `'2'` or `2`.
@@ -749,53 +746,53 @@ VectorSource.prototype.getExtent = function(opt_extent) {
* @return {module:ol/Feature} The feature (or `null` if not found).
* @api
*/
VectorSource.prototype.getFeatureById = function(id) {
getFeatureById(id) {
const feature = this.idIndex_[id.toString()];
return feature !== undefined ? feature : null;
};
}
/**
/**
* Get the format associated with this source.
*
* @return {module:ol/format/Feature|undefined} The feature format.
* @api
*/
VectorSource.prototype.getFormat = function() {
getFormat() {
return this.format_;
};
}
/**
/**
* @return {boolean} The source can have overlapping geometries.
*/
VectorSource.prototype.getOverlaps = function() {
getOverlaps() {
return this.overlaps_;
};
}
/**
/**
* @override
*/
VectorSource.prototype.getResolutions = function() {};
getResolutions() {}
/**
/**
* Get the url associated with this source.
*
* @return {string|module:ol/featureloader~FeatureUrlFunction|undefined} The url.
* @api
*/
VectorSource.prototype.getUrl = function() {
getUrl() {
return this.url_;
};
}
/**
/**
* @param {module:ol/events/Event} event Event.
* @private
*/
VectorSource.prototype.handleFeatureChange_ = function(event) {
handleFeatureChange_(event) {
const feature = /** @type {module:ol/Feature} */ (event.target);
const featureKey = getUid(feature).toString();
const geometry = feature.getGeometry();
@@ -840,15 +837,15 @@ VectorSource.prototype.handleFeatureChange_ = function(event) {
this.changed();
this.dispatchEvent(new VectorSourceEvent(
VectorEventType.CHANGEFEATURE, feature));
};
}
/**
/**
* Returns true if the feature is contained within the source.
* @param {module:ol/Feature} feature Feature.
* @return {boolean} Has feature.
* @api
*/
VectorSource.prototype.hasFeature = function(feature) {
hasFeature(feature) {
const id = feature.getId();
if (id !== undefined) {
return id in this.idIndex_;
@@ -856,22 +853,22 @@ VectorSource.prototype.hasFeature = function(feature) {
const featureKey = getUid(feature).toString();
return featureKey in this.undefIdIndex_;
}
};
}
/**
/**
* @return {boolean} Is empty.
*/
VectorSource.prototype.isEmpty = function() {
isEmpty() {
return this.featuresRtree_.isEmpty() && isEmpty(this.nullGeometryFeatures_);
};
}
/**
/**
* @param {module:ol/extent~Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {module:ol/proj/Projection} projection Projection.
*/
VectorSource.prototype.loadFeatures = function(extent, resolution, projection) {
loadFeatures(extent, resolution, projection) {
const loadedExtentsRtree = this.loadedExtentsRtree_;
const extentsToLoad = this.strategy_(extent, resolution);
for (let i = 0, ii = extentsToLoad.length; i < ii; ++i) {
@@ -889,15 +886,15 @@ VectorSource.prototype.loadFeatures = function(extent, resolution, projection) {
loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()});
}
}
};
}
/**
/**
* Remove an extent from the list of loaded extents.
* @param {module:ol/extent~Extent} extent Extent.
* @api
*/
VectorSource.prototype.removeLoadedExtent = function(extent) {
removeLoadedExtent(extent) {
const loadedExtentsRtree = this.loadedExtentsRtree_;
let obj;
loadedExtentsRtree.forEachInExtent(extent, function(object) {
@@ -909,17 +906,17 @@ VectorSource.prototype.removeLoadedExtent = function(extent) {
if (obj) {
loadedExtentsRtree.remove(obj);
}
};
}
/**
/**
* Remove a single feature from the source. If you want to remove all features
* at once, use the {@link module:ol/source/Vector~VectorSource#clear #clear()} method
* instead.
* @param {module:ol/Feature} feature Feature to remove.
* @api
*/
VectorSource.prototype.removeFeature = function(feature) {
removeFeature(feature) {
const featureKey = getUid(feature).toString();
if (featureKey in this.nullGeometryFeatures_) {
delete this.nullGeometryFeatures_[featureKey];
@@ -930,15 +927,15 @@ VectorSource.prototype.removeFeature = function(feature) {
}
this.removeFeatureInternal(feature);
this.changed();
};
}
/**
/**
* Remove feature without firing a `change` event.
* @param {module:ol/Feature} feature Feature.
* @protected
*/
VectorSource.prototype.removeFeatureInternal = function(feature) {
removeFeatureInternal(feature) {
const featureKey = getUid(feature).toString();
this.featureChangeKeys_[featureKey].forEach(unlistenByKey);
delete this.featureChangeKeys_[featureKey];
@@ -950,17 +947,17 @@ VectorSource.prototype.removeFeatureInternal = function(feature) {
}
this.dispatchEvent(new VectorSourceEvent(
VectorEventType.REMOVEFEATURE, feature));
};
}
/**
/**
* Remove a feature from the id index. Called internally when the feature id
* may have changed.
* @param {module:ol/Feature} feature The feature.
* @return {boolean} Removed the feature from the index.
* @private
*/
VectorSource.prototype.removeFromIdIndex_ = function(feature) {
removeFromIdIndex_(feature) {
let removed = false;
for (const id in this.idIndex_) {
if (this.idIndex_[id] === feature) {
@@ -970,17 +967,20 @@ VectorSource.prototype.removeFromIdIndex_ = function(feature) {
}
}
return removed;
};
}
/**
/**
* Set the new loader of the source. The next loadFeatures call will use the
* new loader.
* @param {module:ol/featureloader~FeatureLoader} loader The loader to set.
* @api
*/
VectorSource.prototype.setLoader = function(loader) {
setLoader(loader) {
this.loader_ = loader;
};
}
}
export default VectorSource;
+22 -22
View File
@@ -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,29 +136,26 @@ class VectorTile extends UrlTile {
}
}
/**
/**
* @return {boolean} The source can have overlapping geometries.
*/
VectorTile.prototype.getOverlaps = function() {
getOverlaps() {
return this.overlaps_;
};
}
/**
/**
* clear {@link module:ol/TileCache~TileCache} and delete all source tiles
* @api
*/
VectorTile.prototype.clear = function() {
clear() {
this.tileCache.clear();
this.sourceTiles_ = {};
};
}
/**
/**
* @inheritDoc
*/
VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projection) {
getTile(z, x, y, pixelRatio, projection) {
const tileCoordKey = getKeyZXY(z, x, y);
if (this.tileCache.containsKey(tileCoordKey)) {
return (
@@ -180,13 +177,13 @@ VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projection) {
this.tileCache.set(tileCoordKey, tile);
return tile;
}
};
}
/**
/**
* @inheritDoc
*/
VectorTile.prototype.getTileGridForProjection = function(projection) {
getTileGridForProjection(projection) {
const code = projection.getCode();
let tileGrid = this.tileGrids_[code];
if (!tileGrid) {
@@ -197,23 +194,26 @@ VectorTile.prototype.getTileGridForProjection = function(projection) {
sourceTileGrid ? sourceTileGrid.getTileSize(sourceTileGrid.getMinZoom()) : undefined);
}
return tileGrid;
};
}
/**
/**
* @inheritDoc
*/
VectorTile.prototype.getTilePixelRatio = function(pixelRatio) {
getTilePixelRatio(pixelRatio) {
return pixelRatio;
};
}
/**
/**
* @inheritDoc
*/
VectorTile.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
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)];
};
}
}
export default VectorTile;
+33 -35
View File
@@ -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
*/
WMTS.prototype.setUrls = function(urls) {
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
*/
WMTS.prototype.getDimensions = function() {
getDimensions() {
return this.dimensions_;
};
}
/**
/**
* Return the image format of the WMTS source.
* @return {string} Format.
* @api
*/
WMTS.prototype.getFormat = function() {
getFormat() {
return this.format_;
};
}
/**
/**
* Return the layer of the WMTS source.
* @return {string} Layer.
* @api
*/
WMTS.prototype.getLayer = function() {
getLayer() {
return this.layer_;
};
}
/**
/**
* Return the matrix set of the WMTS source.
* @return {string} MatrixSet.
* @api
*/
WMTS.prototype.getMatrixSet = function() {
getMatrixSet() {
return this.matrixSet_;
};
}
/**
/**
* Return the request encoding, either "KVP" or "REST".
* @return {module:ol/source/WMTSRequestEncoding} Request encoding.
* @api
*/
WMTS.prototype.getRequestEncoding = function() {
getRequestEncoding() {
return this.requestEncoding_;
};
}
/**
/**
* Return the style of the WMTS source.
* @return {string} Style.
* @api
*/
WMTS.prototype.getStyle = function() {
getStyle() {
return this.style_;
};
}
/**
/**
* Return the version of the WMTS source.
* @return {string} Version.
* @api
*/
WMTS.prototype.getVersion = function() {
getVersion() {
return this.version_;
};
}
/**
/**
* @private
* @return {string} The key for the current dimensions.
*/
WMTS.prototype.getKeyForDimensions_ = function() {
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
*/
WMTS.prototype.updateDimensions = function(dimensions) {
updateDimensions(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;
+6 -7
View File
@@ -52,17 +52,14 @@ export class CustomTile extends ImageTile {
}
}
/**
/**
* @inheritDoc
*/
CustomTile.prototype.getImage = function() {
getImage() {
if (this.zoomifyImage_) {
return this.zoomifyImage_;
}
const image = ImageTile.prototype.getImage.call(this);
const image = super.getImage();
if (this.state == TileState.LOADED) {
const tileSize = this.tileSize_;
if (image.width == tileSize[0] && image.height == tileSize[1]) {
@@ -77,7 +74,9 @@ CustomTile.prototype.getImage = function() {
} else {
return image;
}
};
}
}
/**