[英]Integrate leafletjs AnimatedMarker into typescript
I installed leaflet typescript, and I found that there are problems when using leaflet non-typescript plugins.我安装了leaflet typescript,发现使用leaflet non-typescript插件时出现问题。
For example, when using a plugin with typescript installed, I can successfully import this plugin:例如,当使用安装了 typescript 的插件时,我可以成功导入这个插件:
install:安装:
npm install --save leaflet-routing-machine
npm install --save @types/leaflet-routing-machine
angular component:角分量:
import 'leaflet-routing-machine';
import { Routing } from 'leaflet';
In this way, I can successfully use the plugin leaflet-routing-machine attached to the leaflet.这样我就可以成功使用传单附带的插件leaflet-routing-machine了。
But when I use the AnimatedMarker plugin, it doesn't have typescript, so I don't know how to use it.但是当我使用AnimatedMarker插件时,它没有打字稿,所以我不知道如何使用它。
I have tried the following methods but failed:我尝试了以下方法但失败了:
import 'leaflet.animatedmarker/src/AnimatedMarker';
import { AnimatedMarker, animatedMarker } from 'leaflet';
// Compilation will fail
or要么
let AnimatedMarker = require('leaflet.animatedmarker/src/AnimatedMarker');
console.log(AnimatedMarker);
or要么
import * as AnimatedMarker from 'leaflet.animatedmarker/src/AnimatedMarker';
console.log(AnimatedMarker);
I wish to avoid using like: import * as L from 'leaflet'
L.AnimatedMarker
;我希望避免使用像:
import * as L from 'leaflet'
L.AnimatedMarker
; Although this method can successfully use non-typescript plugins.虽然这种方法可以成功使用非打字稿插件。
That plugin just seems to be a script to extend some L.* objects, like L.Marker.该插件似乎只是一个扩展某些 L.* 对象的脚本,例如 L.Marker。
Putting import 'leaflet.animatedmarker/src/AnimatedMarker';
把
import 'leaflet.animatedmarker/src/AnimatedMarker';
in the main.ts
file should do the trick.在
main.ts
文件中应该可以解决问题。
Like in thisstackblitz example就像在这个stackblitz 示例中一样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.