【问题标题】:How to use Esri Leaflet javascript Plugin with TypeScript如何将 Esri Leaflet javascript 插件与 TypeScript 一起使用
【发布时间】:2017-10-22 18:25:21
【问题描述】:

我在 TypeScript 中的 Aurelia 项目使用 Leaflet 进行映射。虽然 Leaflet 有类型,但 esri-leaflet 插件没有,只是 javascript。如何在我的 TypeScript 类中使用/导入 javascript 插件。 TIA

【问题讨论】:

  • 我认为您最好尝试确定如何将任意 JavaScript 库导入 TypeScript 项目,然后再导入 Aurelia 项目。问题(和解决方案)不太可能特定于 esri-leaflet。

标签: typescript leaflet aurelia esri-leaflet esri-oss


【解决方案1】:

您应该扩展传单的类型定义。 创建一个新的打字稿文件并添加以下内容。

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

   }
}

在传单之后导入此文件

如果您需要扩展其他插件:

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;
  }
}

如果你愿意,你可以明确地使用类型。

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 1970-01-01
    • 2019-06-27
    • 2020-09-24
    • 1970-01-01
    • 2019-01-07
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多