如何使用 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: '© <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()
更新
不知道如何在评论中post编码,所以我会在这里
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: '© <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()
是 Lng 而不是 lng,你打错了
L.latlngBounds 对比 L.latLngBounds
在我的示例中,我尝试检查标记是否在边界框内。如果是,弹出文本将设置为 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: '© <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()
更新 不知道如何在评论中post编码,所以我会在这里
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: '© <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()
是 Lng 而不是 lng,你打错了
L.latlngBounds 对比 L.latLngBounds