Skip to main content
 首页 » 编程设计

javascript中如何在 Angular 6 CLI 应用程序中包含 Leaflet.TextPath 或 Leaflet.PolylineDecorator

2025年05月04日296www_RR

我一直在尝试包含https://github.com/makinacorpus/Leaflet.TextPath在 Angular 6 CLI 应用程序中,但没有成功。有人可以指导我吗?提前致谢。

编辑:或者如果是这个? https://github.com/bbecquet/Leaflet.PolylineDecorator ,它也有类型。

请您参考如下方法:

为了能够包含 Leaflet.TextPath,您需要在 angular-cli 项目中安装 Leaflet 和 Leaflet.TextPath,然后按如下方式导入它们:

在 angular.json 添加:

"styles": [ 
     "node_modules/leaflet/dist/leaflet.css", 
     "src/styles.css" 
], 
"scripts": [ 
   "node_modules/leaflet/dist/leaflet.js" 
] 

在component.ts中添加:

 ... 
 import 'leaflet'; 
 import 'leaflet-textpath'; 
 
 declare let L; // to be able to use L namespace 
 ... 

然后在 ngOnInit 中初始化代码,并将代码按照库中的指示放置:

ngOnInit() { 
   your code initialization here 
 
    ... 
} 

Demo