How do I add Typescript definitions for Leaflet plugins

后端 未结 3 1756
Happy的楠姐
Happy的楠姐 2021-02-06 15:41

I would like to use easy-buttons plugin with Typescript https://github.com/CliffCloud/Leaflet.EasyButton/blob/master/src/easy-button.js and but it doesn\'t come with Typescript

3条回答
  •  执笔经年
    2021-02-06 16:18

    class EasyButton extends L.Control { constructor(options?: EasyButtonOptions) }

    Your new L.EasyButton takes a 'EasyButtonOptions' object for the constructor. This does not match the 'L.easyButton' examples

    A L.easyButton has the following options: function easyButton(icon: string, onClick: (btn: any, map: any)=>void, title?: string, id?: string) : Control.EasyButton;

    An EasyButtonOptions doesn't have a 'icon', 'onClick', 'title' or 'id' instead it takes:

    interface EasyButtonOptions { position?: ControlPosition id?: string type?: 'replace'|'animate' states?: EasyButtonState[] leafletClasses?: boolean tagName?: string }

    So therefore, what is the equivalent of new L.EasyButton() that matches L.easyButton('fa fa-icon', () => '..', 'title) ?

提交回复
热议问题