Angular 版本:8
package.json 中的版本:
"leaflet": "1.5.1",
"leaflet-draw": "1.0.4",
"leaflet-sidebar-v2": "3.0.3",
"esri-leaflet": "2.3.2",
"leaflet-control-geocoder": "1.10.0"
我有进口传单和其他类似的东西:
import * as L from 'leaflet';
import 'leaflet-draw';
import * as esri from 'esri-leaflet';
import 'leaflet-sidebar-v2';
import 'leaflet-control-geocoder';
现在我必须使用或 leaflet-control-geocoder 来实现此功能,但如果我这样写:
L.control.geocoder().addTo(map);
Angular 崩溃。(“typeof Control”类型上不存在属性“geocoder”) 我也尝试使用 esri-leaflet-geocoder,但它也崩溃了。
有什么解决办法吗?
最佳答案
我也遇到了同样的问题。我这样做修复了它
import * as L from 'leaflet';
import Geocoder from 'leaflet-control-geocoder';
...
this.map = L.map('map', {
center: [staticLatLng.lat, staticLatLng.lng],
zoom: zoomLevel
});
const GeocoderControl = new Geocoder();
GeocoderControl.addTo(this.map);
GeocoderControl.on('markgeocode', function (e) {
console.log(e);
});
...
关于javascript - 在 Angular 8 项目中导入 leaftlet-control-geocoder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59575551/