<?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: Using dojo.disconnect in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180566#M16731</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should use &lt;A href="https://dojotoolkit.org/reference-guide/1.10/dojo/on.html"&gt;dojo/on&lt;/A&gt; for your event handling. From the &lt;A href="https://developers.arcgis.com/javascript/3/jshelp/inside_events.html"&gt;Events&lt;/A&gt; section in the documentation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Using the &lt;CODE&gt;on&lt;/CODE&gt; method is preferable to using &lt;CODE&gt;connect&lt;/CODE&gt; for several reasons. First, the Dojo documentation states that &lt;CODE&gt;connect&lt;/CODE&gt; support will be removed in Dojo 2.0, and in fact, &lt;CODE&gt;connect&lt;/CODE&gt; is now a legacy convenience wrapper for &lt;CODE&gt;dojo.on&lt;/CODE&gt;. Secondly, especially in AMD style, it makes your code less verbose and is more similar to event attachment syntax in other JavaScript frameworks. Finally, for &lt;CODE&gt;esri&lt;/CODE&gt; components we add a &lt;CODE&gt;target&lt;/CODE&gt; property to all "synthetic" events (not mouse or key events) which points to the component which fired the event.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"dojo/on" contains the function "&lt;A href="https://dojotoolkit.org/reference-guide/1.10/dojo/on.html#once"&gt;once&lt;/A&gt;", which can be set so the event only happens once and is removed afterward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading your question again, are you expecting disconnect to remove the layer? If so, you'll have to do that with the &lt;A href="https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#removelayer"&gt;removeLayer&lt;/A&gt; method. Disconnect just removes the event handler (meaning if you click on the button again, it won't fire the function to add the map layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Aug 2016 15:51:29 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2016-08-15T15:51:29Z</dc:date>
    <item>
      <title>Using dojo.disconnect</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180565#M16730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How can I use dojo.disconnect to remove a map layer I've added. My code doesn't seem to work, it adds the map layer fine but I can't remove it? Any help would be good:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;script&amp;gt;&lt;/P&gt;&lt;P&gt;var node = dojo.byId("switch1");&lt;BR /&gt; var eventHandle = dojo.connect(node, "onclick", function addMapLayer1(e) {&lt;BR /&gt;&lt;SPAN&gt; var soils1 = new ArcGISDynamicMapServiceLayer("&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fmap%2Farcgisserver%2Fmapserver" rel="nofollow" target="_blank"&gt;https://map/arcgisserver/mapserver&lt;/A&gt;&lt;SPAN&gt;", {&lt;/SPAN&gt;&lt;BR /&gt; opacity: 1,&lt;BR /&gt; "visible": true&lt;BR /&gt; });&lt;BR /&gt; &lt;BR /&gt; dojo.disconnect(eventHandle);&lt;BR /&gt; soils1.setVisibleLayers([1]);&lt;BR /&gt; map.addLayer(soils1);&lt;/P&gt;&lt;P&gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;html&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;div class="switch tiny" style=" float:right;padding-top:0px;"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;input class="switch-input" id="switch1" type="checkbox" name="exampleSwitch"&amp;gt;&lt;BR /&gt; &amp;lt;label class="switch-paddle" for="switch1"&amp;gt;&lt;BR /&gt; &amp;lt;span class="switch-active" aria-hidden="true"&amp;gt;On&amp;lt;/span&amp;gt;&lt;BR /&gt; &amp;lt;span class="switch-inactive" aria-hidden="true"&amp;gt;Off&amp;lt;/span&amp;gt;&lt;BR /&gt; &amp;lt;/label&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &amp;lt;/div&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/html&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2016 15:41:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180565#M16730</guid>
      <dc:creator>OliviaGill1</dc:creator>
      <dc:date>2016-08-15T15:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using dojo.disconnect</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180566#M16731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should use &lt;A href="https://dojotoolkit.org/reference-guide/1.10/dojo/on.html"&gt;dojo/on&lt;/A&gt; for your event handling. From the &lt;A href="https://developers.arcgis.com/javascript/3/jshelp/inside_events.html"&gt;Events&lt;/A&gt; section in the documentation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Using the &lt;CODE&gt;on&lt;/CODE&gt; method is preferable to using &lt;CODE&gt;connect&lt;/CODE&gt; for several reasons. First, the Dojo documentation states that &lt;CODE&gt;connect&lt;/CODE&gt; support will be removed in Dojo 2.0, and in fact, &lt;CODE&gt;connect&lt;/CODE&gt; is now a legacy convenience wrapper for &lt;CODE&gt;dojo.on&lt;/CODE&gt;. Secondly, especially in AMD style, it makes your code less verbose and is more similar to event attachment syntax in other JavaScript frameworks. Finally, for &lt;CODE&gt;esri&lt;/CODE&gt; components we add a &lt;CODE&gt;target&lt;/CODE&gt; property to all "synthetic" events (not mouse or key events) which points to the component which fired the event.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"dojo/on" contains the function "&lt;A href="https://dojotoolkit.org/reference-guide/1.10/dojo/on.html#once"&gt;once&lt;/A&gt;", which can be set so the event only happens once and is removed afterward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading your question again, are you expecting disconnect to remove the layer? If so, you'll have to do that with the &lt;A href="https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#removelayer"&gt;removeLayer&lt;/A&gt; method. Disconnect just removes the event handler (meaning if you click on the button again, it won't fire the function to add the map layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2016 15:51:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180566#M16731</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2016-08-15T15:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using dojo.disconnect</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180567#M16732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ken - thank you for the response, it's helped alot. I think my problem is the fact I'm using the same 'switch' to add the map as I am to remove it. Other than adding a different switch for each event I'm guessing I should add an if clause ie. if the map layer is 'on' and the switch is clicked again then removeLayer...&lt;/P&gt;&lt;P&gt;Olivia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 09:10:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180567#M16732</guid>
      <dc:creator>OliviaGill1</dc:creator>
      <dc:date>2016-08-16T09:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using dojo.disconnect</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180568#M16733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would use a boolean variable to "manage"&amp;nbsp;the visibility of the layer and just toggle the boolean value each time the button is clicked. &amp;nbsp;Then based on the boolean value set the visibility of the layer within the onclick function.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; layerIsOn &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;false&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; eventHandle &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; dojo&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;connect&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;node&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"onclick"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;function&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;addMapLayer1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;e&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; layerIsOn &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;!&lt;/SPAN&gt;layerIsOn&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layerIsOn&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;// switch layer on&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;// switch layer off&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:13:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/using-dojo-disconnect/m-p/180568#M16733</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-11T09:13:37Z</dc:date>
    </item>
  </channel>
</rss>

