<?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: Having Issue on Adding/Removing Service Layer by Checkbox in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755748#M69877</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Behrouz,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You say that you have registered "esri.layers.FeatureLayer". This leads me to believe that you are developing using the old legacy style and not AMD Legacy code. Legacy will not be supported any more when JS API 4.0 comes out and you should quit using Legacy style. It would help to see more of your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just looking at the snippets you provided you also have an issue with the service url.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have:&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14456563199415872 jive_macro_code jive_text_macro" data-renderedposition="197_8_912_16" jivemacro_uid="_14456563199415872"&gt;&lt;SPAN class="keyword"&gt;var service =&lt;SPAN class="string"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Frenewablestoolbox.biol.sfu.ca%2Frorapp%2Frest%2Fservices%2F" rel="nofollow" target="_blank"&gt;http://renewablestoolbox.biol.sfu.ca/rorapp/rest/services/&lt;/A&gt;&lt;SPAN style="color: #e23d39;"&gt;&lt;STRONG&gt;/&lt;/STRONG&gt;&lt;/SPAN&gt;RORApp/MapServer"&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;It should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14456563257564146 jive_text_macro" data-renderedposition="255_8_912_16" jivemacro_uid="_14456563257564146" modifiedtitle="true"&gt;&lt;SPAN class="keyword"&gt;var service =&lt;SPAN class="string"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Frenewablestoolbox.biol.sfu.ca%2Frorapp%2Frest%2Fservices%2FRORApp%2FMapServer%2F" rel="nofollow" target="_blank"&gt;http://renewablestoolbox.biol.sfu.ca/rorapp/rest/services/RORApp/MapServer/&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&lt;SPAN class="keyword"&gt;Notice double slash removed and a slash added to the end of the url since you are just adding the layer id to this string.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 24 Oct 2015 03:14:26 GMT</pubDate>
    <dc:creator>RobertScheitlin__GISP</dc:creator>
    <dc:date>2015-10-24T03:14:26Z</dc:date>
    <item>
      <title>Having Issue on Adding/Removing Service Layer by Checkbox</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755745#M69874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you please take a look at this code and let me know how I can add and remove some layers based on their index number in a Map Service? I tried this before but it is not working!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Layer 52 : &amp;lt;input type="checkbox" value=52 name="overlayLayers"&amp;gt;&amp;lt;br&amp;nbsp; /&amp;gt;
Layer 53 : &amp;lt;input type="checkbox" value=53 name="overlayLayers"&amp;gt;&amp;lt;br&amp;nbsp; /&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; var service ="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Frenewablestoolbox.biol.sfu.ca%2Frorapp%2Frest%2Fservices%2F%2FRORApp%2FMapServer" target="_blank"&gt;http://renewablestoolbox.biol.sfu.ca/rorapp/rest/services//RORApp/MapServer&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; $('input:checkbox[name=overlayLayers]').on('change', function(){
&amp;nbsp;&amp;nbsp;&amp;nbsp; if($(this).is(':checked')){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var index = $(this).val();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayer(service+index);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; else{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var index = $(this).val();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.removeLayer(service+index);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
});&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:03:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755745#M69874</guid>
      <dc:creator>BruceGreen</dc:creator>
      <dc:date>2021-12-12T08:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Having Issue on Adding/Removing Service Layer by Checkbox</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755746#M69875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Behrouz,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; The main issue in your code is you are trying to add a string to the map and not an actual layer.&amp;nbsp; Try something like map.addLayer(new FeatureLayer(service+index));&amp;nbsp; and map.removeLayer is expecting an actual layer as well.&lt;/P&gt;&lt;P&gt;Look at the docs for map.getLayer:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/jsapi/map-amd.html#getlayer" title="https://developers.arcgis.com/javascript/jsapi/map-amd.html#getlayer"&gt;Map | API Reference | ArcGIS API for JavaScript | getLayer&lt;/A&gt;​ &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This would mean that you need to assign an Id to the layer when it is added.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 23:42:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755746#M69875</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2015-10-23T23:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Having Issue on Adding/Removing Service Layer by Checkbox</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755747#M69876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Robert but I tried to do what you recommend but I am not sure why I am getting this error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="err.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/133043_err.png" style="width: 620px; height: 109px;" /&gt;&lt;/P&gt;&lt;P&gt;I already register the&amp;nbsp; "esri.layers.FeatureLayer", &lt;SPAN style="line-height: 1.5;"&gt;and&amp;nbsp; &lt;/SPAN&gt;function(Map, FeatureLayer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but still getting this!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Oct 2015 02:16:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755747#M69876</guid>
      <dc:creator>BruceGreen</dc:creator>
      <dc:date>2015-10-24T02:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Having Issue on Adding/Removing Service Layer by Checkbox</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755748#M69877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Behrouz,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You say that you have registered "esri.layers.FeatureLayer". This leads me to believe that you are developing using the old legacy style and not AMD Legacy code. Legacy will not be supported any more when JS API 4.0 comes out and you should quit using Legacy style. It would help to see more of your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just looking at the snippets you provided you also have an issue with the service url.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have:&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14456563199415872 jive_macro_code jive_text_macro" data-renderedposition="197_8_912_16" jivemacro_uid="_14456563199415872"&gt;&lt;SPAN class="keyword"&gt;var service =&lt;SPAN class="string"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Frenewablestoolbox.biol.sfu.ca%2Frorapp%2Frest%2Fservices%2F" rel="nofollow" target="_blank"&gt;http://renewablestoolbox.biol.sfu.ca/rorapp/rest/services/&lt;/A&gt;&lt;SPAN style="color: #e23d39;"&gt;&lt;STRONG&gt;/&lt;/STRONG&gt;&lt;/SPAN&gt;RORApp/MapServer"&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;It should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14456563257564146 jive_text_macro" data-renderedposition="255_8_912_16" jivemacro_uid="_14456563257564146" modifiedtitle="true"&gt;&lt;SPAN class="keyword"&gt;var service =&lt;SPAN class="string"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Frenewablestoolbox.biol.sfu.ca%2Frorapp%2Frest%2Fservices%2FRORApp%2FMapServer%2F" rel="nofollow" target="_blank"&gt;http://renewablestoolbox.biol.sfu.ca/rorapp/rest/services/RORApp/MapServer/&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&lt;SPAN class="keyword"&gt;Notice double slash removed and a slash added to the end of the url since you are just adding the layer id to this string.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Oct 2015 03:14:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-issue-on-adding-removing-service-layer-by/m-p/755748#M69877</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2015-10-24T03:14:26Z</dc:date>
    </item>
  </channel>
</rss>

