Merge pull request #7614 from KlausBenndorf/publicThisArgs
Remove opt_this from the API
This commit is contained in:
@@ -35,6 +35,16 @@ register(proj4);
|
|||||||
|
|
||||||
The map and sources no longer accept a `logo` option. Instead, if you wish to append a logo to your map, add the desired markup directly in your HTML. In addition, you can use the `attributions` property of a source to display arbitrary markup per-source with the attribution control.
|
The map and sources no longer accept a `logo` option. Instead, if you wish to append a logo to your map, add the desired markup directly in your HTML. In addition, you can use the `attributions` property of a source to display arbitrary markup per-source with the attribution control.
|
||||||
|
|
||||||
|
#### Removal of optional this arguments.
|
||||||
|
|
||||||
|
The following methods did get the optional this (i.e. opt_this) arguments removed. Please use closures, the es6 arrow function or the bind method to achieve this effect (Bind is explained here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
|
||||||
|
|
||||||
|
* Collection#forEach
|
||||||
|
* geom/LineString#forEachSegment
|
||||||
|
* Observable#on, #once, #un
|
||||||
|
* source/TileUTFGrid#forDataAtCoordinateAndResolution
|
||||||
|
* source/Vector#forEachFeature, #forEachFeatureInExtent, #forEachFeatureIntersectingExtent
|
||||||
|
|
||||||
### v4.6.0
|
### v4.6.0
|
||||||
|
|
||||||
#### Renamed `exceedLength` option of `ol.style.Text` to `overflow`
|
#### Renamed `exceedLength` option of `ol.style.Text` to `overflow`
|
||||||
|
|||||||
@@ -101,18 +101,15 @@ _ol_Collection_.prototype.extend = function(arr) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over each element, calling the provided callback.
|
* Iterate over each element, calling the provided callback.
|
||||||
* @param {function(this: S, T, number, Array.<T>): *} f The function to call
|
* @param {function(T, number, Array.<T>): *} f The function to call
|
||||||
* for every element. This function takes 3 arguments (the element, the
|
* for every element. This function takes 3 arguments (the element, the
|
||||||
* index and the array). The return value is ignored.
|
* index and the array). The return value is ignored.
|
||||||
* @param {S=} opt_this The object to use as `this` in `f`.
|
|
||||||
* @template S
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Collection_.prototype.forEach = function(f, opt_this) {
|
_ol_Collection_.prototype.forEach = function(f) {
|
||||||
var fn = (opt_this) ? f.bind(opt_this) : f;
|
|
||||||
var array = this.array_;
|
var array = this.array_;
|
||||||
for (var i = 0, ii = array.length; i < ii; ++i) {
|
for (var i = 0, ii = array.length; i < ii; ++i) {
|
||||||
fn(array[i], i, array);
|
f(array[i], i, array);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -91,23 +91,22 @@ _ol_Observable_.prototype.getRevision = function() {
|
|||||||
* Listen for a certain type of event.
|
* Listen for a certain type of event.
|
||||||
* @param {string|Array.<string>} type The event type or array of event types.
|
* @param {string|Array.<string>} type The event type or array of event types.
|
||||||
* @param {function(?): ?} listener The listener function.
|
* @param {function(?): ?} listener The listener function.
|
||||||
* @param {Object=} opt_this The object to use as `this` in `listener`.
|
|
||||||
* @return {ol.EventsKey|Array.<ol.EventsKey>} Unique key for the listener. If
|
* @return {ol.EventsKey|Array.<ol.EventsKey>} Unique key for the listener. If
|
||||||
* called with an array of event types as the first argument, the return
|
* called with an array of event types as the first argument, the return
|
||||||
* will be an array of keys.
|
* will be an array of keys.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Observable_.prototype.on = function(type, listener, opt_this) {
|
_ol_Observable_.prototype.on = function(type, listener) {
|
||||||
if (Array.isArray(type)) {
|
if (Array.isArray(type)) {
|
||||||
var len = type.length;
|
var len = type.length;
|
||||||
var keys = new Array(len);
|
var keys = new Array(len);
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
keys[i] = _ol_events_.listen(this, type[i], listener, opt_this);
|
keys[i] = _ol_events_.listen(this, type[i], listener);
|
||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
} else {
|
} else {
|
||||||
return _ol_events_.listen(
|
return _ol_events_.listen(
|
||||||
this, /** @type {string} */ (type), listener, opt_this);
|
this, /** @type {string} */ (type), listener);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -116,23 +115,22 @@ _ol_Observable_.prototype.on = function(type, listener, opt_this) {
|
|||||||
* Listen once for a certain type of event.
|
* Listen once for a certain type of event.
|
||||||
* @param {string|Array.<string>} type The event type or array of event types.
|
* @param {string|Array.<string>} type The event type or array of event types.
|
||||||
* @param {function(?): ?} listener The listener function.
|
* @param {function(?): ?} listener The listener function.
|
||||||
* @param {Object=} opt_this The object to use as `this` in `listener`.
|
|
||||||
* @return {ol.EventsKey|Array.<ol.EventsKey>} Unique key for the listener. If
|
* @return {ol.EventsKey|Array.<ol.EventsKey>} Unique key for the listener. If
|
||||||
* called with an array of event types as the first argument, the return
|
* called with an array of event types as the first argument, the return
|
||||||
* will be an array of keys.
|
* will be an array of keys.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Observable_.prototype.once = function(type, listener, opt_this) {
|
_ol_Observable_.prototype.once = function(type, listener) {
|
||||||
if (Array.isArray(type)) {
|
if (Array.isArray(type)) {
|
||||||
var len = type.length;
|
var len = type.length;
|
||||||
var keys = new Array(len);
|
var keys = new Array(len);
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
keys[i] = _ol_events_.listenOnce(this, type[i], listener, opt_this);
|
keys[i] = _ol_events_.listenOnce(this, type[i], listener);
|
||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
} else {
|
} else {
|
||||||
return _ol_events_.listenOnce(
|
return _ol_events_.listenOnce(
|
||||||
this, /** @type {string} */ (type), listener, opt_this);
|
this, /** @type {string} */ (type), listener);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -141,18 +139,16 @@ _ol_Observable_.prototype.once = function(type, listener, opt_this) {
|
|||||||
* Unlisten for a certain type of event.
|
* Unlisten for a certain type of event.
|
||||||
* @param {string|Array.<string>} type The event type or array of event types.
|
* @param {string|Array.<string>} type The event type or array of event types.
|
||||||
* @param {function(?): ?} listener The listener function.
|
* @param {function(?): ?} listener The listener function.
|
||||||
* @param {Object=} opt_this The object which was used as `this` by the
|
|
||||||
* `listener`.
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Observable_.prototype.un = function(type, listener, opt_this) {
|
_ol_Observable_.prototype.un = function(type, listener) {
|
||||||
if (Array.isArray(type)) {
|
if (Array.isArray(type)) {
|
||||||
for (var i = 0, ii = type.length; i < ii; ++i) {
|
for (var i = 0, ii = type.length; i < ii; ++i) {
|
||||||
_ol_events_.unlisten(this, type[i], listener, opt_this);
|
_ol_events_.unlisten(this, type[i], listener);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_ol_events_.unlisten(this, /** @type {string} */ (type), listener, opt_this);
|
_ol_events_.unlisten(this, /** @type {string} */ (type), listener);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export default _ol_Observable_;
|
export default _ol_Observable_;
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ var _ol_PluggableMap_ = function(options) {
|
|||||||
*/
|
*/
|
||||||
function(control) {
|
function(control) {
|
||||||
control.setMap(this);
|
control.setMap(this);
|
||||||
}, this);
|
}.bind(this));
|
||||||
|
|
||||||
_ol_events_.listen(this.controls, CollectionEventType.ADD,
|
_ol_events_.listen(this.controls, CollectionEventType.ADD,
|
||||||
/**
|
/**
|
||||||
@@ -382,7 +382,7 @@ var _ol_PluggableMap_ = function(options) {
|
|||||||
*/
|
*/
|
||||||
function(interaction) {
|
function(interaction) {
|
||||||
interaction.setMap(this);
|
interaction.setMap(this);
|
||||||
}, this);
|
}.bind(this));
|
||||||
|
|
||||||
_ol_events_.listen(this.interactions, CollectionEventType.ADD,
|
_ol_events_.listen(this.interactions, CollectionEventType.ADD,
|
||||||
/**
|
/**
|
||||||
@@ -400,7 +400,7 @@ var _ol_PluggableMap_ = function(options) {
|
|||||||
event.element.setMap(null);
|
event.element.setMap(null);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.overlays_.forEach(this.addOverlayInternal_, this);
|
this.overlays_.forEach(this.addOverlayInternal_.bind(this));
|
||||||
|
|
||||||
_ol_events_.listen(this.overlays_, CollectionEventType.ADD,
|
_ol_events_.listen(this.overlays_, CollectionEventType.ADD,
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ var OverviewMap = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
function(layer) {
|
function(layer) {
|
||||||
ovmap.addLayer(layer);
|
ovmap.addLayer(layer);
|
||||||
}, this);
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
var box = document.createElement('DIV');
|
var box = document.createElement('DIV');
|
||||||
|
|||||||
@@ -114,15 +114,13 @@ LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis
|
|||||||
*
|
*
|
||||||
* @param {function(this: S, ol.Coordinate, ol.Coordinate): T} callback Function
|
* @param {function(this: S, ol.Coordinate, ol.Coordinate): T} callback Function
|
||||||
* called for each segment.
|
* called for each segment.
|
||||||
* @param {S=} opt_this The object to be used as the value of 'this'
|
|
||||||
* within callback.
|
|
||||||
* @return {T|boolean} Value.
|
* @return {T|boolean} Value.
|
||||||
* @template T,S
|
* @template T,S
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
LineString.prototype.forEachSegment = function(callback, opt_this) {
|
LineString.prototype.forEachSegment = function(callback) {
|
||||||
return _ol_geom_flat_segments_.forEach(this.flatCoordinates, 0,
|
return _ol_geom_flat_segments_.forEach(this.flatCoordinates, 0,
|
||||||
this.flatCoordinates.length, this.stride, callback, opt_this);
|
this.flatCoordinates.length, this.stride, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ var _ol_interaction_Modify_ = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.features_ = features;
|
this.features_ = features;
|
||||||
|
|
||||||
this.features_.forEach(this.addFeature_, this);
|
this.features_.forEach(this.addFeature_.bind(this));
|
||||||
_ol_events_.listen(this.features_, CollectionEventType.ADD,
|
_ol_events_.listen(this.features_, CollectionEventType.ADD,
|
||||||
this.handleFeatureAdd_, this);
|
this.handleFeatureAdd_, this);
|
||||||
_ol_events_.listen(this.features_, CollectionEventType.REMOVE,
|
_ol_events_.listen(this.features_, CollectionEventType.REMOVE,
|
||||||
|
|||||||
@@ -313,12 +313,12 @@ _ol_interaction_Select_.prototype.setMap = function(map) {
|
|||||||
var selectedFeatures =
|
var selectedFeatures =
|
||||||
this.featureOverlay_.getSource().getFeaturesCollection();
|
this.featureOverlay_.getSource().getFeaturesCollection();
|
||||||
if (currentMap) {
|
if (currentMap) {
|
||||||
selectedFeatures.forEach(currentMap.unskipFeature, currentMap);
|
selectedFeatures.forEach(currentMap.unskipFeature.bind(currentMap));
|
||||||
}
|
}
|
||||||
Interaction.prototype.setMap.call(this, map);
|
Interaction.prototype.setMap.call(this, map);
|
||||||
this.featureOverlay_.setMap(map);
|
this.featureOverlay_.setMap(map);
|
||||||
if (map) {
|
if (map) {
|
||||||
selectedFeatures.forEach(map.skipFeature, map);
|
selectedFeatures.forEach(map.skipFeature.bind(map));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ _ol_interaction_Snap_.prototype.setMap = function(map) {
|
|||||||
if (currentMap) {
|
if (currentMap) {
|
||||||
keys.forEach(_ol_events_.unlistenByKey);
|
keys.forEach(_ol_events_.unlistenByKey);
|
||||||
keys.length = 0;
|
keys.length = 0;
|
||||||
features.forEach(this.forEachFeatureRemove_, this);
|
features.forEach(this.forEachFeatureRemove_.bind(this));
|
||||||
}
|
}
|
||||||
_ol_interaction_Pointer_.prototype.setMap.call(this, map);
|
_ol_interaction_Pointer_.prototype.setMap.call(this, map);
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ _ol_interaction_Snap_.prototype.setMap = function(map) {
|
|||||||
this.handleFeatureRemove_, this)
|
this.handleFeatureRemove_, this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
features.forEach(this.forEachFeatureAdd_, this);
|
features.forEach(this.forEachFeatureAdd_.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -613,7 +613,7 @@ _ol_interaction_Snap_.handleEvent_ = function(evt) {
|
|||||||
_ol_interaction_Snap_.handleUpEvent_ = function(evt) {
|
_ol_interaction_Snap_.handleUpEvent_ = function(evt) {
|
||||||
var featuresToUpdate = _ol_obj_.getValues(this.pendingFeatures_);
|
var featuresToUpdate = _ol_obj_.getValues(this.pendingFeatures_);
|
||||||
if (featuresToUpdate.length) {
|
if (featuresToUpdate.length) {
|
||||||
featuresToUpdate.forEach(this.updateFeature_, this);
|
featuresToUpdate.forEach(this.updateFeature_.bind(this));
|
||||||
this.pendingFeatures_ = {};
|
this.pendingFeatures_ = {};
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ _ol_pointer_PointerEventHandler_.prototype.registerSource = function(name, sourc
|
|||||||
if (handler) {
|
if (handler) {
|
||||||
this.eventMap_[e] = handler.bind(s);
|
this.eventMap_[e] = handler.bind(s);
|
||||||
}
|
}
|
||||||
}, this);
|
}.bind(this));
|
||||||
this.eventSourceList_.push(s);
|
this.eventSourceList_.push(s);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -178,7 +178,7 @@ _ol_pointer_PointerEventHandler_.prototype.eventHandler_ = function(inEvent) {
|
|||||||
_ol_pointer_PointerEventHandler_.prototype.addEvents_ = function(events) {
|
_ol_pointer_PointerEventHandler_.prototype.addEvents_ = function(events) {
|
||||||
events.forEach(function(eventName) {
|
events.forEach(function(eventName) {
|
||||||
_ol_events_.listen(this.element_, eventName, this.eventHandler_, this);
|
_ol_events_.listen(this.element_, eventName, this.eventHandler_, this);
|
||||||
}, this);
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ _ol_pointer_PointerEventHandler_.prototype.addEvents_ = function(events) {
|
|||||||
_ol_pointer_PointerEventHandler_.prototype.removeEvents_ = function(events) {
|
_ol_pointer_PointerEventHandler_.prototype.removeEvents_ = function(events) {
|
||||||
events.forEach(function(e) {
|
events.forEach(function(e) {
|
||||||
_ol_events_.unlisten(this.element_, e, this.eventHandler_, this);
|
_ol_events_.unlisten(this.element_, e, this.eventHandler_, this);
|
||||||
}, this);
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ _ol_renderer_webgl_VectorLayer_.prototype.prepareFrame = function(frameState, la
|
|||||||
features.push(feature);
|
features.push(feature);
|
||||||
}, this);
|
}, this);
|
||||||
features.sort(vectorLayerRenderOrder);
|
features.sort(vectorLayerRenderOrder);
|
||||||
features.forEach(renderFeature, this);
|
features.forEach(renderFeature.bind(this));
|
||||||
} else {
|
} else {
|
||||||
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
|
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ _ol_reproj_Tile_.prototype.reproject_ = function() {
|
|||||||
image: tile.getImage()
|
image: tile.getImage()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, this);
|
}.bind(this));
|
||||||
this.sourceTiles_.length = 0;
|
this.sourceTiles_.length = 0;
|
||||||
|
|
||||||
if (sources.length === 0) {
|
if (sources.length === 0) {
|
||||||
@@ -281,7 +281,7 @@ _ol_reproj_Tile_.prototype.load = function() {
|
|||||||
}, this);
|
}, this);
|
||||||
this.sourcesListenerKeys_.push(sourceListenKey);
|
this.sourcesListenerKeys_.push(sourceListenKey);
|
||||||
}
|
}
|
||||||
}, this);
|
}.bind(this));
|
||||||
|
|
||||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||||
var state = tile.getState();
|
var state = tile.getState();
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ var _ol_reproj_Triangulation_ = function(sourceProj, targetProj, targetExtent,
|
|||||||
triangle.source = newTriangle;
|
triangle.source = newTriangle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, this);
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
transformInvCache = {};
|
transformInvCache = {};
|
||||||
|
|||||||
@@ -124,28 +124,26 @@ _ol_source_TileUTFGrid_.prototype.getTemplate = function() {
|
|||||||
* in case of an error).
|
* in case of an error).
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @param {function(this: T, *)} callback Callback.
|
* @param {function(*)} callback Callback.
|
||||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
|
||||||
* @param {boolean=} opt_request If `true` the callback is always async.
|
* @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
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_source_TileUTFGrid_.prototype.forDataAtCoordinateAndResolution = function(
|
_ol_source_TileUTFGrid_.prototype.forDataAtCoordinateAndResolution = function(
|
||||||
coordinate, resolution, callback, opt_this, opt_request) {
|
coordinate, resolution, callback, opt_request) {
|
||||||
if (this.tileGrid) {
|
if (this.tileGrid) {
|
||||||
var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
|
var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
|
||||||
coordinate, resolution);
|
coordinate, resolution);
|
||||||
var tile = /** @type {!ol.source.TileUTFGrid.Tile_} */(this.getTile(
|
var tile = /** @type {!ol.source.TileUTFGrid.Tile_} */(this.getTile(
|
||||||
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
|
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
|
||||||
tile.forDataAtCoordinate(coordinate, callback, opt_this, opt_request);
|
tile.forDataAtCoordinate(coordinate, callback, null, opt_request);
|
||||||
} else {
|
} else {
|
||||||
if (opt_request === true) {
|
if (opt_request === true) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
callback.call(opt_this, null);
|
callback(null);
|
||||||
}, 0);
|
}, 0);
|
||||||
} else {
|
} else {
|
||||||
callback.call(opt_this, null);
|
callback(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -379,18 +379,17 @@ _ol_source_Vector_.prototype.clear = function(opt_fast) {
|
|||||||
* 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.
|
||||||
*
|
*
|
||||||
* @param {function(this: T, ol.Feature): S} callback Called with each feature
|
* @param {function(ol.Feature): T} callback Called with each feature
|
||||||
* on the source. Return a truthy value to stop iteration.
|
* on the source. Return a truthy value to stop iteration.
|
||||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @return {S|undefined} The return value from the last call to the callback.
|
* @template T
|
||||||
* @template T,S
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_source_Vector_.prototype.forEachFeature = function(callback, opt_this) {
|
_ol_source_Vector_.prototype.forEachFeature = function(callback) {
|
||||||
if (this.featuresRtree_) {
|
if (this.featuresRtree_) {
|
||||||
return this.featuresRtree_.forEach(callback, opt_this);
|
return this.featuresRtree_.forEach(callback);
|
||||||
} else if (this.featuresCollection_) {
|
} else if (this.featuresCollection_) {
|
||||||
return this.featuresCollection_.forEach(callback, opt_this);
|
return this.featuresCollection_.forEach(callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -402,18 +401,17 @@ _ol_source_Vector_.prototype.forEachFeature = function(callback, opt_this) {
|
|||||||
* value.
|
* value.
|
||||||
*
|
*
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {function(this: T, ol.Feature): S} callback Called with each feature
|
* @param {function(ol.Feature): T} callback Called with each feature
|
||||||
* whose goemetry contains the provided coordinate.
|
* whose goemetry contains the provided coordinate.
|
||||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @return {S|undefined} The return value from the last call to the callback.
|
* @template T
|
||||||
* @template T,S
|
|
||||||
*/
|
*/
|
||||||
_ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, callback, opt_this) {
|
_ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, callback) {
|
||||||
var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
|
var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
|
||||||
return this.forEachFeatureInExtent(extent, function(feature) {
|
return this.forEachFeatureInExtent(extent, function(feature) {
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (geometry.intersectsCoordinate(coordinate)) {
|
if (geometry.intersectsCoordinate(coordinate)) {
|
||||||
return callback.call(opt_this, feature);
|
return callback(feature);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -435,18 +433,17 @@ _ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordin
|
|||||||
* features, equivalent to {@link ol.source.Vector#forEachFeature}.
|
* features, equivalent to {@link ol.source.Vector#forEachFeature}.
|
||||||
*
|
*
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {function(this: T, ol.Feature): S} callback Called with each feature
|
* @param {function(ol.Feature): T} callback Called with each feature
|
||||||
* whose bounding box intersects the provided extent.
|
* whose bounding box intersects the provided extent.
|
||||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @return {S|undefined} The return value from the last call to the callback.
|
* @template T
|
||||||
* @template T,S
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback, opt_this) {
|
_ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback) {
|
||||||
if (this.featuresRtree_) {
|
if (this.featuresRtree_) {
|
||||||
return this.featuresRtree_.forEachInExtent(extent, callback, opt_this);
|
return this.featuresRtree_.forEachInExtent(extent, callback);
|
||||||
} else if (this.featuresCollection_) {
|
} else if (this.featuresCollection_) {
|
||||||
return this.featuresCollection_.forEach(callback, opt_this);
|
return this.featuresCollection_.forEach(callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -461,24 +458,23 @@ _ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback,
|
|||||||
* source.forEachFeatureInExtent()} method instead.
|
* source.forEachFeatureInExtent()} method instead.
|
||||||
*
|
*
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {function(this: T, ol.Feature): S} callback Called with each feature
|
* @param {function(ol.Feature): T} callback Called with each feature
|
||||||
* whose geometry intersects the provided extent.
|
* whose geometry intersects the provided extent.
|
||||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @return {S|undefined} The return value from the last call to the callback.
|
* @template T
|
||||||
* @template T,S
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_source_Vector_.prototype.forEachFeatureIntersectingExtent = function(extent, callback, opt_this) {
|
_ol_source_Vector_.prototype.forEachFeatureIntersectingExtent = function(extent, callback) {
|
||||||
return this.forEachFeatureInExtent(extent,
|
return this.forEachFeatureInExtent(extent,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {S|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 S
|
* @template T
|
||||||
*/
|
*/
|
||||||
function(feature) {
|
function(feature) {
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (geometry.intersectsExtent(extent)) {
|
if (geometry.intersectsExtent(extent)) {
|
||||||
var result = callback.call(opt_this, feature);
|
var result = callback(feature);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,17 +106,6 @@ describe('ol.collection', function() {
|
|||||||
expect(cb.callCount).to.eql(2);
|
expect(cb.callCount).to.eql(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('scope', function() {
|
|
||||||
it('callbacks get the correct scope', function() {
|
|
||||||
var collection = new _ol_Collection_([0]);
|
|
||||||
var that;
|
|
||||||
var uniqueObj = {};
|
|
||||||
collection.forEach(function(elem) {
|
|
||||||
that = this;
|
|
||||||
}, uniqueObj);
|
|
||||||
expect(that).to.be(uniqueObj);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('remove', function() {
|
describe('remove', function() {
|
||||||
|
|||||||
@@ -41,15 +41,6 @@ describe('ol.Observable', function() {
|
|||||||
expect(listener.callCount).to.be(2);
|
expect(listener.callCount).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts an optional `this` arg for the listener', function() {
|
|
||||||
var thisArg = {};
|
|
||||||
observable.on('foo', listener, thisArg);
|
|
||||||
|
|
||||||
observable.dispatchEvent('foo');
|
|
||||||
expect(listener.calledOnce).to.be(true);
|
|
||||||
expect(listener.calledOn(thisArg)).to.be(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns a listener key', function() {
|
it('returns a listener key', function() {
|
||||||
var key = observable.on('foo', listener);
|
var key = observable.on('foo', listener);
|
||||||
|
|
||||||
@@ -106,15 +97,6 @@ describe('ol.Observable', function() {
|
|||||||
expect(listener.callCount).to.be(2);
|
expect(listener.callCount).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts an optional `this` arg for the listener', function() {
|
|
||||||
var thisArg = {};
|
|
||||||
observable.once('foo', listener, thisArg);
|
|
||||||
|
|
||||||
observable.dispatchEvent('foo');
|
|
||||||
expect(listener.calledOnce).to.be(true);
|
|
||||||
expect(listener.calledOn(thisArg)).to.be(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns a listener key', function() {
|
it('returns a listener key', function() {
|
||||||
var key = observable.once('foo', listener);
|
var key = observable.once('foo', listener);
|
||||||
|
|
||||||
@@ -141,24 +123,6 @@ describe('ol.Observable', function() {
|
|||||||
expect(listener.calledOnce).to.be(true);
|
expect(listener.calledOnce).to.be(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts a `this` arg', function() {
|
|
||||||
var thisArg = {};
|
|
||||||
observable.on('foo', listener, thisArg);
|
|
||||||
|
|
||||||
observable.dispatchEvent('foo');
|
|
||||||
expect(listener.calledOnce).to.be(true);
|
|
||||||
|
|
||||||
// will not unregister without the same thisArg
|
|
||||||
observable.un('foo', listener);
|
|
||||||
observable.dispatchEvent('foo');
|
|
||||||
expect(listener.callCount).to.be(2);
|
|
||||||
|
|
||||||
// properly unregister by providing the same thisArg
|
|
||||||
observable.un('foo', listener, thisArg);
|
|
||||||
observable.dispatchEvent('foo');
|
|
||||||
expect(listener.callCount).to.be(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ol.Observable.unByKey()', function() {
|
describe('ol.Observable.unByKey()', function() {
|
||||||
|
|||||||
@@ -253,18 +253,7 @@ describe('ol.source.TileUTFGrid', function() {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
source.forDataAtCoordinateAndResolution(
|
source.forDataAtCoordinateAndResolution(
|
||||||
bonn3857, resolutionZoom1, callback, null, true
|
bonn3857, resolutionZoom1, callback, true
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls callback with correct `this` bound', function(done) {
|
|
||||||
var scope = {foo: 'bar'};
|
|
||||||
var callback = function(data) {
|
|
||||||
expect(this).to.be(scope);
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
source.forDataAtCoordinateAndResolution(
|
|
||||||
bonn3857, resolutionZoom1, callback, scope, true
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -275,7 +264,7 @@ describe('ol.source.TileUTFGrid', function() {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
source.forDataAtCoordinateAndResolution(
|
source.forDataAtCoordinateAndResolution(
|
||||||
noState3857, resolutionZoom1, callback, null, true
|
noState3857, resolutionZoom1, callback, true
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user