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