Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my map there are numberof layers. I want my custom legends to show when the related layer feature is visible in the current map view. I am able to turn on/off the display of the legend according to display scale but I need to hide the legend if the feature is not in the map view even if it is in the range of display scale.

I go through the layer collection of the map. I tried to debug when the vector layer feature is visible in the map view but I get layer.features.length as always zero.

I need it total in terms of openlayers script. I do not want to utilize GeoExt.

Can anyone help on this?


share|improve this question

Here's a way to determine whether a feature is visible in the current extent:

features = your-layer.features; 
for (var i = 0; i < features.length; i++) { 
    if (features[i].geometry.getBounds().intersectsBounds(map.getExtent())) { 
share|improve this answer

Your Answer


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.