問題描述
我想檢查標記是在地圖視圖上還是在地圖外.我正在放置地圖的標記,但無法檢查它是否在 currentView 上.我試過下面的代碼.this.map.getBounds().contains(e.layer.getLatLng());但它讓我回歸真實.地圖正在返回其舊的 lat lng,即邊界(我認為是這樣)
I 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)
推薦答案
map.getBounds().contains(myMarker.getLatLng())
map.getBounds()
:返回當前地圖視圖的 LatLngBounds.
map.getBounds()
: Returns the LatLngBounds of the current map view.
latLngBounds.contains()
:如果矩形包含給定點,則返回 true
.
myMarker.getLatLng()
:返回標記的當前地理位置.
myMarker.getLatLng()
: Returns the current geographical position of the marker.
另請參閱:地圖視點中的區域估計使用傳單
這篇關于檢查標記是否在視圖中(地圖) - mapbox的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!