Check if marker is in view (map) - mapbox

2020-03-06 17:53发布

enter image description hereI want to check if marker is on mapview or out of the map. I am putting marker of the map and not able to check if it on currentView or not. I have tried below code. this.map.getBounds().contains(e.layer.getLatLng()); but it is returning me true. map is returning its old lat lng i.e bounds (I think so)

2条回答
别忘想泡老子
2楼-- · 2020-03-06 18:42

I use custom function:

function inBounds(point, bounds) {
  var lng = (point.lng - bounds._ne.lng) * (point.lng - bounds._sw.lng) < 0;
  var lat = (point.lat - bounds._ne.lat) * (point.lat - bounds._sw.lat) < 0;
  return lng && lat;
}
查看更多
孤傲高冷的网名
3楼-- · 2020-03-06 18:45

map.getBounds().contains(myMarker.getLatLng())

See also: area estimation in viewpoint of map using leaflet

查看更多
登录 后发表回答