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