<?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: Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24 in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1210222#M78609</link>
    <description>&lt;P&gt;Sir, I did some &lt;FONT color="#FF0000"&gt;cheating&lt;/FONT&gt; to join the API response, kindly let me know it is right or wrong !&amp;nbsp;&lt;/P&gt;&lt;P&gt;the API response array and feature layer attribute joined globally, and passed to the feature layer constructor&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var j1 = misTblDistrict.map((el)=&amp;gt;{return(el);});
var j2= features.map((fet)=&amp;gt;{return(fet.attributes);});

let joinedArray = j1.map((item, i) =&amp;gt; Object.assign({}, item, j2[i]));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;create the feature layer like this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var districtsFeatureLayer = new FeatureLayer({
          id: "districts",
          source: features.map((feature, index) =&amp;gt; {
            return {
              attributes: joinedArray[index],
              geometry: {
                type: "polygon",
                rings: feature.geometry.rings,
                spatialReference: new SpatialReference({
                  wkid: spatialReference.wkid,
                }),
              },
            };
          }),
          outFields: ["*"],
          objectIdField: "MalePopulation",
          geometryType: "polygon",
          spatialReference: new SpatialReference({
            wkid: spatialReference.wkid,
          }),
          renderer: districtRenderer7,
          popupTemplate:popupDistrict1,
        });&lt;/LI-CODE&gt;&lt;P&gt;for attribute property attribute: joinedArray[index]&amp;nbsp; &amp;nbsp;has been passed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately it joined and given me the result.&amp;nbsp; Is this way is right ?.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am also trying the way you have mentioned. It is taking some time for me to understand.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Wed, 07 Sep 2022 06:28:16 GMT</pubDate>
    <dc:creator>JayakumarPD</dc:creator>
    <dc:date>2022-09-07T06:28:16Z</dc:date>
    <item>
      <title>Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1207571#M78494</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using ESRI JavaScript API 4.24.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could able to render the JSON data to the map using the bellow code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would like to join the response data received from an API, which contain the unique value similar to the rendered json feature service.&lt;/P&gt;&lt;P data-unlink="true"&gt;Note: I don't have this option -&amp;nbsp;Dynamic data layers&amp;nbsp;&lt;SPAN&gt;on the fly from data inside registered workspaces.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The api response is like this. I have to join the api response and render the map based on the MalePopulation/FemalePopulatin/TotalPopulation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const misTblDistrict =[
                {
                    KGISDistrictCode: "01",
                    KGISDistrictName: "Belagavi",
                    MalePopulation: 233336,
                    FemalePopulation: 57438,
                    TotalPopulation: 290774
                },
                {
                    KGISDistrictCode: "02",
                    KGISDistrictName: "Bagalkot",
                    MalePopulation: 549540,
                    FemalePopulation: 844171,
                    TotalPopulation: 1393711
                },
                {
                    KGISDistrictCode: "03",
                    KGISDistrictName: "Vijayapura",
                    MalePopulation: 202111,
                    FemalePopulation: 177079,
                    TotalPopulation: 379190
                },
                {
                    KGISDistrictCode: "04",
                    KGISDistrictName: "Kalburgi",
                    MalePopulation: 222823,
                    FemalePopulation: 234340,
                    TotalPopulation: 457163
                },
                {
                    KGISDistrictCode: "05",
                    KGISDistrictName: "Bidar",
                    MalePopulation: 385580,
                    FemalePopulation: 73176,
                    TotalPopulation: 458756
                },

            ];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the running code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; 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 Map and add a dynamic layer&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet"
          href="https://js.arcgis.com/4.24/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script&amp;gt;
        // dojoConfig has to be configured before including the esri js library
        var locationPath = location.pathname.replace(/\/[^\/]+$/, "");
        var dojoConfig = {
            async: true,
            //baseUrl: "/js",
            //locale: location.search.substring(1) === "" ? "en-us" : location.search.substring(1),
            packages: [
                {
                    name: "ksrsac",
                    location: locationPath + "/js/data",
                },
            ],
            parseOnLoad: false,
        };
    &amp;lt;/script&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.24/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src="https://code.jquery.com/jquery-3.6.0.min.js"
            integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
            crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;style&amp;gt;
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script&amp;gt;
        
        require(["esri/config",
            "esri/Map",
            "esri/views/MapView",
            "esri/layers/FeatureLayer",
            "esri/geometry/Polygon",
            "esri/geometry/SpatialReference",
            "dojo/parser",
            "esri/renderers/SimpleRenderer",
            "dojo/text!ksrsac/district.json"], function (
                esriConfig,
                Map,
                MapView,
                FeatureLayer,
                Polygon,
                SpatialReference,
                parser,
                SimpleRenderer,
                district
            ) {
            parser.parse();
            
            const map = new Map({
                basemap: "streets-vector"
            });
            const view = new MapView({
                map: map,
                center: [76.00, 15.00],
                zoom: 6,
                container: "viewDiv"
            });
            var districts = JSON.parse(district);
        
            const {features, fields, geometryType, spatialReference} = districts;
            var districtsFeatureLayer = new FeatureLayer({
                id: "districts",
                source: features.map((feature) =&amp;gt; {
                    return {
                        attributes: feature.attributes,
                        geometry: {
                            type: 'polygon',
                            rings: feature.geometry.rings,
                            spatialReference: new SpatialReference({ wkid: spatialReference.wkid })
                        }
                    };
                }), 
                outFields: ["*"],
                objectIdField: "OBJECTID",
                geometryType: "polygon",
                spatialReference: new SpatialReference({ wkid: spatialReference.wkid }),
            });
          map.add(districtsFeatureLayer);           
        });
    &amp;lt;/script&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;Json data is enclosed for reference.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 06:47:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1207571#M78494</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2022-08-30T06:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1208167#M78525</link>
      <description>&lt;P&gt;If you want to join external data to data from a FeatureLayer, it's going to require a few steps.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new client-side FeatureLayer with the fields from source FL and external data, and matching geometry to source FeatureLayer&lt;/LI&gt;&lt;LI&gt;Query all the features from your source FeatureLayer. This could be troublesome if you have a large amount of data, so you might need to paginate your requests.&lt;/LI&gt;&lt;LI&gt;Iterate over your features and add new attributes to your features based on a common field.&lt;/LI&gt;&lt;LI&gt;Use FeatureLayer applyEdits to add these features to your client-side FeatureLayer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I wrote a blog post very similar to this workflow, but doing a spatial join based on geometry. In your case it would be based on a common field and matching value.&lt;/P&gt;&lt;P&gt;&lt;A href="https://odoe.net/blog/spatial-joins" target="_blank" rel="noopener"&gt;https://odoe.net/blog/spatial-joins&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Also, if you find that the join is slow due to the amount of data you have and it blocks interaction with your page, you could consider using a custom worker. We have a sample, using the spatial join with a worker, on github.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/jsapi-resources/tree/master/esm-samples/jsapi-custom-workers" target="_blank" rel="noopener"&gt;https://github.com/Esri/jsapi-resources/tree/master/esm-samples/jsapi-custom-workers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 14:26:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1208167#M78525</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-08-31T14:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1208609#M78546</link>
      <description>&lt;P&gt;Sir,&lt;/P&gt;&lt;P&gt;Thank you for the flow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;&lt;SPAN&gt;Create a new client-side FeatureLayer with the fields from source FL : I have created and similar&amp;nbsp;way create for the external data also&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Query all the features from your source FeatureLayer : I will do this, feature polygon count is max-235. trouble with slowness&amp;nbsp;will not be there.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. I&lt;/SPAN&gt;terate over your features and add new attributes to your features based on a common field: this I have not done, I will do.&lt;/P&gt;&lt;P&gt;4. Use FeatureLayer applyEdits to add these features to your client-side FeatureLayer : this I have not done, I i will give it a try.&amp;nbsp;&lt;/P&gt;&lt;P&gt;By this process, I think, I will get a new feature layer with joined external data, so I can apply the renderer.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Once again thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 09:46:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1208609#M78546</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2022-09-01T09:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1210222#M78609</link>
      <description>&lt;P&gt;Sir, I did some &lt;FONT color="#FF0000"&gt;cheating&lt;/FONT&gt; to join the API response, kindly let me know it is right or wrong !&amp;nbsp;&lt;/P&gt;&lt;P&gt;the API response array and feature layer attribute joined globally, and passed to the feature layer constructor&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var j1 = misTblDistrict.map((el)=&amp;gt;{return(el);});
var j2= features.map((fet)=&amp;gt;{return(fet.attributes);});

let joinedArray = j1.map((item, i) =&amp;gt; Object.assign({}, item, j2[i]));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;create the feature layer like this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var districtsFeatureLayer = new FeatureLayer({
          id: "districts",
          source: features.map((feature, index) =&amp;gt; {
            return {
              attributes: joinedArray[index],
              geometry: {
                type: "polygon",
                rings: feature.geometry.rings,
                spatialReference: new SpatialReference({
                  wkid: spatialReference.wkid,
                }),
              },
            };
          }),
          outFields: ["*"],
          objectIdField: "MalePopulation",
          geometryType: "polygon",
          spatialReference: new SpatialReference({
            wkid: spatialReference.wkid,
          }),
          renderer: districtRenderer7,
          popupTemplate:popupDistrict1,
        });&lt;/LI-CODE&gt;&lt;P&gt;for attribute property attribute: joinedArray[index]&amp;nbsp; &amp;nbsp;has been passed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately it joined and given me the result.&amp;nbsp; Is this way is right ?.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am also trying the way you have mentioned. It is taking some time for me to understand.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 06:28:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1210222#M78609</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2022-09-07T06:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1297858#M81336</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7384"&gt;@ReneRubalcava&lt;/a&gt;, I am trying to create a feature layer with the help of join 2 data source, one is map-layer and other is data from JSON, but my map is not rendering because the field i have in JSON is not present in fields of feature layer. can you please help me out in this situation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 04:25:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1297858#M81336</guid>
      <dc:creator>ChetanKargeti</dc:creator>
      <dc:date>2023-06-11T04:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Joining API response json data to FeatureLayer created by Jsonfile using esri js api 4.24</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1307866#M81678</link>
      <description>&lt;P&gt;Kindly provide the code.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2023 10:36:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/joining-api-response-json-data-to-featurelayer/m-p/1307866#M81678</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2023-07-13T10:36:44Z</dc:date>
    </item>
  </channel>
</rss>

