1.

从官网中查看对应文档:https://leafletjs.com/

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

如何修改leaflet的marker图标 随笔 第1张

2.

如何修改leaflet的marker图标 随笔 第2张

3.

如何修改leaflet的marker图标 随笔 第3张

 

var greenIcon = L.icon({
    iconUrl: 'leaf-green.png',
    shadowUrl: 'leaf-shadow.png',

    iconSize:     [38, 95],    //  图标的大小
    shadowSize:   [50, 64], //  影子的大小
    iconAnchor:   [22, 94],  //  图标将对应标记点的位置
    shadowAnchor: [4, 62],  // 相同的影子
    popupAnchor:  [-3, -76] // 点的相对于iconAnchor弹出应该开放
});

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

 

 

如何修改leaflet的marker图标 随笔 第4张

var LeafIcon = L.Icon.extend({
    options: {
        shadowUrl: 'leaf-shadow.png',
        iconSize:     [38, 95],
        shadowSize:   [50, 64],
        iconAnchor:   [22, 94],
        shadowAnchor: [4, 62],
        popupAnchor:  [-3, -76]
    }
});

var greenIcon = new LeafIcon({iconUrl: 'leaf-green.png'}),
    redIcon = new LeafIcon({iconUrl: 'leaf-red.png'}),
    orangeIcon = new LeafIcon({iconUrl: 'leaf-orange.png'});

L.marker([51.5, -0.09], {icon: greenIcon}).addTo(map).bindPopup("I am a green leaf.");
L.marker([51.495, -0.083], {icon: redIcon}).addTo(map).bindPopup("I am a red leaf.");
L.marker([51.49, -0.1], {icon: orangeIcon}).addTo(map).bindPopup("I am an orange leaf.");

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄