Merge pull request #1528 from elemoine/vector-api-foreachfeature

[vector-api] Change forEachFeatureAtPixel signature
This commit is contained in:
Éric Lemoine
2014-01-17 07:18:44 -08:00
7 changed files with 32 additions and 28 deletions

View File

@@ -487,24 +487,28 @@ ol.Map.prototype.disposeInternal = function() {
* @param {ol.Pixel} pixel Pixel.
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
* callback.
* @param {S=} opt_obj Scope for feature callback.
* @param {function(this: U, ol.layer.Layer): boolean=} opt_layerFunction Layer
* function, only layers which are visible and for which this function
* returns `true` will be tested for features. By default, all visible
* layers will be tested.
* @param {U=} opt_obj2 Scope for layer function.
* @param {S=} opt_this Value to use as `this` when executing `callback`.
* @param {function(this: U, ol.layer.Layer): boolean=} opt_layerFilter Layer
* filter function, only layers which are visible and for which this
* function returns `true` will be tested for features. By default, all
* visible layers will be tested.
* @param {U=} opt_this2 Value to use as `this` when executing `layerFilter`.
* @return {T|undefined} Callback result.
* @template S,T,U
*/
ol.Map.prototype.forEachFeatureAtPixel =
function(pixel, callback, opt_obj, opt_layerFunction, opt_obj2) {
function(pixel, callback, opt_this, opt_layerFilter, opt_this2) {
if (goog.isNull(this.frameState_)) {
return;
}
var coordinate = this.getCoordinateFromPixel(pixel);
var thisArg = goog.isDef(opt_this) ? opt_this : null;
var layerFilter = goog.isDef(opt_layerFilter) ?
opt_layerFilter : goog.functions.TRUE;
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
return this.renderer_.forEachFeatureAtPixel(
coordinate, this.frameState_, callback, opt_obj,
opt_layerFunction, opt_obj2);
coordinate, this.frameState_, callback, thisArg,
layerFilter, thisArg2);
};

View File

@@ -45,7 +45,7 @@ goog.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.Layer);
* @inheritDoc
*/
ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) {
function(coordinate, frameState, callback, thisArg) {
var layer = this.getLayer();
var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.Image);
@@ -58,7 +58,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
* @return {?} Callback result.
*/
function(feature) {
return callback.call(opt_this, feature, this);
return callback.call(thisArg, feature, layer);
});
};

View File

@@ -89,7 +89,7 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
* @inheritDoc
*/
ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) {
function(coordinate, frameState, callback, thisArg) {
if (goog.isNull(this.replayGroup_)) {
return undefined;
} else {
@@ -109,7 +109,7 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
function(geometry, data) {
var feature = /** @type {ol.Feature} */ (data);
goog.asserts.assert(goog.isDef(feature));
return callback.call(opt_this, feature, layer);
return callback.call(thisArg, feature, layer);
});
}
};

View File

@@ -50,7 +50,7 @@ goog.inherits(ol.renderer.dom.ImageLayer, ol.renderer.dom.Layer);
* @inheritDoc
*/
ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) {
function(coordinate, frameState, callback, thisArg) {
var layer = this.getLayer();
var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.Image);
@@ -63,7 +63,7 @@ ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
* @return {?} Callback result.
*/
function(feature) {
return callback.call(opt_this, feature, this);
return callback.call(thisArg, feature, layer);
});
};

View File

@@ -49,7 +49,7 @@ goog.inherits(ol.renderer.Layer, goog.Disposable);
* @param {ol.FrameState} frameState Frame state.
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
* callback.
* @param {S=} opt_this Object to use as `this` in `callback`.
* @param {S} thisArg Value to use as `this` when executing `callback`.
* @return {T|undefined} Callback result.
* @template S,T
*/

View File

@@ -85,26 +85,26 @@ ol.renderer.Map.prototype.disposeInternal = function() {
* @param {ol.FrameState} frameState FrameState.
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
* callback.
* @param {S=} opt_obj Scope for feature callback.
* @param {function(this: U, ol.layer.Layer): boolean=} opt_layerFunction Layer
* function.
* @param {U=} opt_obj2 Scope for layer function.
* @param {S} thisArg Value to use as `this` when executing `callback`.
* @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
* function, only layers which are visible and for which this function
* returns `true` will be tested for features. By default, all visible
* layers will be tested.
* @param {U} thisArg2 Value to use as `this` when executing `layerFilter`.
* @return {T|undefined} Callback result.
* @template S,T,U
*/
ol.renderer.Map.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_obj,
opt_layerFunction, opt_obj2) {
var layerFunction = goog.isDef(opt_layerFunction) ?
opt_layerFunction : goog.functions.TRUE;
function(coordinate, frameState, callback, thisArg,
layerFilter, thisArg2) {
var layersArray = this.map_.getLayerGroup().getLayersArray();
var i;
for (i = layersArray.length - 1; i >= 0; --i) {
var layer = layersArray[i];
if (layer.getVisible() && layerFunction.call(opt_obj2, layer)) {
if (layer.getVisible() && layerFilter.call(thisArg2, layer)) {
var layerRenderer = this.getLayerRenderer(layer);
var result = layerRenderer.forEachFeatureAtPixel(
coordinate, frameState, callback, opt_obj);
coordinate, frameState, callback, thisArg);
if (result) {
return result;
}

View File

@@ -76,7 +76,7 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
* @inheritDoc
*/
ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) {
function(coordinate, frameState, callback, thisArg) {
var layer = this.getLayer();
var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.Image);
@@ -89,7 +89,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel =
* @return {?} Callback result.
*/
function(feature) {
return callback.call(opt_this, feature, this);
return callback.call(thisArg, feature, layer);
});
};