简体   繁体   English

如何使用URL参数将地址传递到我的JavaScript API地图?

[英]How do I pass an address into my javascript API map using URL parameters?

I am using the latest version of the ESRI JavaScript API to build a basemap template. 我使用最新版本的ESRI JavaScript API来构建底图模板。 What I would like to do is pass an address parameter into my map so that when it opens the map is zoomed into the address in question. 我想要做的是将地址参数传递到我的地图中,这样当它打开时,地图会缩放到相关地址中。 Similar to the examples below: 与以下示例类似:

Viewer for Flex: (link not active) http://myserver.com/flexviewers/actmap/index.html?search=15 Fordham St, Pocatello, Idaho Flex的Viewer :(链接未激活) http://myserver.com/flexviewers/actmap/index.html?search=15 Fordham St,Pocatello,Idaho

ArcGIS Online http://www.arcgis.com/home/webmap/viewer.html?find=380 new york st,redlands,ca ArcGIS Online http://www.arcgis.com/home/webmap/viewer.html?find=380 new york st,redlands,ca

How do I do this? 我该怎么做呢? Do I need to define parameters within the code or can I simply pass URL parameters to the map like in the above examples to the geocode or locator tools? 我是否需要在代码中定义参数,或者我可以简单地将URL参数传递给地图,如上例中的地理编码或定位工具一样?

The ESRI Javascript API uses DOJO and so you would need to write some JavaScript to take the address in the URL and the pass it to a locator service. ESRI Javascript API使用DOJO ,因此您需要编写一些JavaScript来获取URL中的地址并将其传递给定位器服务。

Parsing the URL could be done in DOJO with the following code: 解析URL可以在DOJO中使用以下代码完成:

var params = getUrlParams();
var id = params['id']; // or params.id

or use Dojo provides http://dojotoolkit.org/reference-guide/dojo/queryToObject.html 或使用Dojo提供http://dojotoolkit.org/reference-guide/dojo/queryToObject.html

then this link will give you some information on calling the locator service https://developers.arcgis.com/javascript/jssamples/locator_service.html 然后此链接将为您提供有关调用定位器服务的一些信息https://developers.arcgis.com/javascript/jssamples/locator_service.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM