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

@@ -187,6 +187,26 @@ ol.renderer.canvas.VectorLayer.prototype.getTransform = function() {
};
/**
* @param {ol.Pixel} pixel Pixel coordinate relative to the map viewport.
* @return {Array.<ol.Feature>} Features at the pixel location.
*/
ol.renderer.canvas.VectorLayer.prototype.getFeatureInfoForPixel =
function(pixel) {
// TODO adjust pixel tolerance for point features
var minPixel = new ol.Pixel(pixel.x - 1, pixel.y - 1);
var maxPixel = new ol.Pixel(pixel.x + 1, pixel.y + 1);
var map = this.getMap();
var minCoordinate = map.getCoordinateFromPixel(minPixel);
var maxCoordinate = map.getCoordinateFromPixel(maxPixel);
var bbox = ol.extent.boundingExtent([minCoordinate, maxCoordinate]);
var filter = new ol.filter.Extent(bbox);
// TODO do a real intersect against the filtered result for exact matches
return this.getLayer().getFeatures(filter);
};
/**
* @param {goog.events.Event} event Layer change event.
* @private