Select to view content in your preferred language

URL Parameters

18044
20
05-27-2010 07:32 AM
AndyBurns
Occasional Contributor
Hi All

Does anyone have any documentation or any ideas about what URL parameters we can pass to the javascript API?

thanks
0 Kudos
20 Replies
JohnGrayson
Esri Regular Contributor
Since this functionality is application specific, here's one example of how I've done it before:

  
  var urlObject = esri.urlToObject(document.location.href);
  if (urlObject.query) {
    if (urlObject.query.lon && urlObject.query.lat) {
      var lon = parseFloat(urlObject.query.lon);
      var lat = parseFloat(urlObject.query.lat);
      var initialLocation = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lon, lat, new esri.SpatialReference({
        wkid: 4326
      })));
      map.centerAndZoom(initialLocation, 14);
    }
  }
0 Kudos
RajasekharReddyMayaluru
New Contributor
Hi Grayson,

I'm new to this API, I'm trying to integrate with Arc GIS with my web application .

Can you please send me full example (with some URL with static values),So that i can customize it.

I'm looking for an example to locate a point using Arc GIS javascript API to pass lat/lng as input .


Thanks,
Rajasekhar


Since this functionality is application specific, here's one example of how I've done it before:

  
  var urlObject = esri.urlToObject(document.location.href);
  if (urlObject.query) {
    if (urlObject.query.lon && urlObject.query.lat) {
      var lon = parseFloat(urlObject.query.lon);
      var lat = parseFloat(urlObject.query.lat);
      var initialLocation = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lon, lat, new esri.SpatialReference({
        wkid: 4326
      })));
      map.centerAndZoom(initialLocation, 14);
    }
  }
0 Kudos
MichaelOlkin
New Contributor III
I've been interested for quite some time in being able to use url parameters to select & zoom to features by using the parameters in attribute queries.  It's disappointing that this basic function is still not included among the ArcGIS API for Javascript code samples.  I've gone ahead & developed my own code sample, which I've posted to ArcGIS.com here: http://www.arcgis.com/home/item.html?id=92ff586d7e934fde9ee62356592f8761

The sample that I posted uses two parameters to select a tax parcel.  Clicking a different parcel on the map revises the parameters.  The UrlToObject method in the Esri namespace is used to convert the url parameters into variables & the HTML5 Pushstate method is used for updating the parameters when a different parcel is clicked.

I hope that this sample is helpful.  All suggestions and comments are welcome.

Michael Olkin
GIS Administrator
Town of Amherst, MA
http://www.amherstma.gov/maps
0 Kudos
KellyHutchins
Esri Frequent Contributor
Nice sample Mike. This is a frequently asked question so we really should have a sample that shows how to do this in the help.
0 Kudos
derekswingley1
Frequent Contributor II
The Specify WebMap via URL sample shows this.
MichaelOlkin
New Contributor III
The Specify WebMap via URL sample shows this.


That's a good sample and it uses a URL parameter, but not to select a feature.
0 Kudos
MichaelVolz
Esteemed Contributor

Does this page exist anymore?  If not, can anyone tell me where it has been moved to or at least some similar sample code?

0 Kudos
KenBuja
MVP Esteemed Contributor
0 Kudos
MichaelVolz
Esteemed Contributor

Ken:

According to your reply this sample URL is:

http://developers.arcgis.com/javascript/samples/ags_basic

Does I just add the extents the end of the URL for it to zoom in at start-up like this:

http://developers.arcgis.com/javascript/samples/ags_basic?Extent=-8427510.777,4867167.541,-8425000.4...

I got the extents by loading in an ESRI basemap which I thought would be the projection that would work with your sample, but it does not zoom to anything and just shows white space.

Am I using the wrong coordinate system in my test URL?

0 Kudos
JordanBaumgardner
Occasional Contributor III

You get to specify the parameter format.

?x1=123.123&y1=123.123&...

?extent=123.13,123.12,123.12,123.12

What I think you might have missed is the JS code that reads it in.

//get the web map id from the url
urlObject
= esri.urlToObject(document.location.href);
urlObject
.query = urlObject.query || {};
if(urlObject.query && urlObject.query.webmap){
    configOptions
.webmap = urlObject.query.webmap;
}

You need to read the params off the url/query string and the do something with the values.

0 Kudos