Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

1 Answer 1

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.