Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 9 is this supports? if yes then pls share reference code #133

Open
swapnasheela12 opened this issue Aug 25, 2020 · 3 comments
Open

Comments

@swapnasheela12
Copy link

Hi

i was install npm in angular 9 project but there is having one issue
contextmenu: true,

giving error is

error TS2345: Argument of type '{ center: [number, number]; zoomControl: false; zoom: number; contextmenu: boolean; contextmenuWidth: number; contextmenuHeight: number; contextmenuItems: { text: string; callback: (e: any) => void; }[]; }' is not assignable to parameter of type 'MapOptions'.
Object literal may only specify known properties, and 'contextmenu' does not exist in type 'MapOptions'.

157       contextmenu: true,
          ~~~~~~~~~~~~~~~~~

plz give me any working reference with angular 9

@PechioA
Copy link

PechioA commented Jun 7, 2021

I was facing the same issue, what I did was separating the markerOptions object declaration, and passing the object to the marker on its creation time. Like this: ( I am using angular 8 )

let options : any = {
    riseOnHover:true,
    icon:icon,
    contextmenu: true,
    contextmenuWidth: 140,
    contextmenuItems: [{
         text: 'Marker item',
     }]
  };
  let marker : L.Marker = L.marker([address.lat,address.lng],options);

@joshting
Copy link

I am using Angular 14/15. How would this work with typescript since there is no type definitions available?

@joshting
Copy link

joshting commented Apr 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants