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); } }
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); } }
The Specify WebMap via URL sample shows this.
Does this page exist anymore? If not, can anyone tell me where it has been moved to or at least some similar sample code?
Here's its new address: Web map using url parameters | ArcGIS API for JavaScript
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:
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?
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.