<?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: Read in a .txt file in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754245#M69747</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very interesting! So how does javascript write cookies to the local computer? As far as I know, cookies are written by javascript but stored on the local user to be retrieved and read later&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Aug 2017 15:32:51 GMT</pubDate>
    <dc:creator>GregSalvador</dc:creator>
    <dc:date>2017-08-10T15:32:51Z</dc:date>
    <item>
      <title>Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754240#M69742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basic question here, but how do I read in a .txt file and store it as an array? I am using javascript and arcgis' 4.4 API&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have several layers on a map that I want&amp;nbsp;"visible = true" on startup. Instead of hard coding the titles of the layers in a giant if() statement, I would like to read in the titles from a text file. I think&amp;nbsp;a simple array would be best to save the read in data.&amp;nbsp;Once read in, I will loop through the array and access the desired layerViews that way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I'm currently doing:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; (item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"City Limits"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; || item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"Land"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; ||&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"Parcels"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; || item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"Boundary"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; ||&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"Fill"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; || item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"Other Cities &amp;amp; Towns Boundaries"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; || item.title === &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"Other Cities &amp;amp; Towns Fills"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; item.visible = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;true&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;What I would Like to Do:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;for(i = &lt;SPAN style="color: red;"&gt;0&lt;/SPAN&gt;; i &amp;lt; dataArray.&lt;SPAN style="color: black;"&gt;length&lt;/SPAN&gt;; i++){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;if(item.title === dataArray&lt;I&gt;)&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;item.visible = true;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I have found reference material that mentions javascript's Node.js &lt;SPAN&gt;File System Module&lt;/SPAN&gt;, so if that could be incorporated into my main .js script I would be a happy camper.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Aug 2017 22:51:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754240#M69742</guid>
      <dc:creator>GregSalvador</dc:creator>
      <dc:date>2017-08-09T22:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754241#M69743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can add your layer names as an additional Javascript file to your app with all the layer names stored in a JSON object or array. &amp;nbsp;So in your HTML you add (in the header &amp;lt;head&amp;gt;):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;script src&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"showlayers.js"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;/&lt;/SPAN&gt;script&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the showlayers.js file content would be something like:&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; visibleItems &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;"City Limits"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;"Land"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;"Parcels"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&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="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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And when checking for the layers to make visible:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;i &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; i &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; myItems&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;length&lt;SPAN class="number token"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; i&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;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; item &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; myItems&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&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;if&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;visibleItems&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;indexOf&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;item&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;title&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&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; item&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;true&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&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="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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:00:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754241#M69743</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-12T08:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754242#M69744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this is the best solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should note that the node fs module doesn't exist in browser javascript.&amp;nbsp; Browser javascript can't directly interact with the local filesystem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:29:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754242#M69744</guid>
      <dc:creator>ThomasSolow</dc:creator>
      <dc:date>2017-08-10T13:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754243#M69745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much, this is exactly what I need! I've never had anyone reply to me on internet forums, this is very exciting lol&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:43:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754243#M69745</guid>
      <dc:creator>GregSalvador</dc:creator>
      <dc:date>2017-08-10T13:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754244#M69746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Welcome to the Geonet community!&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:47:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754244#M69746</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2017-08-10T13:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754245#M69747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very interesting! So how does javascript write cookies to the local computer? As far as I know, cookies are written by javascript but stored on the local user to be retrieved and read later&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2017 15:32:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754245#M69747</guid>
      <dc:creator>GregSalvador</dc:creator>
      <dc:date>2017-08-10T15:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Read in a .txt file</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754246#M69748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good question. &amp;nbsp;I don't know many of the details here but&amp;nbsp;the browser must have&amp;nbsp;access to the filesystem at some level. &amp;nbsp;For instance, modern browsers include a database called indexedDB, which ultimately sits&amp;nbsp;in the local filesystem (cookies, like you mentioned, and local storage must also sit in the local filesystem).&amp;nbsp;&amp;nbsp;You can write to and read from indexedDB from JavaScript, but the browser mediates this; there's no direct access from JavaScript to the filesystem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It does seem like it would be possible to write your list of items to indexedDB (or local storage, or a cookie) from inside the browser and subsequently pull the list from those sources (or write it out, if it doesn't exist). &amp;nbsp;On some level you are interacting with the local filesystem when you do this,&amp;nbsp;but not directly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to directly access files directly you have three options as far as I know:&amp;nbsp;files must be dragged and dropped into the browser using the drag and drop API, or selected by a user using the file input, or retrieved from an http server using an http request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My understanding is that node's fs module is just a nice JavaScript wrapper around your operating system's syscalls to read/write files, it doesn't actually represent a native JavaScript way to read/write files.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2017 15:56:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/read-in-a-txt-file/m-p/754246#M69748</guid>
      <dc:creator>ThomasSolow</dc:creator>
      <dc:date>2017-08-10T15:56:45Z</dc:date>
    </item>
  </channel>
</rss>

