I have an OpenLayers map a few thousand Points of Interest. These POIs are Vector Features rendered in a Vector Layer.

We are loading the POIs once in order to minimize load on the server.

Next to the map will be a box which will display the names of POIs currently in view.

I'm not clear on the best way to update this list of names.

I believe that I can store an array of the POIs (Features). Then, when the map is panned/searched/zoomed, loop through them, calling the "onScreen" function.

map.events.register("moveend", map, function(evt) {
      var output = [];
      for (var i=0;i<myFeatures.length;i++) {
          var poi = myFeatures[i];
          if (poi.onScreen()){
     // then, use output to display the list in html...
     myDOMbox.innerHTML = output.join();


Is there a more efficient way to do this?

Thanks in advance.

1 Answer 1


Not quite sure what your "onScreen" function is, but an example that should work is this:

map.events.register("moveend", map, function(evt) {
    var extent = map.getExtent();
    var output = [];
    for (var i = 0, l = myFeatures.features.length; i < l; i++) {
        var feature = myFeatures.features[i];
        if (extent.intersectsBounds(feature.geometry.getBounds())) {
  • Thanks. The onScreen function is part of the api here: dev.openlayers.org/docs/files/OpenLayers/Feature/… I'm guessing that it does the same thing as your intersectBounds function. Much appreciated though.
    – shackleton
    Commented May 14, 2013 at 17:10
  • Aha, seems OpenLayers has got guite a few new features lately. I guess my solution is akin to setting boundsOnly to true on onScreen. But either way, you have to somehow loop through all features to check them. Glad to help!
    – atlefren
    Commented May 14, 2013 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.