我正在使用很棒的esri-leaflet-geocoder
插件,但无法在生产中渲染。
我注册了一个provider(ArcGIS Online Geocoding Service)并得到了一个api key,然后按照github页面上的文档添加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 的官方文档页面并尝试了那里列出的内容。事实证明,它似乎更最新。
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”在生产中工作/渲染?