Getting the Map Service REST URL to the Map as URL parameter

Discussion created by marylandgis on Aug 4, 2011
Latest reply on Aug 4, 2011 by stevel
I'm a javascript novice.

Undaunted, I would like to pass the dynamic map service URL parameter here

var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer.toString("string_goes_here");

as a URL parameter, rather than writing it explicitly into the html file as in the simple JS map viewer examples.

I'm grabbing the URL ok using the function shown below.  I'd like to simply pass the contents of the var from that function into the operationalLayer variable like this:

var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(rest_url);

Or like this:

var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer.toString(rest_url);

But neither of those approaches work, of course.  Can someone point the way?   (Hopefully, short and straight.)


  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 "";
    return results[1];
var rest_url = gup( 'resturl' );