<?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 Add and Remove KML Layer Repeatedly in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520821#M48550</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to make a layer list with checkboxes to turn on/off layers (TOC).&lt;/P&gt;&lt;P&gt;My layer list need to support KML layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I make a very simple example to add and remove kml layer using the online example&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/jssamples/layers_kml.html" title="https://developers.arcgis.com/javascript/jssamples/layers_kml.html"&gt;https://developers.arcgis.com/javascript/jssamples/layers_kml.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I realise only the initial adding and removing of layer works.&lt;/P&gt;&lt;P&gt;The 2nd time I add the kml layer, it will not be rendered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To make things easy, I created a jsfiddle @ &lt;A href="https://jsfiddle.net/L5pyvezt/1/" title="https://jsfiddle.net/L5pyvezt/1/"&gt;https://jsfiddle.net/L5pyvezt/1/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In this fiddle, there are 2 buttons on top.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you click on add, realise that an orange box will be rendered&lt;/P&gt;&lt;P&gt;When you click on remove, the orange box will be removed&lt;/P&gt;&lt;P&gt;When you click on add again, it is expected that the orange box will be re-rendered but alas, it did not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(&lt;STRONG&gt;Warning&lt;/STRONG&gt;: do not add, remove, add, remove too many time, for some unknown reason, although the codes are so minimal, it will crash your browser)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have any advice to this strange behavior?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some extra information:&lt;/P&gt;&lt;P&gt;1) The same code works for feature layer&lt;/P&gt;&lt;P&gt;2) Calling kmllayer.refresh() works&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 26 Dec 2015 08:29:00 GMT</pubDate>
    <dc:creator>BryanSng</dc:creator>
    <dc:date>2015-12-26T08:29:00Z</dc:date>
    <item>
      <title>Add and Remove KML Layer Repeatedly</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520821#M48550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to make a layer list with checkboxes to turn on/off layers (TOC).&lt;/P&gt;&lt;P&gt;My layer list need to support KML layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I make a very simple example to add and remove kml layer using the online example&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/jssamples/layers_kml.html" title="https://developers.arcgis.com/javascript/jssamples/layers_kml.html"&gt;https://developers.arcgis.com/javascript/jssamples/layers_kml.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I realise only the initial adding and removing of layer works.&lt;/P&gt;&lt;P&gt;The 2nd time I add the kml layer, it will not be rendered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To make things easy, I created a jsfiddle @ &lt;A href="https://jsfiddle.net/L5pyvezt/1/" title="https://jsfiddle.net/L5pyvezt/1/"&gt;https://jsfiddle.net/L5pyvezt/1/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In this fiddle, there are 2 buttons on top.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you click on add, realise that an orange box will be rendered&lt;/P&gt;&lt;P&gt;When you click on remove, the orange box will be removed&lt;/P&gt;&lt;P&gt;When you click on add again, it is expected that the orange box will be re-rendered but alas, it did not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(&lt;STRONG&gt;Warning&lt;/STRONG&gt;: do not add, remove, add, remove too many time, for some unknown reason, although the codes are so minimal, it will crash your browser)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have any advice to this strange behavior?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some extra information:&lt;/P&gt;&lt;P&gt;1) The same code works for feature layer&lt;/P&gt;&lt;P&gt;2) Calling kmllayer.refresh() works&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Dec 2015 08:29:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520821#M48550</guid>
      <dc:creator>BryanSng</dc:creator>
      <dc:date>2015-12-26T08:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Remove KML Layer Repeatedly</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520822#M48551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bryan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Here is your code re-worked and working:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
&amp;nbsp; &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt;
&amp;nbsp; &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"&amp;gt;
&amp;nbsp; &amp;lt;meta name="apple-mobile-web-app-capable" content="yes"&amp;gt;
&amp;nbsp; &amp;lt;meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"&amp;gt;
&amp;nbsp; &amp;lt;meta name="mobile-web-app-capable" content="yes"&amp;gt;
&amp;nbsp; &amp;lt;title&amp;gt;ArcGIS dynamic and tile layers using Popup and InfoTemplates&amp;lt;/title&amp;gt;
&lt;SPAN&gt;&amp;nbsp; &amp;lt;link rel="stylesheet" href="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fjs.arcgis.com%2F3.15%2Fesri%2Fcss%2Fesri.css" target="_blank"&gt;https://js.arcgis.com/3.15/esri/css/esri.css&lt;/A&gt;&lt;SPAN&gt;"&amp;gt;&lt;/SPAN&gt;
&amp;nbsp; &amp;lt;style&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; html,
&amp;nbsp;&amp;nbsp;&amp;nbsp; body {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height: 100%;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width: 100%;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; margin: 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; padding: 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; #map {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height: 100%;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; margin: 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; padding: 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; &amp;lt;/style&amp;gt;
&lt;SPAN&gt;&amp;nbsp; &amp;lt;script src="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fjs.arcgis.com%2F3.15%2F" target="_blank"&gt;https://js.arcgis.com/3.15/&lt;/A&gt;&lt;SPAN&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;/SPAN&gt;
&amp;nbsp; &amp;lt;script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var map;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var kml;

&amp;nbsp;&amp;nbsp;&amp;nbsp; require([
&amp;nbsp;&amp;nbsp;&amp;nbsp; "esri/map",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "esri/layers/KMLLayer",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "dojo/parser",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "dojo/on",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "dijit/layout/ContentPane",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "dojo/domReady!"
&amp;nbsp; ], function (
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; KMLLayer,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parser,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on
&amp;nbsp;&amp;nbsp;&amp;nbsp; ) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = new Map("map", {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basemap: "topo"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parser.parse();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on(dojo.byId("addBtn"), "click", kmladd);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on(dojo.byId("removeBtn"), "click", kmlremove);
&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var kmlUrl = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fdl.dropboxusercontent.com%2Fu%2F2654618%2Fkml%2FWyoming.kml" target="_blank"&gt;https://dl.dropboxusercontent.com/u/2654618/kml/Wyoming.kml&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function kmladd() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kml = new KMLLayer(kmlUrl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayer(kml);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log('added');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function kmlremove() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.removeLayer(kml);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kml = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log('removed');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp; &amp;lt;/script&amp;gt;

&amp;nbsp; &amp;lt;body class="tundra"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;button id="addBtn"&amp;gt;add&amp;lt;/button&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;button id="removeBtn"&amp;gt;remove&amp;lt;/button&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;lt;/body&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;/html&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:43:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520822#M48551</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2021-12-11T22:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Remove KML Layer Repeatedly</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520823#M48552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Robert, super thanks for the rework solution!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hmm while it is working, however I'm working on a component that will create and store the layer instance instead of creating each time the layer is shown. This mean new KMLLayer(...) will only be executed once during startup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried modifying the rework solution such that new KMLLayer(...) is executed only once but alas the problem returns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there anyway I can get a KMLLayer to be created only once and used in subsequent add / remove operations? FeatureLayer does work great though (no such problem).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To make things simple, I updated the fiddle, thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://jsfiddle.net/L5pyvezt/2" style="line-height: 1.5;" title="https://jsfiddle.net/L5pyvezt/2"&gt;https://jsfiddle.net/L5pyvezt/2&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Dec 2015 10:09:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520823#M48552</guid>
      <dc:creator>BryanSng</dc:creator>
      <dc:date>2015-12-28T10:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Remove KML Layer Repeatedly</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520824#M48553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bryan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; No you can not reuse a KMLLayer once it has been removed from the map. For some reason the layer becomes inoperable once removed and needs to recreated. That was the reason I had it that way in my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use &lt;A href="https://developers.arcgis.com/javascript/jsapi/kmllayer-amd.html#suspend" title="https://developers.arcgis.com/javascript/jsapi/kmllayer-amd.html#suspend"&gt;KMLLayer | API Reference | ArcGIS API for JavaScript | suspend&lt;/A&gt;​ if you want to stop the layer from drawing on the map if setting the visibility to false is not good enough. Otherwise you will need to re-create the layer each time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Dec 2015 13:00:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520824#M48553</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2015-12-28T13:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Remove KML Layer Repeatedly</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520825#M48554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm ok, I guess I had to rework the component then, but thanks, that's good information to know kmllayer has this limitation&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Dec 2015 14:10:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520825#M48554</guid>
      <dc:creator>BryanSng</dc:creator>
      <dc:date>2015-12-28T14:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Remove KML Layer Repeatedly</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520826#M48555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another thing you might want to try is parsing the KML inside of your JavaScript code to create a feature layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will get you from KML to GeoJSON: &lt;A href="https://github.com/mapbox/togeojson" title="https://github.com/mapbox/togeojson"&gt;mapbox/togeojson · GitHub&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;From there, you can use &lt;A href="http://terraformer.io/"&gt;Terraformer&lt;/A&gt; to get from GeoJSON to ArcGIS format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Dec 2015 18:46:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-and-remove-kml-layer-repeatedly/m-p/520826#M48555</guid>
      <dc:creator>JeffJacobson</dc:creator>
      <dc:date>2015-12-28T18:46:03Z</dc:date>
    </item>
  </channel>
</rss>

