首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Leaflet Esri在Angular上进行地理编码而不是导入地理编码类

Leaflet Esri在Angular上进行地理编码而不是导入地理编码类
EN

Stack Overflow用户
提问于 2020-09-17 15:22:17
回答 1查看 678关注 0票数 0

我尝试在Angular项目中使用地理编码表单esri-leaflet库,但我有导入类问题。

这是我的组件代码:

代码语言:javascript
复制
import { Component, OnInit, AfterViewInit, Type } from '@angular/core';
import { latLng, tileLayer, layerGroup, marker, Layer, Control, circle, polygon, Map } from 'leaflet';
import * as L from 'leaflet';
import * as esri from 'esri-leaflet';
import GeocodeService from 'esri-leaflet-geocoder/dist/esri-leaflet-geocoder';


@Component({
  selector: 'abd-map',
  templateUrl: './abd-map.component.html',
  styleUrls: ['./abd-map.component.scss']
})
export class AbdMapComponent implements OnInit, AfterViewInit {


  constructor() {}

  ngOnInit(): void {

 }


  ngAfterViewInit(): void{


    const openStreetMap = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
      attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    });

    const googleMap = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
        maxZoom: 20,
        subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
    });


    const map = L.map('map', {
        center: [39.61, -105.02],
        zoom: 13,
        layers: [openStreetMap, googleMap]
    });

    const baseMaps = {
      'openStreetMap': openStreetMap,
      'googleMap': googleMap
  };

    L.control.layers(baseMaps).addTo(map);


    const searchControl = esri.Geocoding.geosearch().addTo(map);


  }



}

当我运行"ng serve“时,我得到了这个错误:

/src/app/abd-map/abd-map.Component.TS 41:30-44“在'esri-leaflet‘中找不到导出'Geocoding’(导入为'esri')时出错。”

有人能帮我吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-09-17 16:49:49

您应该导入:

代码语言:javascript
复制
import "leaflet/dist/leaflet.css";
import * as L from "leaflet";
import "esri-leaflet-geocoder/dist/esri-leaflet-geocoder.css";
import "esri-leaflet-geocoder/dist/esri-leaflet-geocoder";
import * as ELG from "esri-leaflet-geocoder";

然后像这样初始化插件:

代码语言:javascript
复制
  const searchControl = new ELG.Geosearch();
  const results = new L.LayerGroup().addTo(map);

    searchControl
      .on("results", function (data) {
        results.clearLayers();
        for (let i = data.results.length - 1; i >= 0; i--) {
          results.addLayer(L.marker(data.results[i].latlng));
        }
      })
      .addTo(map);

Demo

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

https://stackoverflow.com/questions/63933122

复制
相关文章

相似问题

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