如何在leafletjs地图上扩展标记?

问题描述 投票:0回答:1

单击标记时,我需要获取一些数据。

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不是函数

leaflet marker extend
1个回答
0
投票

您正在使用出厂的L.marker而不是L.Marker类

L.Marker.extend ...大写M

© www.soinside.com 2019 - 2024. All rights reserved.