openlayers/ol3 — pull request #3066 by tsauerwein (2014-12-19 17:33:37+00:00)
Title: Introduce hasFeatureAtPixel

This PR is based on #3065.

#3065 implements hit-detection for WebGL, but unfortunately the performance is not good enough to do hit-detection on `mousemove` (if you have many features). This is because we are calling `drawElements` for every feature, which is expensive.

For `mousemove` you are usually not interested in the actual features that `forEachFeatureAtPixel` provides, you just want to know if there is a feature or not, so that you can change the mouse pointer. So in this case you can draw all features at "once" (or to be precise: per texture group) for the hit-detection, and then check if there is a feature or not.

That's why we introduced a `hasFeatureAtPixel` method, which simply returns `true` if there is a feature at the given pixel. For WebGL this function is very fast, for 50000 features it takes less than 20ms (on my system).

Example usage:

$(map.getViewport()).on('mousemove', function(evt) {
var pixel = map.getEventPixel(evt.originalEvent);
var hit = map.hasFeatureAtPixel(pixel);
map.getTarget().style.cursor = hit ? 'pointer' : '';
});

Example: [icon-sprite-webgl.html](http://tsauerwein.github.io/ol3/webgl-point-hasFeatureAtPixel/examples/icon-sprite-webgl.html)