首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Esri-leaflet-geocoder:组件未呈现;如何在生产环境中连接提供程序

Esri-leaflet-geocoder:组件未呈现;如何在生产环境中连接提供程序
EN

Stack Overflow用户
提问于 2021-03-08 02:12:32
回答 1查看 182关注 0票数 0

我使用的是一个很棒的esri-leaflet-geocoder插件,但无法让它在生产环境中呈现。

我注册了一个提供商(ArcGIS在线地理编码服务),并获得了一个api密钥,然后按照github页面上的documentation添加了api密钥:

代码语言:javascript
复制
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的官方文档页面,并尝试了那里列出的内容。事实证明,它似乎更新潮。

代码语言:javascript
复制
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);

它没有工作,但控制台似乎表明,他们确实采取了文档中列出的道具:

代码语言:javascript
复制
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”在生产环境中工作/渲染呢?

EN

回答 1

Stack Overflow用户

发布于 2021-03-08 23:44:46

这对我很有效:

代码语言:javascript
复制
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

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

https://stackoverflow.com/questions/66519812

复制
相关文章

相似问题

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