How to use Esri Leaflet javascript Plugin with TypeScript

693 views Asked by At

My Aurelia project in TypeScript uses Leaflet for mapping. While Leaflet has typings the esri-leaflet plugin does not and is just javascript. How do I use / import the javascript plugin in my TypeScript classes. TIA

1

There are 1 answers

0
Jonas Tomanga On

You should extend the type definition for leaflet. Create a new typescript file and add the following.

declare module L {
   export let esri:any;
   export class Esri {

   }
}

import this file after leaflet

if you need to extend other plugins:

declare module L {
   //plugins that extend Control comes here
   export namespace Control {
      export let Navbar: any;
   }
   // plugins that have control factories come here
  export namespace control {
     export let navbar: any;
  }
  //plugins that extend Layer comes here
   export namespace Layer {
      export let NewLayer: any;
   }
   // plugins that have layer factories come here
  export namespace layer {
     export let newLayer: any;
  }
  //plugins that extend Handler comes here
   export namespace Handler {
      export let NewHandler: any;
   }
   // plugins that have handler factories come here
  export namespace handler {
     export let newHandler: any;
  }
}

You can be explicit with the types if you want to.