我无法显示地图,也无法使用esri提供的搜索:这里是类型记录文件的代码。
import { Component, OnInit } from '@angular/core';
import { Title, Meta } from '@angular/platform-browser';
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 esri from "esri-leaflet-geocoder";
/*import * as esri from "esri-leaflet";*/ this one is not working i already installed it.
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']})
export class AppComponent implements OnInit{
marker;
title = 'Events Management';
constructor() { }
ngOnInit(){
const apiKey = "I already have the key";
const basemapEnum = "ArcGIS:Navigation";
const map = L.map("map", {
minZoom: 2
}).setView([-33.8688,151.2093], 14); // Sydney
L.esri.Vector.vectorBasemapLayer(basemapEnum, {
apiKey: apiKey
}).addTo(map);
const searchControl = esri.Geocoding.geosearch({
position: "topright",
placeholder: "Enter an address or place e.g. 1 York St",
useMapBounds: false,
providers: [esri.Geocoding.arcgisOnlineProvider({
apikey: apiKey,
nearby: {
lat: -33.8688,
lng: 151.2093
},
})]
}).addTo(map);
const results = L.layerGroup().addTo(map);
searchControl.on("results", (data) => {
results.clearLayers();
for (let i = data.results.length - 1; i >= 0; i--) {
const lngLatString = `${Math.round(data.results[i].latlng.lng * 100000)/100000}, ${Math.round(data.results[i].latlng.lat * 100000)/100000}`;
const marker = L.marker(data.results[i].latlng);
marker.bindPopup(`<b>${lngLatString}</b><p>${data.results[i].properties.LongLabel}</p>`)
results.addLayer(marker);
marker.openPopup();
}
});
}
}ERROR TypeError: leaflet__WEBPACK_IMPORTED_MODULE_2__.esri是未定义的--这是我在控制台中看到的错误--我到处查找,但是什么也没有发现,即使我只用esri更改了L,它也不能与向量部分一起工作
发布于 2021-02-07 06:12:38
我不知道角,但你已经评论了你进口埃斯里传单的地方:
/*import * as esri from "esri-leaflet";*/您应该重命名来自esri -Geo编码器的导入,这样它就不会干扰您的esri导入:
import * as esri from "esri-leaflet"
import * as EsriGeocoder from "esri-leaflet-geocoder"如果没有esri,esri对象就不会导入并附加到L,任何对任何L.esri的调用都不会起作用。
https://stackoverflow.com/questions/66032585
复制相似问题