urlUtils JS 4.2

2080
3
Jump to solution
01-24-2017 03:03 PM
PatrckWild
New Contributor II

I see that JS API 4.2 doesn't yet support urlUtils.

Is this awaiting or is there a new/better solution?

Does anyone have an example to build a simple app with JS 4.2 that will accept url parameters like the 3.19 exp_history example?

https://developers.arcgis.com/javascript/3/samples/exp_history/?parceled=1919402007

Thanks,

PW

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

Are you looking for urlUtils.urlToObject()?

urlUtils | API Reference | ArcGIS API for JavaScript 4.2 

urlUtils.urlToObject("https://developers.arcgis.com/javascript/3/samples/exp_history/?parceled=191940200");

/** outputs
{
  "path": "https://developers.arcgis.com/javascript/3/samples/exp_history/",
  "query": {
    "parceled": "1919402007"
  }
}
**/

View solution in original post

3 Replies
SteveCole
Frequent Contributor

You could still do this with strictly javascript. I mean, it's certainly more elegant and nice to have a helper like the urlUtils but isn't that hard to do otherwise. Here's a snippit that zooms the map to a lat/long if passed as a parameter in the URL:

//If a coordinate location was passed as a parameter, zoom the map to it
//Evaluate the URL of this HTML page to determine if any parameters were passed with it
htmlPagePath = window.location.toString();
qLocation = htmlPagePath.indexOf('?');

if (qLocation < 1){
    passedLatLong = false;
} else {
    passedLatLong = true;
}
 
if (passedLatLong) 
 {
 //Extract the lat/long coordinates passed as a parameter with the URL
 var coordStr = window.location.toString().substr(qLocation + 1,window.location.toString().length);
 var coords = new Array();
 coords = coordStr.split(',');
 
 //Create a lat/long point
 var bridgeLoc = new Point(coords[0],coords[1], new SpatialReference({wkid:4326}));
 var theLatLongPoint = new Point(coords[0],coords[1], new SpatialReference({ wkid: 4326 }));
 var webMercatorPoint = webMercatorUtils.geographicToWebMercator(theLatLongPoint);
 map.centerAndZoom(webMercatorPoint, 16);
 map.resize();
 }

This just assumed that the url was something like "http://server/folder/index.html?-122,48"

You can easily adjust this to be "...?parcelId=xxxx"

ReneRubalcava
Frequent Contributor

Are you looking for urlUtils.urlToObject()?

urlUtils | API Reference | ArcGIS API for JavaScript 4.2 

urlUtils.urlToObject("https://developers.arcgis.com/javascript/3/samples/exp_history/?parceled=191940200");

/** outputs
{
  "path": "https://developers.arcgis.com/javascript/3/samples/exp_history/",
  "query": {
    "parceled": "1919402007"
  }
}
**/
PatrckWild
New Contributor II

Looks like it moved from esri/urlUtils to esri/core/urlUtils

Thanks Rene!

0 Kudos