geoman-io/leaflet-geoman

Document Typescript casting of event payload

開放

#1,014 建立於 2021年10月19日

 (0 則留言) (0 個反應) (0 位負責人)JavaScript (404 個分叉)batch import
good first issuehelp wantedimprovementtypescript

倉庫指標

星標
 (1,933 顆星)
PR 合併指標
 (平均合併 9天 6小時) (30 天內合併 5 個 PR)

描述

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:

貢獻者指南