Javascript 使用有角度的小叶弧?
我如何在角度上使用?到目前为止,我所尝试的:Javascript 使用有角度的小叶弧?,javascript,angular,leaflet,ngx-leaflet,Javascript,Angular,Leaflet,Ngx Leaflet,我如何在角度上使用?到目前为止,我所尝试的: npm安装--保存传单弧 添加“脚本”:[“节点模块/传单弧/src/传单弧.js”]到 angular.json 添加import'../../node_modules/传单弧/src/传单弧.js' 到my component.component.ts 但是,当我在my component.component.ts中执行以下操作时,仍然会出现一个错误,属性“Arc”在类型“typeof Polyline”上不存在。: L.Polyline.Arc
npm安装--保存传单弧
“脚本”:[“节点模块/传单弧/src/传单弧.js”]
到
angular.json
import'../../node_modules/传单弧/src/传单弧.js'代码>
到my component.component.ts
my component.component.ts
中执行以下操作时,仍然会出现一个错误,属性“Arc”在类型“typeof Polyline”上不存在。
:
L.Polyline.Arc(…)
当我执行ng serve
时,这实际上是可行的,但编译时仍然会出现错误
有什么想法吗?要让它发挥作用,您需要遵循以下步骤:
npm i传单--保存
npm安装--保存传单弧
"styles": [
"node_modules/leaflet/dist/leaflet.css",
"src/styles.css"
],
"scripts": [
"node_modules/leaflet/dist/leaflet.js",
"node_modules/leaflet-arc/src/leaflet-arc.js"
]
在app.component.ts中,您需要按如下方式导入两个库:
import { Component, OnInit } from '@angular/core';
import 'leaflet';
import 'leaflet-arc'; // import leaflet-arc here
declare let L;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
ngOnInit() {
const map = L.map('map').setView([60, 100], 3);
// create an arc here
L.Polyline.Arc([59.56667, 150.80000], [67.50000, 64.03333], {
color: 'red',
vertices: 200
}).addTo(map);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
}
}
太棒了,真管用!看来问题已经解决了,
declare let L
。好主意!谢谢是的,确实如此,请确保在模板中同时导入传单和传单弧,然后使用declare let L
。注意到我在从“arc”导入弧一行中得到了一个错误,给出了一个意外的标识符代码>。它运行正常,但想修复这个错误,我想不是用我提供的代码,因为我没有使用那一行。在我测试它的本地副本中,我没有得到任何错误
<div id="map"></div>
#map {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}