如何解决Esri-leaflet-geocoder:组件未呈现;如何连接生产中的提供者
我正在使用出色的 esri-leaflet-geocoder
插件,但无法在生产环境中进行渲染。
我注册了一个provider(ArcGIS Online Geocoding Service)并拿到了api key,然后按照github页面上的documentation添加了api key:
var searchControl = L.esri.Geocoding.geosearch({
providers: [
L.esri.Geocoding.arcgisOnlineProvider({
// API Key to be passed to the ArcGIS Online Geocoding Service
useMapBounds: false,apikey: process.env.ESRI_API_KEY
})
]
});
我收到以下错误:
TypeError: Cannot read property 'Geocoding' of undefined
因此,我转到了 esri-leaflet-geocoder here 的官方文档页面并尝试了那里列出的内容。事实证明它似乎是最新的。
var provider = ELG.arcgisOnlineProvider({ token: process.env.ESRI_API_KEY });
var searchControl = new ELG.Geosearch({
useMapBounds: false,providers: [provider]
});
console.log('ELG.arcgisOnlineProvider() ',provider);
console.log('searchControl',searchControl);
它没有用,但控制台似乎表明他们确实采用了文档中列出的道具:
ELG.arcgisOnlineProvider()
NewClass {_requestQueue: Array(0),_authenticating: false,options: {…},_initHooksCalled: true,_eventParents: {…}}
options:
supportsSuggest: true
token: process.env.ESRI_API_KEY // In the log it's a string
url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/"
__proto__: Object
_authenticating: false
_eventParents: {1: NewClass}
_initHooksCalled: true
_requestQueue: []
__proto__: NewClass
searchControl
NewClass {options: {…},_geosearchCore: NewClass,_leaflet_id: 1,_initHooksCalled: true}
options:
providers: Array(1)
0: NewClass
options: {token: process.env.ESRI_API_KEY // Again it is logging a string
url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/",supportsSuggest: true}
_authenticating: false
_eventParents: {1: NewClass}
_initHooksCalled: true
_requestQueue: []
__proto__: NewClass
length: 1
__proto__: Array(0)
useMapBounds: false
__proto__: Object
那么我怎样才能让“searchControl”在生产环境中工作/渲染?
解决方法
这对我有用:
import * as ELG from "esri-leaflet-geocoder";
var searchControl = ELG.geosearch({
useMapBounds: false,providers: [
ELG.arcgisOnlineProvider({
apikey: "your key here"
})
]
});
searchControl.addTo(leafletMap);
Working codesandbox
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。