aratcliffe / Leaflet.contextmenu

A context menu for Leaflet.
MIT License
367 stars 107 forks source link

Does it work with angular? #121

Open patricia-martinez-imatia opened 5 years ago

patricia-martinez-imatia commented 5 years ago

Does This library work with angular? I saw examples with angularjs but none with angular.

If so, there is an example to follow.

Thanks you

Azbesciak commented 5 years ago

Yes, it works as most (if not all) js libraries. But I didn't found any dedicated support for now.

joshting commented 1 year ago

Found solution on my own. Where I import 'leaflet-contextmenu', I manually added the type definition called leaflet-contextmenu.d.ts with the following content:

declare namespace L {
    interface ContextMenuItem {
        text: string;
        index?: number
        callback?: (ev: ContextMenuItemClickEvent) => void;
    }

    interface MapOptions {
        contextmenu: boolean;
        contextmenuItems: ContextMenuItem[]
    }

    interface MarkerOptions {
        contextmenu: boolean;
        contextmenuItems: ContextMenuItem[]
    }

    interface ContextMenuItemClickEvent {
        latlng: LatLng;
        layerPoint: Point;
        containerPoint: Point;
        relatedTarget: Marker | Path | undefined;
    }
}

Now, I am able to declare those options, compile and the plugin works. Tested in react with TS, it should work with Angular too.