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
+13 -9
View File
@@ -487,24 +487,28 @@ ol.Map.prototype.disposeInternal = function() {
* @param {ol.Pixel} pixel Pixel. * @param {ol.Pixel} pixel Pixel.
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature * @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
* callback. * callback.
* @param {S=} opt_obj Scope for feature callback. * @param {S=} opt_this Value to use as `this` when executing `callback`.
* @param {function(this: U, ol.layer.Layer): boolean=} opt_layerFunction Layer * @param {function(this: U, ol.layer.Layer): boolean=} opt_layerFilter Layer
* function, only layers which are visible and for which this function * filter function, only layers which are visible and for which this
* returns `true` will be tested for features. By default, all visible * function returns `true` will be tested for features. By default, all
* layers will be tested. * visible layers will be tested.
* @param {U=} opt_obj2 Scope for layer function. * @param {U=} opt_this2 Value to use as `this` when executing `layerFilter`.
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template S,T,U * @template S,T,U
*/ */
ol.Map.prototype.forEachFeatureAtPixel = 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_)) { if (goog.isNull(this.frameState_)) {
return; return;
} }
var coordinate = this.getCoordinateFromPixel(pixel); 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( return this.renderer_.forEachFeatureAtPixel(
coordinate, this.frameState_, callback, opt_obj, coordinate, this.frameState_, callback, thisArg,
opt_layerFunction, opt_obj2); layerFilter, thisArg2);
}; };
@@ -45,7 +45,7 @@ goog.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.Layer);
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel = ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) { function(coordinate, frameState, callback, thisArg) {
var layer = this.getLayer(); var layer = this.getLayer();
var source = layer.getSource(); var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.Image); goog.asserts.assertInstanceof(source, ol.source.Image);
@@ -58,7 +58,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
* @return {?} Callback result. * @return {?} Callback result.
*/ */
function(feature) { function(feature) {
return callback.call(opt_this, feature, this); return callback.call(thisArg, feature, layer);
}); });
}; };
@@ -89,7 +89,7 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel = ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) { function(coordinate, frameState, callback, thisArg) {
if (goog.isNull(this.replayGroup_)) { if (goog.isNull(this.replayGroup_)) {
return undefined; return undefined;
} else { } else {
@@ -109,7 +109,7 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
function(geometry, data) { function(geometry, data) {
var feature = /** @type {ol.Feature} */ (data); var feature = /** @type {ol.Feature} */ (data);
goog.asserts.assert(goog.isDef(feature)); goog.asserts.assert(goog.isDef(feature));
return callback.call(opt_this, feature, layer); return callback.call(thisArg, feature, layer);
}); });
} }
}; };
+2 -2
View File
@@ -50,7 +50,7 @@ goog.inherits(ol.renderer.dom.ImageLayer, ol.renderer.dom.Layer);
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel = ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) { function(coordinate, frameState, callback, thisArg) {
var layer = this.getLayer(); var layer = this.getLayer();
var source = layer.getSource(); var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.Image); goog.asserts.assertInstanceof(source, ol.source.Image);
@@ -63,7 +63,7 @@ ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
* @return {?} Callback result. * @return {?} Callback result.
*/ */
function(feature) { function(feature) {
return callback.call(opt_this, feature, this); return callback.call(thisArg, feature, layer);
}); });
}; };
+1 -1
View File
@@ -49,7 +49,7 @@ goog.inherits(ol.renderer.Layer, goog.Disposable);
* @param {ol.FrameState} frameState Frame state. * @param {ol.FrameState} frameState Frame state.
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature * @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
* callback. * 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. * @return {T|undefined} Callback result.
* @template S,T * @template S,T
*/ */
+10 -10
View File
@@ -85,26 +85,26 @@ ol.renderer.Map.prototype.disposeInternal = function() {
* @param {ol.FrameState} frameState FrameState. * @param {ol.FrameState} frameState FrameState.
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature * @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
* callback. * callback.
* @param {S=} opt_obj Scope for feature callback. * @param {S} thisArg Value to use as `this` when executing `callback`.
* @param {function(this: U, ol.layer.Layer): boolean=} opt_layerFunction Layer * @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
* function. * function, only layers which are visible and for which this function
* @param {U=} opt_obj2 Scope for layer 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. * @return {T|undefined} Callback result.
* @template S,T,U * @template S,T,U
*/ */
ol.renderer.Map.prototype.forEachFeatureAtPixel = ol.renderer.Map.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_obj, function(coordinate, frameState, callback, thisArg,
opt_layerFunction, opt_obj2) { layerFilter, thisArg2) {
var layerFunction = goog.isDef(opt_layerFunction) ?
opt_layerFunction : goog.functions.TRUE;
var layersArray = this.map_.getLayerGroup().getLayersArray(); var layersArray = this.map_.getLayerGroup().getLayersArray();
var i; var i;
for (i = layersArray.length - 1; i >= 0; --i) { for (i = layersArray.length - 1; i >= 0; --i) {
var layer = layersArray[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 layerRenderer = this.getLayerRenderer(layer);
var result = layerRenderer.forEachFeatureAtPixel( var result = layerRenderer.forEachFeatureAtPixel(
coordinate, frameState, callback, opt_obj); coordinate, frameState, callback, thisArg);
if (result) { if (result) {
return result; return result;
} }
@@ -76,7 +76,7 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel = ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel =
function(coordinate, frameState, callback, opt_this) { function(coordinate, frameState, callback, thisArg) {
var layer = this.getLayer(); var layer = this.getLayer();
var source = layer.getSource(); var source = layer.getSource();
goog.asserts.assertInstanceof(source, ol.source.Image); goog.asserts.assertInstanceof(source, ol.source.Image);
@@ -89,7 +89,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel =
* @return {?} Callback result. * @return {?} Callback result.
*/ */
function(feature) { function(feature) {
return callback.call(opt_this, feature, this); return callback.call(thisArg, feature, layer);
}); });
}; };