当我点击标记时,我需要获取一些数据。
let greenIcon = L.icon({
iconUrl: 'assets/img/sample1.png',
shadowUrl: 'assets/img/sample1-shadow.png',
iconSize: [38, 38],
shadowSize: [38, 38],
iconAnchor: [22, 37],
shadowAnchor: [20, 36],
popupAnchor: [-3, -26]
});
const customMarker = L.marker.extend({
options: {
someCustomProperty: 'Custom data!',
anotherCustomProperty: 'More data!'
}
});
let myMarker = new customMarker(markerLocation, {
icon: greenIcon,
someCustomProperty: 'Adding custom data to this marker!',
anotherCustomProperty: 'More custom data to this marker!'
}).addTo(map).on('click', onClickMarker);
function onClickMarker(e) {
alert(this.options.someCustomProperty);
}
在控制台上写:
未捕获的TypeError:L.marker.extend不是函数
答案 0 :(得分:1)
您使用的是工厂L.marker而不是L.Marker类
L.Marker.extend ...大写M