首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Angular 8项目中导入leaftlet-control-geocoder?

在Angular 8项目中导入leaftlet-control-geocoder?
EN

Stack Overflow用户
提问于 2020-01-03 16:52:20
回答 3查看 1.1K关注 0票数 1

角度验证:8

Package.json中的版本:

代码语言:javascript
复制
"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"

我有进口传单和其他类似的东西:

代码语言:javascript
复制
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来实现这个功能,但是如果我这样写:

代码语言:javascript
复制
L.control.geocoder().addTo(map);

angular crash。(在类型'typeof Control‘上不存在'geocoder’属性)我也尝试了esri-leaflet-geocoder,但它也崩溃了。

有什么解决方案吗?

EN

回答 3

Stack Overflow用户

发布于 2021-06-09 00:19:54

我也有同样的问题。我通过这样做修复了它

代码语言:javascript
复制
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);
});
...
票数 1
EN

Stack Overflow用户

发布于 2020-01-03 17:26:34

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

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

代码语言:javascript
复制
var geocoder = new L.Control.geocoder();
map.addControl(geocoder);
票数 0
EN

Stack Overflow用户

发布于 2020-02-19 22:52:06

我也有同样的问题。我在L.Routing.control中添加了地理编码器,它可以工作了!(实际上,VS代码仍然是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,leaftlet-routing-machine插件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59575551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档