您可以按以下方式创建新的图标类:
var LeafIcon = L.Icon.extend({
options: {
iconSize: [38, 95],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
}
});
然后像下面这样创建一个新的图标对象:
var greenIcon = new LeafIcon({
iconUrl: 'http://leafletjs.com/examples/custom-icons/leaf-green.png',
shadowUrl: 'http://leafletjs.com/examples/custom-icons/leaf-shadow.png'
})
现在,您可以像下面这样,在地图上使用上面的图标作为标记:
L.marker([51.5, -0.09], {icon: greenIcon}).addTo(map);
如需了解更多信息,请参阅此文档。
使用滑块控件需要创建两个图像:
(1) Marker Icon [ Use name: marker-icon.png ]
(2) Marker Icon Shadow [ Use name: marker-shadow.png ]
之后,您可以像下面这样指定默认图像路径:
L.Icon.Default.imagePath = "Url to the image folder"
e.x L.Icon.Default.imagePath = "http://leafletjs.com/examples/custom-icons"
这样图标的URL将是:
Icon URL : http://leafletjs.com/examples/custom-icons/marker-icon.png
Shadow URL: http://leafletjs.com/examples/custom-icons/marker-shadow.png