Search code examples
javascriptopenlayers

Checking if a marker is in the current visible area


When a marker is clicked and if it is not on the current visible area, I'm want to do something.

I'm trying with this but it's doing it wrong cause its considering markers I cannot see inside the area. Can't figure out what's wrong here. Thanks!

var marker_is_visible = this.map.getExtent().containsLonLat (new OpenLayers.LonLat(marker.x, marker.y)) 
if (!marker_is_visible) {
     // Reset view
}

Solution

  • Actually, there's a standard function onScreen() for this purpose; check it out here.