How to improve performance of getFeaturesAtPixel?

风格不统一 提交于 2019-12-24 03:49:14

问题


I use the "map.getFeaturesAtPixel" method to exactly get the first feature under on a mouse-click interaction.

This works as expected even though the method does not return a single feature but all the features whose graphical representation hits the clicked point.

This behaviour will be "acceptable" but it turns out that its performance decreases as soon as we zoom out and lots of features are condensed and displayed like a giant mass of features...

I know this is not the ideal way to display features on a map but it can happen in some scenarios.

Anyway, I tried what it seems to be a faster way to retrieve what I want (first feature under my click) using a "small" Extent (based on the click coordinate) and using getFeaturesIntersectingExtent. This approach is really fast but it does not work in all scenarios since it's only aware of features geometries and not their graphical representation (my needs).

Question: is there a another way to get this first-feature-under-click in an optimal way?


回答1:


you can use this to get feature on mouse click

var feature = map.forEachFeatureAtPixel(evt.pixel,
                    function (feature) {
                        return feature;
                    });


来源:https://stackoverflow.com/questions/58027971/how-to-improve-performance-of-getfeaturesatpixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!