开发者

Checking if a marker is in the current visible area

开发者 https://www.devze.com 2023-01-30 10:47 出处:网络
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

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.getEx开发者_StackOverflow中文版tent().containsLonLat (new OpenLayers.LonLat(marker.x, marker.y)) 
if (!marker_is_visible) {
     // Reset view
}


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


Think, your marker.x and marker.y are not latitude and longitude but coordinates of map position of marker. Try to check x < 0 || y < 0 || x > mapWidth || y > mapHeight

0

精彩评论

暂无评论...
验证码 换一张
取 消