簡體   English   中英

如何使用Leaflet檢查標記是否在邊界框中

[英]How to check if a marker is in a bounding box with Leaflet

在我的示例中,我試圖檢查標記是否在邊界框中。 如果是,則將彈出文本設置為true。

我一直以“ L.latlngBounds”結尾不是函數。 有人可以指出我正確的方向嗎?

checkBounds = (marker) ->
  if L.latlngBounds(inBounds).contains(currentMarker.getLatLng())
    return "True"
  else
    return "False"

map = L.map('mapid').setView([
  51.505
  -0.09
], 13)
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors').addTo map

neCorner = L.marker([47.6349, -122.3206])
swCorner = L.marker([47.6341, -122.3211])
currentMarker = L.marker([47.6345, -122.3208])
inBounds = new L.featureGroup([swCorner, neCorner])

map.fitBounds(inBounds.getBounds(), { padding: [50, 50] } )
currentMarker.addTo(map).bindPopup(checkBounds(currentMarker)).openPopup()

更新無法弄清楚如何在注釋中發布代碼,因此我將在此處進行

checkBounds = (marker) ->
    if L.latLngBounds([swCorner, neCorner]).contains(marker)
    return "True"
  else
    return "False"

map = L.map('mapid').setView([
  51.505
  -0.09
], 13)
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors').addTo map

neCorner = L.latLng([47.6349, -122.3206])
swCorner = L.latLng([47.6341, -122.3211])

currentMarker = L.latLng([47.6355, -122.3208])

map.fitBounds(([swCorner, neCorner]), { padding: [50, 50] } )
L.marker(currentMarker).addTo(map).bindPopup(checkBounds(currentMarker)).openPopup()

L NG不LNG,你有一個錯字

L.lat L ngBounds與L.lat L ngBounds

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM