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.479,4869435.962
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?
Here's its new address: Web map using url parameters | ArcGIS API for JavaScript
Does this page exist anymore? If not, can anyone tell me where it has been moved to or at least some similar sample code?
lol, Me: Well that's a big flippn question! Gotta see what the answer is ; )
I created a module that will update the browser's query string as the map is zoomed, panned, and layers are turned on and off.
WSDOT-GIS/arcgis-query-string-utilities · GitHub
Hi there Can I see how you have been used this code?
The Specify WebMap via URL sample shows this.
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); } }
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); } }
function getUrlParam(name, url) { // optionally pass an URL to parse if (!url) url = window.location.href; // if no parameter url is given, use the page URL name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); // instruction needed if we want to extract an array var results = new RegExp("[\\?&]"+name+"=([^&#]*)").exec(url); if( results == null ) return null; // if the name is not found, return null else // decodeURIComponent doesn't recognize '+' as encoding for space return decodeURIComponent(results[1].replace(/\+/g," ")); }
function buildUrl() { //This function constructs a url argument to use when passing shared urls. var mext, dfrom, dto, ll, ur, xa, xg, xf, xt, ct; mext = dijit.byId("map").getMap().extent; dfrom = dijit.byId("dateFrom").value; dto = dijit.byId("dateTo").value; ll = "" + mext.xmin + "," + mext.ymin; ur = "" + mext.xmax + "," + mext.ymax; xa = dijit.byId("sp").searchaddress; xg = dijit.byId("gmSelectAreas").value; xf = "" + (1 + dfrom.getMonth()) + "+" + dfrom.getDate() + "+" + dfrom.getFullYear(); xt = "" + (1 + dto.getMonth()) + "+" + dto.getDate() + "+" + dto.getFullYear(); ct = dojo.cookie("ct"); //return window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + dojox.encoding.crypto.Blowfish.encrypt("ll=" + ll + "&ur=" + ur + ((xa) ? "&xa=" : "") + xa + ((xg) ? "&xg=" : "") + xg + "&xf=" + xf + "&xt=" + xt + "&ct=" + ct, "slcpd"); return window.location.protocol + "//" + window.location.host + window.location.pathname + "?ll=" + ll + "&ur=" + ur + ((xa) ? "&xa=" : "") + xa + ((xg) ? "&xg=" : "") + xg + "&xf=" + xf + "&xt=" + xt + "&ct=" + ct; } function getValuesFromURL(name,urlstring) { //Utility function for finding a url argument in a url. See how it is used below. //Use RegExp to clean up the URL and to search for the given parameter name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(urlstring); if (results === null) { return ""; } else { return (results[1]); } } //In body of main code for page var sstring = window.location.search; urlargs = { ll: dojo.map(getValuesFromURL("ll", sstring).split("%2c"),function(x) { return parseFloat(x);},this), //Lower left ur: dojo.map(getValuesFromURL("ur", sstring).split("%2c"),function(x) { return parseFloat(x);},this), //Upper right xa: getValuesFromURL("xa", sstring).split("+").join(" "), //Search Address xg: getValuesFromURL("xg", sstring), //geokey to a specific location xf: new Date(Date.parse(getValuesFromURL("xf", sstring).split("+").join(" "))), //Date from xt: new Date(Date.parse(getValuesFromURL("xt", sstring).split("+").join(" "))), //Date to xs: getValuesFromURL("xs", sstring), //Sort by xk: getValuesFromURL("xk", sstring), //Skin ct: getValuesFromURL("ct", sstring) //Crime Types }; urlargs.xf = (urlargs.xf > 0) ? urlargs.xf : ""; urlargs.xt = (urlargs.xt > 0) ? urlargs.xt : ""; //This part is wrapped in a large try...catch because bad arguments can throw errors if (urlargs.xs) { dojo.cookie("xs", urlargs.xs); } //Then still yet farther down, when I am creating the map object options = { extent: urlargs.urlextent || urlargs.initextent //There is more, but that is the key part for extent }; //And then I pass that options object as the 2nd argument when creating the map if (urlargs.ll[0] && urlargs.ll[1] && urlargs.ur[0] && urlargs.ur[1]) { urlargs.urlextent = new esri.geometry.Extent({ "xmin": urlargs.ll[0], "ymin": urlargs.ll[1], "xmax": urlargs.ur[0], "ymax": urlargs.ur[1], "spatialReference": { "wkid": 102113 } }); } else { urlargs.initextent = new esri.geometry.Extent({ "xmin": -10137766.624432003, "ymin": 4628644.247807602, "xmax": -9998498.358896358, "ymax": 4711960.608638476, "spatialReference": { "wkid": 102113 } }); }
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.