【问题标题】:Import leaftlet-control-geocoder in Angular 8 Project?在 Angular 8 项目中导入传单控制地理编码器?
【发布时间】:2020-01-03 08:52:19
【问题描述】:

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

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

有什么办法吗?

【问题讨论】:

    标签: javascript angular dictionary leaflet geocoder


    【解决方案1】:

    我遇到了同样的问题。我这样做修复了它

    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);
    });
    ...
    

    【讨论】:

      【解决方案2】:

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

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

      var geocoder = new L.Control.geocoder();
      map.addControl(geocoder);
      

      【讨论】:

      【解决方案3】:

      我遇到了同样的问题。我在 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,传单路由机插件。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2021-12-03
      • 2020-04-30
      • 1970-01-01
      相关资源
      最近更新 更多