geoman-io/leaflet-geoman

Document Typescript casting of event payload

Open

#1.014 geöffnet am 19. Okt. 2021

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (1.933 Stars) (404 Forks)batch import
good first issuehelp wantedimprovementtypescript

Beschreibung

In the event payload the return type of layer is `L.Layer? so it needs to be casted to the Layer-Type.

layer.on('pm:edit', (e) => {
  if(e.shape === 'Polygon'){
     (e.layer as Polygon).getLatLngs();
  }
});

I think following should work too: (But not tested)

layer.on('pm:edit', (e) => {
  if(e.layer instanceof L.Polygon){
     (e.layer as Polygon).getLatLngs();
  }
});

This should documented in the Readme

Explainations:

Contributor Guide