Angular 传单Esri地理编码非导入地理编码类
我尝试在Angular项目上使用地理编码表单esri传单库,但我有导入类问题 这是我的组件代码:Angular 传单Esri地理编码非导入地理编码类,angular,typescript,leaflet,esri,esri-leaflet-geocoder,Angular,Typescript,Leaflet,Esri,Esri Leaflet Geocoder,我尝试在Angular项目上使用地理编码表单esri传单库,但我有导入类问题 这是我的组件代码: 从'@angular/core'导入{Component,OnInit,AfterViewInit,Type}; 从“传单”导入{latLng、tileLayer、layerGroup、marker、Layer、Control、圆圈、多边形、Map}; 从“传单”中输入*作为L; 从“esri传单”导入*作为esri; 从“esri传单地理编码器/dist/esri传单地理编码器”导入地理编码服务
从'@angular/core'导入{Component,OnInit,AfterViewInit,Type};
从“传单”导入{latLng、tileLayer、layerGroup、marker、Layer、Control、圆圈、多边形、Map};
从“传单”中输入*作为L;
从“esri传单”导入*作为esri;
从“esri传单地理编码器/dist/esri传单地理编码器”导入地理编码服务;
@组成部分({
选择器:“abd映射”,
templateUrl:'./abd map.component.html',
样式URL:['./abd-map.component.scss']
})
导出类AbdMapComponent实现OnInit,AfterViewInit{
构造函数(){}
ngOnInit():void{
}
ngAfterViewInit():void{
const openStreetMap=L.tileLayer('https://{s}.tile.openStreetMap.org/{z}/{x}/{y}.png'{
属性:“©;贡献者”
});
const googleMap=L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'{
maxZoom:20,
子域:['mt0','mt1','mt2','mt3']
});
常量map=L.map('map'{
中间:[39.61,-105.02],
缩放:13,
图层:[openStreetMap,谷歌地图]
});
常数基映射={
“openStreetMap”:openStreetMap,
“谷歌地图”:谷歌地图
};
L.控制。图层(底图)。添加到(地图);
const searchControl=esri.Geocoding.geosearch().addTo(map);
}
}
您应该导入:
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";
然后像这样初始化插件:
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);
好的,谢谢,现在我的代码可以导入了,但是反向地理编码也有问题。const geocodeService=esriGeocoder.geocodeService();map.on('click',e=>{debugger geocodeService.reverse().latlng(e.latlng).run(res=>{});});错误TS2339:类型“传单事件”上不存在属性“latlng”。这是另一个问题,我的朋友。请以新的方式提问,如果答案对你有帮助,请接受/投票。