<?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: problem with creating a point layer from csv in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1313278#M81813</link>
    <description>&lt;P&gt;If your goal is simply to display a CSV file specified from a file input, a much simpler process is possible that never even has to leave the client. You can see this in &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-shapefile" target="_self"&gt;the sandbox for the sample&lt;/A&gt; by replacing the contents of the script tag on line 37 with the following:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Expand",
        "esri/layers/CSVLayer"
      ], (Map, MapView, Expand, CSVLayer) =&amp;gt; {
        document
          .getElementById("uploadForm")
          .addEventListener("change", (event) =&amp;gt; {
            var reader = new FileReader();

            reader.addEventListener("load", function (evt) {
              var blob = new Blob([evt.target.result], {type:"text/plain"});
              var layer = new CSVLayer({url:URL.createObjectURL(blob)});

              map.add(layer);
              expand.collapse();
            });

            reader.readAsText(event.target.files[0]);
          });

        const map = new Map({
          basemap: "dark-gray-vector"
        });

        const view = new MapView({
          center: [-41.647, 36.41],
          zoom: 2,
          map: map,
          container: "viewDiv",
          popup: {
            defaultPopupTemplateEnabled: true
          }
        });

        const fileForm = document.getElementById("mainWindow");

        const expand = new Expand({
          expandIcon: "upload",
          view: view,
          content: fileForm
        });

        view.ui.add(expand, "top-right");
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It loads the sample CSV you provided just fine:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="csv.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76713i95CE56FB73AA499F/image-size/large?v=v2&amp;amp;px=999" role="button" title="csv.png" alt="csv.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2023 21:47:17 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2023-07-28T21:47:17Z</dc:date>
    <item>
      <title>problem with creating a point layer from csv</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1308790#M81711</link>
      <description>&lt;P&gt;I'm trying to create an add data widget with csv input.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;using the shapefile to feature Layer sample as a base.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-shapefile/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-shapefile/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;the sample uses generate, and for the publishing parameters Analyze.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Callers can use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/rest/users-groups-and-items/analyze.htm" target="_blank" rel="noopener"&gt;Analyze&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;operation to generate the default publishing parameters for the source input."&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/rest/users-groups-and-items/generate.htm" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/rest/users-groups-and-items/generate.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a 1 point csv for testing. -&amp;nbsp;attached&lt;/P&gt;&lt;P&gt;the analyze works, but i think I'm not using the generate properly because I'm getting "&lt;SPAN&gt;414 Request-URI Too Large error" on such a small table.&lt;BR /&gt;&lt;BR /&gt;I believe&amp;nbsp;the generate should return an object to automatically work with the addShapefileToMap.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en" &amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;title&amp;gt;CodePen - Create a FeatureLayer from a shapefile almost there&amp;lt;/title&amp;gt;
  

&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;!-- partial:index.partial.html --&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;title&amp;gt;
      Create a FeatureLayer from a shapefile | Sample | ArcGIS Maps SDK for
      JavaScript 4.27
    &amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
      #mainWindow {
        padding: .5em;
        background-color: #fff;
      }
      #mainWindow p, #uploadForm {
          display: block;
          padding: .1em;
        }
    &amp;lt;/style&amp;gt;

    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.27/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.27/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Expand",
        "esri/request",
        "esri/layers/FeatureLayer",
        "esri/layers/support/Field",
        "esri/Graphic"
      ], (
        esriConfig,
        Map,
        MapView,
        Expand,
        request,
        FeatureLayer,
        Field,
        Graphic
      ) =&amp;gt; {
        const portalUrl = "https://www.arcgis.com";

        document
          .getElementById("uploadForm")
          .addEventListener("change", (event) =&amp;gt; {
            const fileName = event.target.value.toLowerCase();

              generateFeatureCollection(fileName);

          });

        const map = new Map({
          basemap: "dark-gray-vector"
        });

        const view = new MapView({
          center: [-41.647, 36.41],
          zoom: 2,
          map: map,
          container: "viewDiv",
          popup: {
            defaultPopupTemplateEnabled: true
          }
        });

        const fileForm = document.getElementById("mainWindow");

        const expand = new Expand({
          expandIcon: "upload",
          view: view,
          content: fileForm
        });

        view.ui.add(expand, "top-right");

        function generateFeatureCollection(fileName) {
          let name = fileName.split(".");
          // Chrome adds c:\fakepath to the value - we need to remove it
          name = name[0].replace("c:\\fakepath\\", "");

          document.getElementById("upload-status").innerHTML =
            "&amp;lt;b&amp;gt;Loading &amp;lt;/b&amp;gt;" + name;

          // define the input params for generate see the rest doc for details
          // https://developers.arcgis.com/rest/users-groups-and-items/generate.htm
          const params = {
            name: name,
            targetSR: view.spatialReference,
            maxRecordCount: 1000,
            enforceInputFileSizeLimit: true,
            enforceOutputJsonSizeLimit: true
          };

          // generalize features to 10 meters for better performance
          params.generalize = true;
          params.maxAllowableOffset = 10;
          params.reducePrecision = true;
          params.numberOfDigitsAfterDecimal = 0;

          let myContent = {
            filetype: "csv",
            publishParameters: JSON.stringify(params),
            f: "json"
          };

          ////////////////////////////// analyze csv
          request(portalUrl + "/sharing/rest/content/features/analyze", {
            query: myContent,
            body: document.getElementById("uploadForm"),
            responseType: "json"
          })
            .then((response) =&amp;gt; { 
			
            console.log("analyze")            
            console.log(response);
			////////create new query for generate with response from analyze
			let myContent = {
            filetype: "csv",
            publishParameters: JSON.stringify(response.data.publishParameters),
            f: "json"
          };
		  
            /////////////////////////////////////generate 
            request(portalUrl + "/sharing/rest/content/features/generate", {
			//method:"post",
            query: myContent,
            body: response.data.records,
            responseType: "json"
          })
            .then((response) =&amp;gt; {
             console.log("generate")
             console.log(response);
              const layerName = response.data.publishParameters.name;
                //response.data.featureCollection.layers[0].layerDefinition.name;
                

              document.getElementById("upload-status").innerHTML =
                "&amp;lt;b&amp;gt;Loaded: &amp;lt;/b&amp;gt;" + layerName;
              addShapefileToMap(response.data);
            })
            .catch(errorHandler);
        })
            .catch(errorHandler);
        }
            
            
/////////////////////////////////////////////  all this inside then          


        function errorHandler(error) {
		console.log(error.message)
          document.getElementById("upload-status").innerHTML =
            "&amp;lt;p style='color:red;max-width: 500px;'&amp;gt;" + error.message + "&amp;lt;/p&amp;gt;";
        }

        function addShapefileToMap(featureCollection) {
          
          console.log("adding layer")
          // add the shapefile to the map and zoom to the feature collection extent
          // if you want to persist the feature collection when you reload browser, you could store the
          // collection in local storage by serializing the layer using featureLayer.toJson()
          // see the 'Feature Collection in Local Storage' sample for an example of how to work with local storage
          let sourceGraphics = [];

          const layers = featureCollection.layers.map((layer) =&amp;gt; {
            const graphics = layer.featureSet.features.map((feature) =&amp;gt; {
              return Graphic.fromJSON(feature);
            });
            sourceGraphics = sourceGraphics.concat(graphics);
            const featureLayer = new FeatureLayer({
              objectIdField: "FID",
              source: graphics,
              fields: layer.layerDefinition.fields.map((field) =&amp;gt; {
                return Field.fromJSON(field);
              })
            });
            return featureLayer;
            // associate the feature with the popup on click to enable highlight and zoom to
          });
          map.addMany(layers);
          view.goTo(sourceGraphics).catch((error) =&amp;gt; {
            if (error.name != "AbortError") {
              console.error(error);
            }
          });

          document.getElementById("upload-status").innerHTML = "";
        }
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;div id="mainWindow"&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div style="padding-left:4px;"&amp;gt;
          &amp;lt;p&amp;gt;
            Download shapefile from
            &amp;lt;a
              href="https://bsvensson.github.io/various-tests/shp/drp_county_boundary.zip"
              &amp;gt;here.&amp;lt;/a
            &amp;gt;
          &amp;lt;/p&amp;gt;
          &amp;lt;p&amp;gt;Add a zipped shapefile to the map.&amp;lt;/p&amp;gt;
          &amp;lt;p&amp;gt;
            Visit the
            &amp;lt;a
              target="_blank"
              href="https://doc.arcgis.com/en/arcgis-online/reference/shapefiles.htm"
              &amp;gt;Shapefiles&amp;lt;/a
            &amp;gt;
            help topic for information and limitations.
          &amp;lt;/p&amp;gt;
          &amp;lt;form enctype="multipart/form-data" method="post" id="uploadForm"&amp;gt;
            &amp;lt;div class="field"&amp;gt;
              &amp;lt;label class="file-upload"&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;strong&amp;gt;Add File&amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;
                &amp;lt;input type="file" name="file" id="inFile" /&amp;gt;
              &amp;lt;/label&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/form&amp;gt;
          &amp;lt;span
            class="file-upload-status"
            style="opacity:1;"
            id="upload-status"
          &amp;gt;&amp;lt;/span&amp;gt;
          &amp;lt;div id="fileInfo"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&amp;lt;!-- partial --&amp;gt;
  
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 20:12:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1308790#M81711</guid>
      <dc:creator>SvivaManager</dc:creator>
      <dc:date>2023-07-17T20:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: problem with creating a point layer from csv</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1309157#M81719</link>
      <description>&lt;P&gt;From looking at this you will need to use a shapefile rather than a csv. From running the application code we get an invalid file format error.&lt;/P&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 16:05:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1309157#M81719</guid>
      <dc:creator>David_McRitchie</dc:creator>
      <dc:date>2023-07-18T16:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: problem with creating a point layer from csv</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1309336#M81726</link>
      <description>&lt;P&gt;&lt;SPAN&gt;this is a dist file code , copy it as html file or paste the code on codepen - like the original sample its taken from.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I'm using&amp;nbsp;&lt;SPAN&gt;shapefile&amp;nbsp;sample for a quick start so the function name and title are from the source. the code itself is edited.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;shapefile no longer matters when you run this sample, its csv -&amp;gt;analyze response &amp;gt;generate - &lt;STRONG&gt;breaks&lt;/STRONG&gt; &amp;gt; add to map.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;use the csv I've&amp;nbsp;attached or create one, did it work? did you try something else?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;did the analyze return a response - it should ? did the generate? - it didn't&amp;nbsp;for me, i think the paraments&amp;nbsp;i used are wrongly implemented&amp;nbsp;.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 00:15:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1309336#M81726</guid>
      <dc:creator>SvivaManager</dc:creator>
      <dc:date>2023-07-19T00:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: problem with creating a point layer from csv</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1313278#M81813</link>
      <description>&lt;P&gt;If your goal is simply to display a CSV file specified from a file input, a much simpler process is possible that never even has to leave the client. You can see this in &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-shapefile" target="_self"&gt;the sandbox for the sample&lt;/A&gt; by replacing the contents of the script tag on line 37 with the following:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Expand",
        "esri/layers/CSVLayer"
      ], (Map, MapView, Expand, CSVLayer) =&amp;gt; {
        document
          .getElementById("uploadForm")
          .addEventListener("change", (event) =&amp;gt; {
            var reader = new FileReader();

            reader.addEventListener("load", function (evt) {
              var blob = new Blob([evt.target.result], {type:"text/plain"});
              var layer = new CSVLayer({url:URL.createObjectURL(blob)});

              map.add(layer);
              expand.collapse();
            });

            reader.readAsText(event.target.files[0]);
          });

        const map = new Map({
          basemap: "dark-gray-vector"
        });

        const view = new MapView({
          center: [-41.647, 36.41],
          zoom: 2,
          map: map,
          container: "viewDiv",
          popup: {
            defaultPopupTemplateEnabled: true
          }
        });

        const fileForm = document.getElementById("mainWindow");

        const expand = new Expand({
          expandIcon: "upload",
          view: view,
          content: fileForm
        });

        view.ui.add(expand, "top-right");
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It loads the sample CSV you provided just fine:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="csv.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76713i95CE56FB73AA499F/image-size/large?v=v2&amp;amp;px=999" role="button" title="csv.png" alt="csv.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 21:47:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/problem-with-creating-a-point-layer-from-csv/m-p/1313278#M81813</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-07-28T21:47:17Z</dc:date>
    </item>
  </channel>
</rss>

