Allow forEachFeatureAtPixel callback to break out of loop
This commit is contained in:
@@ -85,14 +85,16 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
|
||||
function(pixel, callback) {
|
||||
if (!goog.isNull(this.replayGroup_)) {
|
||||
function(pixel, callback, opt_obj) {
|
||||
if (goog.isNull(this.replayGroup_)) {
|
||||
return undefined;
|
||||
} else {
|
||||
goog.asserts.assert(!ol.extent.isEmpty(this.renderedExtent_));
|
||||
goog.asserts.assert(!isNaN(this.renderedResolution_));
|
||||
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||
var renderGeometryFunction = this.getRenderGeometryFunction_();
|
||||
goog.asserts.assert(goog.isFunction(renderGeometryFunction));
|
||||
this.replayGroup_.forEachGeometryAtCoordinate(this.renderedExtent_,
|
||||
return this.replayGroup_.forEachGeometryAtCoordinate(this.renderedExtent_,
|
||||
this.renderedResolution_, coordinate, renderGeometryFunction,
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
@@ -101,7 +103,7 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
|
||||
function(geometry, data) {
|
||||
var feature = /** @type {ol.Feature} */ (data);
|
||||
goog.asserts.assert(goog.isDef(feature));
|
||||
callback(feature);
|
||||
return callback.call(opt_obj, feature);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,7 +44,10 @@ goog.inherits(ol.renderer.Layer, goog.Disposable);
|
||||
|
||||
/**
|
||||
* @param {ol.Pixel} pixel Pixel.
|
||||
* @param {function(ol.Feature)} callback Feature callback.
|
||||
* @param {function(this: S, ol.Feature): T} callback Feature callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template S,T
|
||||
*/
|
||||
ol.renderer.Layer.prototype.forEachFeatureAtPixel = goog.nullFunction;
|
||||
|
||||
|
||||
@@ -80,13 +80,30 @@ ol.renderer.Map.prototype.disposeInternal = function() {
|
||||
|
||||
/**
|
||||
* @param {ol.Pixel} pixel Pixel.
|
||||
* @param {function(ol.Feature)} callback Feature callback.
|
||||
* @param {function(this: S, ol.Feature): T} callback Feature callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template S,T
|
||||
*/
|
||||
ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
||||
function(pixel, callback) {
|
||||
goog.object.forEach(this.layerRenderers_, function(layerRenderer) {
|
||||
layerRenderer.forEachFeatureAtPixel(pixel, callback);
|
||||
});
|
||||
function(pixel, callback, opt_obj) {
|
||||
var layers = this.map_.getLayers();
|
||||
if (goog.isDef(layers)) {
|
||||
var layersArray = layers.getArray();
|
||||
var i;
|
||||
for (i = layersArray.length - 1; i >= 0; --i) {
|
||||
var layer = layersArray[i];
|
||||
if (layer.getVisible()) {
|
||||
var layerRenderer = this.getLayerRenderer(layer);
|
||||
var result =
|
||||
layerRenderer.forEachFeatureAtPixel(pixel, callback, opt_obj);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user