Do not hit-detect the same feature multiple times

In other words forEachFeatureAtPixel should not call the user-provided callback more than once for a given feature.
This commit is contained in:
Éric Lemoine
2014-08-18 10:24:12 +02:00
parent 1fc620b7bb
commit c81dfdc69b
3 changed files with 53 additions and 2 deletions

View File

@@ -121,6 +121,8 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
var resolution = frameState.viewState.resolution;
var rotation = frameState.viewState.rotation;
var layer = this.getLayer();
/** @type {Object.<string, boolean>} */
var features = {};
return this.replayGroup_.forEachGeometryAtPixel(extent, resolution,
rotation, coordinate, frameState.skippedFeatureUids,
/**
@@ -131,7 +133,11 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
function(geometry, data) {
var feature = /** @type {ol.Feature} */ (data);
goog.asserts.assert(goog.isDef(feature));
return callback.call(thisArg, feature, layer);
var key = goog.getUid(feature).toString();
if (!(key in features)) {
features[key] = true;
return callback.call(thisArg, feature, layer);
}
});
}
};