要使其工作,您需要执行以下步骤:
npm i leaflet --save
npm install --save leaflet-arc
转到 angular.json 并添加两个库,如下所示:
"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);
}
}
模板:
<div id="map"></div>
风格:
#map {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}
演示