2016-10-17 5 views
0

私の例では、マーカーがバウンディングボックス内にあるかどうかを確認しようとしています。そうである場合、ポップアップテキストは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() 

答えて

2

ここでそれをやることがないLNG、あなたが持っているngのLですa typo

l.lat l ngBounds対L.lat L ngBounds

+0

私が得たそれらの新しいプログレッシブレンズは、私が彼らがそうであると思ったほど良くないと思います。 :) TOTALLYは "L"を逃した。ありがとう。気にする人のために、新しいコードは次のように読んでいます: – Ben

+0

は@alexを追加するべきですが、私がバックアップしようとしていたときに面白いことをしました。 – Ben

関連する問題