<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting the Map Service REST URL to the Map as URL parameter in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196868#M18249</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;But how to I pass that string to this variable?&lt;BR /&gt;var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer("string_goes_here"); &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Don,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry, I misunderstood your question. What is the value of rest_url after you've sent it through your function?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The syntax for specifying the URL parameter is shown &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/arcgisdynamicmapservicelayer.htm"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The URL should be something like &lt;/SPAN&gt;&lt;A href="http://server/ArcGIS/rest/services/layername"&gt;http://server/ArcGIS/rest/services/layername&lt;/A&gt;&lt;SPAN&gt; - see the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/ags_rest.htm"&gt;Services Directory&lt;/A&gt;&lt;SPAN&gt; help file entry.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Aug 2011 00:03:39 GMT</pubDate>
    <dc:creator>StephenLead</dc:creator>
    <dc:date>2011-08-05T00:03:39Z</dc:date>
    <item>
      <title>Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196865#M18246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm a javascript novice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Undaunted, I would like to pass the dynamic map service URL parameter here&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer.toString("string_goes_here");&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;as a URL parameter, rather than writing it explicitly into the html file as in the simple JS map viewer examples.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm grabbing the URL ok using the function shown below.&amp;nbsp; I'd like to simply pass the contents of the var from that function into the operationalLayer variable like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(rest_url);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer.toString(rest_url);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But neither of those approaches work, of course.&amp;nbsp; Can someone point the way?&amp;nbsp;&amp;nbsp; (Hopefully, short and straight.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Don&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; function gup( name )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; var regexS = "[\\?&amp;amp;]"+name+"=([^&amp;amp;#]*)";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; var regex = new RegExp( regexS );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; var results = regex.exec( window.location.href );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if( results == null )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return results[1];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;var rest_url = gup( 'resturl' );&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2011 23:33:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196865#M18246</guid>
      <dc:creator>DonBarker</dc:creator>
      <dc:date>2011-08-04T23:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196866#M18247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can't test this (and I'm not an expert on regexp), but I think you might want to do something along these lines:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

var fullUrl = window.location.href; //get the full URL
var layerUrl = gup(fullUrl); // send this to the function
console.log(layerUrl);// this should be just the layer definition section

function gup( name )
{
&amp;nbsp; name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
&amp;nbsp; var regexS = "[\\?&amp;amp;]"+name+"=([^&amp;amp;#]*)";
&amp;nbsp; var regex = new RegExp( regexS );
&amp;nbsp; var results = regex.exec(name);
&amp;nbsp; if( results == null )
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "";
&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; return results[1]; //return just the Layer definition of the URL
}

&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:50:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196866#M18247</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2021-12-11T09:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196867#M18248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Steve,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for taking time to reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm already getting the map service REST URL as a string variable ok.&amp;nbsp; So the regex is not a problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But how to I pass that string to this variable?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer("string_goes_here");&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Don&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2011 23:59:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196867#M18248</guid>
      <dc:creator>DonBarker</dc:creator>
      <dc:date>2011-08-04T23:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196868#M18249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;But how to I pass that string to this variable?&lt;BR /&gt;var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer("string_goes_here"); &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Don,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry, I misunderstood your question. What is the value of rest_url after you've sent it through your function?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The syntax for specifying the URL parameter is shown &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/arcgisdynamicmapservicelayer.htm"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The URL should be something like &lt;/SPAN&gt;&lt;A href="http://server/ArcGIS/rest/services/layername"&gt;http://server/ArcGIS/rest/services/layername&lt;/A&gt;&lt;SPAN&gt; - see the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/ags_rest.htm"&gt;Services Directory&lt;/A&gt;&lt;SPAN&gt; help file entry.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2011 00:03:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196868#M18249</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2011-08-05T00:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196869#M18250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The value is a clean URL like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://129.2.24.163/ArcGIS/rest/services/00_SMC_Environmental_Health/MapServer"&gt;http://129.2.24.163/ArcGIS/rest/services/00_SMC_Environmental_Health/MapServer&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2011 00:06:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196869#M18250</guid>
      <dc:creator>DonBarker</dc:creator>
      <dc:date>2011-08-05T00:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196870#M18251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The value is a clean URL like this:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://129.2.24.163/ArcGIS/rest/services/00_SMC_Environmental_Health/MapServer" rel="nofollow noopener noreferrer" target="_blank"&gt;http://129.2.24.163/ArcGIS/rest/services/00_SMC_Environmental_Health/MapServer&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a bit confused now, since this works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var rest_url = "http://129.2.24.163/ArcGIS/rest/services/00_SMC_Environmental_Health/MapServer";
var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(rest_url); 
map.addLayer(dynamicMapServiceLayer);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you examine rest_url at run-time in FireBug and ensure that it's a valid string?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry I haven't been able to help much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:50:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196870#M18251</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2021-12-11T09:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196871#M18252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Steve,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I confused you because Im a poor javascripter.&amp;nbsp; I believed that this could not work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(rest_url); &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;You have affirmed that it should work.&amp;nbsp; So now I see how to pursue this.&amp;nbsp; I need to prepend "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://" rel="nofollow" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;" to the var rest_url.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks so much for helping me muddle through this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2011 02:19:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196871#M18252</guid>
      <dc:creator>DonBarker</dc:creator>
      <dc:date>2011-08-05T02:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Map Service REST URL to the Map as URL parameter</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196872#M18253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;no probs, happy to have helped. I'll be interested to see the finished result if you can post it here.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2011 03:06:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/getting-the-map-service-rest-url-to-the-map-as-url/m-p/196872#M18253</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2011-08-05T03:06:27Z</dc:date>
    </item>
  </channel>
</rss>

