0
在我的示例中,我试图检查标记是否在边界框内。如果是,则弹出文本被设置为true。如何用Leaflet检查标记是否在边界框中
我一直以“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()
更新 无法弄清楚如何评论发表的代码,所以我会做在这里
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()
我猜那些新的渐进镜片并不如我想象的那么好。 :)完全错过了“L”。谢谢。对于那些关心的人来说,新代码的读取方式如下: – Ben
应该添加了@alex,但在尝试备份时做了一些有趣的事情。 – Ben