在Angular项目中引入Leaflet TimeDimension库时,需要注意以下事项:
npm install leaflet@1.6.0 leaflet-timedimension@1.1.0
"styles": [ "node_modules/leaflet/dist/leaflet.css", "node_modules/leaflet-timedimension/dist/leaflet.timedimension.control.css" ], "scripts": [ "node_modules/leaflet/dist/leaflet.js", "node_modules/leaflet-timedimension/dist/leaflet.timedimension.control.js" ]
import * as L from 'leaflet'; import 'leaflet-timedimension';
...
ngOnInit() { const map = L.map('map').setView([51.505, -0.09], 13); const layer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }); layer.addTo(map);
const timeDimensionControl = L.control.timeDimension(); timeDimensionControl.addTo(map); }
通过以上步骤,可以解决Angular无法识别Leaflet TimeDimension的问题。