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

@@ -148,6 +148,8 @@ ol.source.ImageVector.prototype.forEachFeatureAtPixel = function(
if (goog.isNull(this.replayGroup_)) {
return undefined;
} else {
/** @type {Object.<string, boolean>} */
var features = {};
return this.replayGroup_.forEachGeometryAtPixel(
extent, resolution, 0, coordinate, skippedFeatureUids,
/**
@@ -157,7 +159,12 @@ ol.source.ImageVector.prototype.forEachFeatureAtPixel = function(
*/
function(geometry, data) {
var feature = /** @type {ol.Feature} */ (data);
return callback(feature);
goog.asserts.assert(goog.isDef(feature));
var key = goog.getUid(feature).toString();
if (!(key in features)) {
features[key] = true;
return callback(feature);
}
});
}
};