2015-04-01 74 views
1

我想在點擊標記時放大標記。我正在使用Mapbox和傳單。如何放大Mapbox Leaflet中的標記點擊事件?

我想:

marker.on('click', function(e){ 
    map.setView([e.lat, e.lng], 12); 
}); 

但它給了我某種錯誤的:

TypeError: t is null

我甚至嘗試:

marker.on('click', function(e){ 
    map.fitBounds(marker.getBounds()); 
}); 
+0

能否請您發表您的錯誤? – AlexVogel 2015-04-01 07:38:15

+0

我編輯了這個問題。 :) – Rohan 2015-04-01 07:40:32

回答

8

要得到事件的緯度和經度,您必須使用e.latlng:latlng reference。使用此:

marker.on('click', function(e){ 
    map.setView(e.latlng, 13); 
}); 
2

嘗試

marker.on('click', function(e){ 
    map.setView([e.latlng.lat, e.latlng.lng], 12); 
}); 
相關問題