Zoom to Passed URL Code Help

1601
6
Jump to solution
03-07-2012 02:51 AM
AlexDeVine
New Contributor III
Morning Folks,

I am currently redeveloping the campus web application for my university and wanted to reprogram an old functionality back in. When our campus map was ArcIMS-based, our registrar's office was apple to pass building number parameters via url to the map service from the campus class registration site and have the web app open zoomed to the building number passed. When we moved out map from ArcIMS to .Net Web ADF, I eliminated that functionality when I discovered that adding that functionality to the web app at that point was beyond my coding capability. A few years later now, and I have become a better coder. I am redeveloping the web app in javascript API and would like to allow the registrar's office to link and zoom to our web map again.

I believe I know how I could accomplish this, but I wanted to ask you more experienced folks if this seems the most efficient way: I already have a find, create graphics from results and zoom to envelope of graphics set of functions in my web app and was hoping to just utilize that. Here is the code:

 
function execute(searchText) {          //set the search text to find parameters          findParams.searchText = searchText;          findTask.execute(findParams, showResults);     }          function showResults(results) {        //display the results of the building text search          //symbology for graphics          var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 1), new dojo.Color([0, 255, 255, 0.25]));          var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([0, 255, 255]), 1);          var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([0, 255, 255]), 2), new dojo.Color([0, 255, 255, 0.25]));            //find results return an array of graphics in the graphicslayer.          var graphicslayer = new esri.layers.GraphicsLayer();                  map.graphics.clear();           //Build an array of attribute information and add each found graphic to the map           dojo.forEach(results, function(result) {             var graphic = new esri.Graphic(result.feature);             graphic.setSymbol(polygonSymbol);             map.graphics.add(graphic);              graphicslayer.add(graphic);                                    });            //create an extent matching the graphics of the parcel(s)          var zoomExtent = esri.graphicsExtent(graphicslayer.graphics);    var zoomXmin = zoomExtent.xmin;    var zoomXmax = zoomExtent.xmax;    var zoomScale = zoomXmax - zoomXmin;    if (zoomExtent.xmin < 2508000 || zoomExtent.ymin < 1420000 || zoomExtent.xmax > 2567000 || zoomExtent.ymax > 1453000)                  {     alert("Your Find Building results include a building outside of ACC/Main UGA Campus. Please refine your search");     }    else if (zoomScale > 10000)     {      alert("Your Find Building results require a coarse scale to display. Please refine your search");      }    else     {     map.setExtent(zoomExtent.expand(2));     }         } 


I was thinking that I could get the registrar's office to change their software to generate a url appended with ?NUMBER=#### and I could write a function to parse the code, extract the value for number and pass that to the above existing function and have it handle the task. Would this be the most efficient way to accomplish this? I would probably use an if statement in the "init" function to look for a url with the appended info and then just make it jump to the function execute(searchText). Does that sound reasonable? Anyone have a better solution? Thank you in advance for your help.

Alex DeVine
University of Georgia
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
We have a sample in the help that shows how to extract info from the url then zoom to that location:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/exp_history.ht...

View solution in original post

0 Kudos
6 Replies
KellyHutchins
Esri Frequent Contributor
We have a sample in the help that shows how to extract info from the url then zoom to that location:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/exp_history.ht...
0 Kudos
AlexDeVine
New Contributor III
Thanks, Kelly!


In case anyone looks at this down the line, I created this function adapted from link info you posted to extract the search info from the url:

function getBuildNoFromUrl(url) {
             var urlObject = esri.urlToObject(url);
             if (urlObject.query && urlObject.query.NUMBER) {
                    return urlObject.query.NUMBER;
             }
          }


and then added this code to my init function to pass that search info to my existing findTask

var url = window.location;
          var NUMBER = getBuildNoFromUrl(document.location.href);
          if (!!NUMBER){ 
            searchText = NUMBER;
            execute(searchText);
  }


Worked like a charm!
0 Kudos
ChristopherPollard
Occasional Contributor
Kelly,
Do you have any additional samples that show how to simply open another AGJapi web application, then zoom and center to a lat/long.
I found this sample which will zoom to a Arcgis.com web map which is perfect.
http://www.arcgis.com/home/webmap/viewer.html?webmap=27b7e8d12a4b45649bce510b53c60c6a&center=-75.163...

but now I need one for this mapping application that I created:
http://www.dvrpc.org/webmaps/trafficcounts/index.html

I want to be able to go between two separate AGJapi that have different datasets but sometimes users want to view additional data that might be related.
Here's the second mapping application:
http://www.dvrpc.org/webmaps/cmp/index.htm

I can easily capture the lat/long of the user click or from the layer being identified but I am now sure how to pass the URL after the initial 'index.html'.
Thanks,
Chris
0 Kudos
KellyHutchins
Esri Frequent Contributor
Christopher,

The general idea would be to construct a url to the application you want to open and append the extent (or center point) to the end of the url. Here's a snippet that shows how to get the current extent, append it to a  url then use window.location to navigate to that url:

var zoomExtent = "extent=" + dojo.toJson(map.extent.toJson());
window.location = appUrl + "?" + zoomExtent;



The application you are going to open needs to be setup to read the url parameters and zoom to that location. This sample shows in the help shows how to read url params:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/exp_history.ht...
0 Kudos
ThomasFurcron
Occasional Contributor
Kelly,

The link you provided is now disabled (http://help.arcgis.com/en/webapi/jav...p_history.html), I found the samples are on the new webpage, but I can't find the one you were linking to.  Can you point me in the right direction?

Thanks!!

Tom
0 Kudos
KenBuja
MVP Esteemed Contributor
0 Kudos