From 849e50517cb5fc281f4907e0115bb668979820b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Mon, 13 Jan 2014 11:42:25 +0100 Subject: [PATCH] Add ol.source.ImageVector#forEachFeatureAtPixel --- src/ol/source/imagevectorsource.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ol/source/imagevectorsource.js b/src/ol/source/imagevectorsource.js index e5ed007814..28886bef58 100644 --- a/src/ol/source/imagevectorsource.js +++ b/src/ol/source/imagevectorsource.js @@ -73,6 +73,12 @@ ol.source.ImageVector = function(options) { */ this.canvasSize_ = [0, 0]; + /** + * @private + * @type {ol.render.canvas.ReplayGroup} + */ + this.replayGroup_ = null; + goog.base(this, { attributions: options.attributions, canvasFunction: goog.bind(this.canvasFunctionInternal_, this), @@ -135,10 +141,34 @@ ol.source.ImageVector.prototype.canvasFunctionInternal_ = replayGroup.replay(this.canvasContext_, extent, pixelRatio, transform, goog.functions.TRUE); + this.replayGroup_ = replayGroup; + return this.canvasElement_; }; +/** + * @inheritDoc + */ +ol.source.ImageVector.prototype.forEachFeatureAtPixel = + function(extent, resolution, rotation, coordinate, callback) { + if (goog.isNull(this.replayGroup_)) { + return undefined; + } else { + return this.replayGroup_.forEachGeometryAtPixel( + extent, resolution, 0, coordinate, goog.functions.TRUE, + /** + * @param {ol.geom.Geometry} geometry Geometry. + * @param {Object} data Data. + */ + function(geometry, data) { + var feature = /** @type {ol.Feature} */ (data); + return callback(feature); + }); + } +}; + + /** * @param {ol.Coordinate} center Center. * @param {number} resolution Resolution.