当与markercluster配对时,Leafet e.target.getLatLng()无法正常工作

时间:2016-07-25 17:16:54

标签: leaflet

我正在使用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)};

1 个答案:

答案 0 :(得分:0)

我在错误的地方括号。

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));