我使用的是Leafet (更准确地说是django-leaflet),我已经能够在任何标记上形成一个点击(.on),这样它就可以平移到标记并放大到10。这是通过使用map.setView(e.target.getLatLng(),10)来完成的;
但是,我现在已经实现了leaflet markercluster,getLatLng()现在似乎是一个未定义的函数?
没有markercluster的代码,它工作得很好:
function onEachFeature(feature, layer) {
layer.bindPopup(feature.properties.name).on('click', clickZoomy);
function clickZoomy(e) {
if (map.getZoom() < 10){
map.setView(e.target.getLatLng(),10) //ZOOM
} else{
map.setView(e.target.getLatLng())
}};下面是我在markercluster中使用的代码:
var multimarker = new L.MarkerClusterGroup();
multimarker.addLayer(L.marker([52.526013, 13.398351],{icon: markHospital})).on('click', clickZoom);
multimarker.addLayer(L.marker([52.513666, 13.389633],{icon: markHospital})).on('click', clickZoom);
multimarker.addLayer(L.marker([52.512842, 13.389277],{icon: markHospital})).on('click', clickZoom);
map.addLayer(multimarker); function clickZoom(e) {
map.setView(e.target.getLatLng(),10)};发布于 2016-07-26 02:12:03
我把括号放错地方了。
multimarker.addLayer(L.marker([52.526013, 13.398351],{icon: markHospital})).on('click', clickZoom);必须更改为
multimarker.addLayer(L.marker([52.526013, 13.398351],{icon: markHospital}).on('click', clickZoom));https://stackoverflow.com/questions/38573836
复制相似问题