Coffeescript 如何检查标记是否位于带有传单的边界框中

Coffeescript 如何检查标记是否位于带有传单的边界框中,coffeescript,leaflet,Coffeescript,Leaflet,在我的示例中,我试图检查标记是否在边界框内。如果是,弹出文本将设置为true 我总是以“L.latlngBounds”结尾不是一个函数。 有人能给我指出正确的方向吗 checkBounds = (marker) -> if L.latlngBounds(inBounds).contains(currentMarker.getLatLng()) return "True" else return "False" map = L.map('mapid').setVie

在我的示例中,我试图检查标记是否在边界框内。如果是,弹出文本将设置为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=(标记)->
如果L.latlngBounds(inBounds).contains(currentMarker.getLatLng())
返回“True”
其他的
返回“False”
map=L.map('mapid')。setView([
51.505
-0.09
], 13)
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',属性:'©;contributors')。添加到地图
neCorner=L.标记([47.6349,-122.3206])
swCorner=L.标记([47.6341,-122.3211])
currentMarker=L.marker([47.6345,-122.3208])
内边界=新的L.特征组([swCorner,neCorner])
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()
checkBounds=(标记)->
如果L.latLngBounds([swCorner,neCorner])包含(标记)
返回“True”
其他的
返回“False”
map=L.map('mapid')。setView([
51.505
-0.09
], 13)
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',属性:'©;contributors')。添加到地图
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).bindpoppup(checkBounds(currentMarker)).openPopup()

这是Lng而不是lng,您有一个打字错误


L.latLngBounds与L.latLngBounds

我猜我买的那些新的渐进式镜片没有我想象的那么好。:)完全错过了那个“L”。谢谢对于那些关心的人来说,新的代码是这样写的:应该添加@alex,但是在我试图备份时做了一些有趣的事情。