2

I need to get some data when I click on the markers.

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);
        }

Written on the console:

Uncaught TypeError: L.marker.extend is not a function

1 Answer 1

3

You are using the factory L.marker instead of the L.Marker class

L.Marker.extend ... capital M

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.