Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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()){
             output.push(poi.attributes['name']);
          }
      }
     // 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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.geometery.getBounds()) {
            output.push(poi.attributes['name']);
        } 
    }
});
share|improve this answer
    
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 May 14 '13 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 May 14 '13 at 20:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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