Search code examples
javascriptopenlayers

How can I get all the features displayed on a map in OpenLayers?


Is there a way I can get all the features from a OpenLayers Vector layer that are visible on the map?

For example what if the layer has 100 features, but at the zoom level I am at, at the moment I can only see 20 of these features.

Is there a way to programmatically get the visible features on the map?

Thanks


Solution

  • OL2 solution, my answer from 2013:

    Have a look at the onScreen method of OpenLayers:

    http://dev.openlayers.org/docs/files/OpenLayers/Marker-js.html#OpenLayers.Marker.onScreen

    OL3 solution:

    Get all features from the Openlayers 3 viewport