Giving the map a getFeatureInfoForPixel method

This method is an entry point for getting feature information.
Renderers can use a hit canvas or defer to a layer (source) to
get matching features for a pixel.

For now this is only implemented for vector layers, and it uses
a bbox query because we cannot refine the result because of
missing geometry intersection functions yet.
This commit is contained in:
ahocevar
2013-04-29 16:26:29 +02:00
parent a0340faa63
commit cc1b70c74b
5 changed files with 83 additions and 1 deletions

View File

@@ -427,6 +427,34 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
};
/**
* Get feature information for a pixel on the map.
*
* @param {ol.Pixel} pixel Pixel coordinate relative to the map viewport.
* @param {Array.<ol.layer.Layer>|undefined} opt_layers Layers to restrict the
* query to. All layers will be queried if not provided.
* @return {Array.<ol.Feature|string>} Feature information. Layers that are
* able to return attribute data will return ol.Feature instances, other
* layers will return a string which can either be plain text or markup.
*/
ol.Map.prototype.getFeatureInfoForPixel = function(pixel, opt_layers) {
var renderer = this.getRenderer();
var layers = goog.isDefAndNotNull(opt_layers) ?
opt_layers : this.getLayers().getArray();
var layer, layerRenderer;
var featureInfo = [];
for (var i = 0, ii = layers.length; i < ii; ++i) {
layer = layers[i];
layerRenderer = renderer.getLayerRenderer(layer);
if (goog.isFunction(layerRenderer.getFeatureInfoForPixel)) {
featureInfo.push.apply(featureInfo,
layerRenderer.getFeatureInfoForPixel(pixel));
}
}
return featureInfo;
};
/**
* @return {ol.Collection} Interactions.
*/