由于某种原因,我在控制台中收到undefined
,但我不确定为什么。
var mp = document.getElementById('map'), ms = mp.style, center = L.latLng(47.62, -122.3321), h = innerHeight-130;
var tl = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'});
ms.height = h+'px';
var map = L.map('map', {center:center, zoom:10, layers:[tl]});
// remove when deployed
map.on('click', function(e){
console.log(e.latLng);
});
但是,如果我将 console.log(e.latLng)
更改为 console.log(e)
,我就会看到结果。据自己documentation ,它应该可以工作。为什么不呢?
最佳答案
e.latLng
应该是 e.latlng
。很难看出区分大小写的问题。
关于javascript - event.latLng 在 Leaflet 中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42894765/