2016-11-14 70 views

回答

0

最好的辦法是你定義圖標和設置的事件時層變化:

var icon1 = L.icon({ 
    iconUrl: 'marker.png', 
    iconSize:  [38, 95], 
}); 
var icon2 = L.icon({ 
    iconUrl: 'bus.png', 
    iconSize:  [38, 95], 
}); 

var marker = L.marker([51.5, -0.09], {icon: icon1}).addTo(map); 

map.on('baselayerchange', function(e) { 
    if(e.layer.name == "whatyouwant"){ 
     marker.setIcon(icon1); 
    }else{ 
     marker.setIcon(icon2); 
    } 
});