1

角度版本: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';

现在我必须使用或传单控制地理编码器来实现这个功能,但如果我写这个:

L.control.geocoder().addTo(map);

角度崩溃。(“typeof Control”类型上不存在属性“geocoder”)我也尝试使用esri-leaflet-geocoder,但它也崩溃了。

任何解决方案?

4

3 回答 3

2

我有同样的问题。我这样做了

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);
});
...
于 2021-06-08T16:19:53.773 回答
0

我有同样的问题。我在 L.Routing.control 中添加了地理编码器,它可以工作了!(实际上,VS Code 仍然说Property 'Geocoder' does not exist on type 'typeof Control')但它有效!:

L.Routing.control({ waypoints: [L.latLng(57.74, 11.94), L.latLng(57.6792, 11.949)], showAlternatives: true, geocoder: L.Control.Geocoder.nominatim() }).addTo(this.map);

我正在使用 Angular 8,传单路由机插件。

于 2020-02-19T14:52:06.460 回答
0

请尝试使用大写“C”L.Control.geocoder().addTo(map)

或(但应该具有相同的效果)

var geocoder = new L.Control.geocoder();
map.addControl(geocoder);
于 2020-01-03T09:26:33.653 回答