<?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 Leaflet using a variable for addTo(map) in Open Source Mapping Libraries Ques.</title>
    <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834135#M355</link>
    <description>&lt;P&gt;OK, I have a simple cancer web map in Leaflet and I'm stumped on a problem.&lt;/P&gt;
&lt;P&gt;1. I have an HTML check box which when clicked turns on a layer. (Layer switcher is not an option) this basically calls a function and passes the cancer layer name. i.e.updateLayerVis("lung")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I have different types of cancer defined by name. i.e. var throat = new L.GeoJSON(data .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. So the function listed above passes the value 'lung' to 'a' below. It appears to be passing a dumb string called 'lung' while addTo is looking for a layer. Is it possible to use this string to add the appropriate layer to the map?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;function updateLayerVis(a){&lt;/P&gt;
&lt;P&gt;console.log(a); // lung&lt;/P&gt;
&lt;P&gt;a.value.addTo(map); // returns an error "a.addTo is not a function"&lt;/P&gt;
&lt;P&gt;a.addTo(map); // returns an error "a.addTo is not a function"&lt;/P&gt;
&lt;P&gt;lung.addTo(map); //works but with 15 check boxes, I'd need a large switch function.&lt;/P&gt;
&lt;P&gt;};&lt;/P&gt;</description>
    <pubDate>Mon, 28 Aug 2023 13:25:44 GMT</pubDate>
    <dc:creator>BillChappell</dc:creator>
    <dc:date>2023-08-28T13:25:44Z</dc:date>
    <item>
      <title>Leaflet using a variable for addTo(map)</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834135#M355</link>
      <description>&lt;P&gt;OK, I have a simple cancer web map in Leaflet and I'm stumped on a problem.&lt;/P&gt;
&lt;P&gt;1. I have an HTML check box which when clicked turns on a layer. (Layer switcher is not an option) this basically calls a function and passes the cancer layer name. i.e.updateLayerVis("lung")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I have different types of cancer defined by name. i.e. var throat = new L.GeoJSON(data .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. So the function listed above passes the value 'lung' to 'a' below. It appears to be passing a dumb string called 'lung' while addTo is looking for a layer. Is it possible to use this string to add the appropriate layer to the map?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;function updateLayerVis(a){&lt;/P&gt;
&lt;P&gt;console.log(a); // lung&lt;/P&gt;
&lt;P&gt;a.value.addTo(map); // returns an error "a.addTo is not a function"&lt;/P&gt;
&lt;P&gt;a.addTo(map); // returns an error "a.addTo is not a function"&lt;/P&gt;
&lt;P&gt;lung.addTo(map); //works but with 15 check boxes, I'd need a large switch function.&lt;/P&gt;
&lt;P&gt;};&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 13:25:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834135#M355</guid>
      <dc:creator>BillChappell</dc:creator>
      <dc:date>2023-08-28T13:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Leaflet using a variable for addTo(map)</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834136#M356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check out this stack overflow thread.&lt;/P&gt;&lt;P&gt;&lt;A class="link-bare" href="http://stackoverflow.com/questions/5613834/convert-string-to-variable-name-in-javascript" title="http://stackoverflow.com/questions/5613834/convert-string-to-variable-name-in-javascript"&gt;http://stackoverflow.com/questions/5613834/convert-string-to-variable-name-in-javascript&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Nov 2016 22:48:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834136#M356</guid>
      <dc:creator>JohnGravois</dc:creator>
      <dc:date>2016-11-28T22:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Leaflet using a variable for addTo(map)</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834137#M357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of creating a variable with the name of each data layer, rather create a list of layers with the layer name as an index e.g.&lt;/P&gt;&lt;P&gt;&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; maplayers &lt;SPAN class="operator 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;
maplayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"lung"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;L&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GeoJSON&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;data&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;
maplayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"throat"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;L&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GeoJSON&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;data&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Then when clicking on the checkbox you can use the string value to activate the indexed layer.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;function&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;updateLayerVis&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; maplayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;addTo&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;map&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:06:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834137#M357</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-12T10:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Leaflet using a variable for addTo(map)</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834138#M358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was going toward this route when I saw your answer. It was cleaner then mine so I tried it. I also tried mapLayers&lt;A&gt;.addTo(map); and this worked. &lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Nov 2016 14:56:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834138#M358</guid>
      <dc:creator>BillChappell</dc:creator>
      <dc:date>2016-11-29T14:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Leaflet using a variable for addTo(map)</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834139#M359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, applying the addTo function directly to the indexed layer item should also work. &amp;nbsp;It's just nice to have the item available as a short variable if you need to refer to it further down in the function again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2016 05:47:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-using-a-variable-for-addto-map/m-p/834139#M359</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2016-11-30T05:47:50Z</dc:date>
    </item>
  </channel>
</rss>

