<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> <title>Topographic Map</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.1/js/dojo/dijit/themes/claro/claro.css"> <style> html, body { height: 100%; width: 100%; margin: 0; padding: 0; } .esriScalebar{ padding: 20px 20px; } #map{ padding:0; } </style> <script type="text/javascript">var djConfig = {parseOnLoad: true};</script> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.1"></script> <script type="text/javascript"> dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); var map; function init() { var initExtent = new esri.geometry.Extent({"xmin":-122.46,"ymin":37.73,"xmax":-122.36,"ymax":37.77,"spatialReference":{"wkid":4326}}); map = new esri.Map("map",{ extent:esri.geometry.geographicToWebMercator(initExtent) }); var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"); map.addLayer(basemap); //if there are url params zoom to location var coords, zoomLevel; var urlObject = esri.urlToObject(document.location.href); if(urlObject.query && urlObject.query.coords && urlObject.query.zoomLevel){ var coords = urlObject.query.coords.split(','); var lon = parseFloat(coords[0]); var lat = parseFloat(coords[1]); var zoomLevel = parseInt(urlObject.query.zoomLevel); var point = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lon,lat)); map.centerAndZoom(point,zoomLevel); } dojo.connect(map, 'onLoad', function(theMap) { //resize the map when the browser resizes dojo.connect(dijit.byId('map'), 'resize', map,map.resize); }); } dojo.addOnLoad(init); </script> </head> <body class="claro"> <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;"> <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="border:1px solid #000;padding:0;"> </div> </div> </body> </html>
I know this post is going on 3 years old, but thank you! This code works perfectly!
var urlObject = esri.urlToObject(document.location.href); // Set our default position, zoom level and layerid's x = 349299; y = 313074; zoomLevel = 0; // Do we have a qeury string on the URL? if (urlObject.query) { // Do we have a coords parameter? if (urlObject.query.coords) { var coords = urlObject.query.coords.split(','); // We have an x and a y right? if (coords.length == 2) { x = parseFloat(coords[0]); y = parseFloat(coords[1]); console.log("x coord passed to map: ", x); console.log("y coord passed to map: ", y); } } // Let's check for a zoomlevel if (urlObject.query.zoomLevel) { var zoomLevel = parseInt(urlObject.query.zoomLevel); console.log("Zoomlevel passed to map: ", zoomLevel); } //Let's check if any layers are specified /*if (urlObject.query.layers) { //layers = parseInt(urlObject.query.layers); layers = urlObject.query.layers.split(','); console.log("layer ID's passed to map: ", layers); }*/ if (urlObject.query.lgsl) { var lklgsl = urlObject.query.lgsl; layers = matchLgsl(lklgsl); console.log("lgsl code:", lklgsl); } //set the visable layers that where passed in the url lbsr.setVisibleLayers(layers); console.log("Layer ID's being drawn", layers); } // Position our mapto the x and y provided in the url var point = new esri.geometry.Point([x, y], new esri.SpatialReference({ wkid: 27700 })); //var point = esri.geometry.Point(new esri.geometry.Point(x, y)); console.log("Zooming to location...", point, zoomLevel); map.centerAndZoom(point, zoomLevel); console.log("Zoom complete"); // Highlight the item on our map if (!graphic) { addGraphic(point); } else { graphic.setGeometry(point); };
function gup(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); if (results == null) return ""; else return results[1]; }
//check to see if an envelope has been sent (ie four values in x1,x2,y1 & y20 var newExtent = new esri.geometry.Extent(); var xMin = Math.abs(gup('x1')); var yMin = Math.abs(gup('y1')); var xMax = Math.abs(gup('x2')); var yMax = Math.abs(gup('y2')); var mk, pt, gra; //check to see if just a point has been sent in x1 & y1 if (Math.abs(gup('y2')) == 0 && (Math.abs(gup('x2')) == 0) && (Math.abs(gup('x1')) > 0) && (Math.abs(gup('y1')) > 0)) { x1 = xMin y1 = yMin xMin = xMin - 50 yMin = yMin - 50 xMax = xMin + 100 yMax = yMin + 100 dojo.connect(map, "onLoad", function () { ShowLocation(x1, y1); }); } if ((xMin > 0) && (yMin > 0) && (xMax > 0) && (yMax > 0)) { newExtent.xmin = xMin; newExtent.ymin = yMin; newExtent.xmax = xMax; newExtent.ymax = yMax; newExtent.spatialReference = new esri.SpatialReference({ wkid: 27700 }); map.setExtent(newExtent); }
Is there a way to accomplish this in AGOL (or AGOL WAB)? The framework is pretty robust...
I want to basically have a user click on a point and the app stores that click's coordinates. Then in the pop-up, there is an out-link <a href></a> that appends the x & y to the end of the URL.
So if a user clicked a point of 100,30 the outlink URL would be http://website.com/index.html?x=100&y=30
Is this possible?