<?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 an array of client-side features to StreamLayer in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/add-an-array-of-client-side-features-to/m-p/1269228#M6488</link>
    <description>&lt;P&gt;I'm using a widget to add a StreamLayer to a map.&lt;/P&gt;&lt;P&gt;If I add a StreamLayer from a StreamServer, everything works fine. E.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layer = new StreamLayer({
    url: 'https://geoeventsample1.esri.com:6443/arcgis/rest/services/LABus/StreamServer',
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If, however, I create &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-StreamLayer.html#constructors-summary" target="_blank" rel="noopener"&gt;an array of client-side features&lt;/A&gt; and use layer.&lt;SPAN&gt;sendMessageToClient({ type: "features", features: [ ... ]}) the features do not display on the map.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's a &lt;A href="https://codepen.io/markegge/pen/mdGjpQG" target="_blank" rel="noopener"&gt;CodePen of a working version&lt;/A&gt; (outside of Experience Builder).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's my widget.tsx:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, AllWidgetProps } from 'jimu-core'
import { JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'
import FeatureLayer from 'esri/layers/FeatureLayer'
import StreamLayer from 'esri/layers/StreamLayer'
const { useState } = React

const Widget = (props: AllWidgetProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const [jimuMapView, setJimuMapView] = useState&amp;lt;JimuMapView&amp;gt;()

  const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
    if (jmv) {
      setJimuMapView(jmv)
    }
  }

  // Create the StreamLayer
  const layer = new StreamLayer({
     fields: [
      {
        name: "OBJECTID",
        alias: "OBJECTID",
        type: "oid",
      },
      {
        name: "TRACKID",
        alias: "TrackId",
        type: "long",
      }
    ],
    timeInfo: {
      trackIdField: "TRACKID"
    },
    geometryType: "polygon", // required property
    spatialReference: {
      wkid: 102100
    },
    renderer: { 
      type: "simple",
      symbol: {
            type: "simple-fill",
            color: [233, 116, 81, 0.5],
      } 
    }
  })

  let objectIdCounter = 0

  const addLayer = () =&amp;gt; {

    // Add the layer to the map (accessed through the Experience Builder JimuMapView data source)
    jimuMapView.view.map.add(layer)
  }

  const addFeatures = () =&amp;gt; {

    layer.sendMessageToClient({
      type: "features",
      features: [
        {
          attributes: {
            TRACKID: 1,
            OBJECTID: objectIdCounter++
          },
          geometry: {
            rings: [[
                    [-12475988, 3965039], 
                    [-12476958, 3965047], 
                    [-12475991, 3966004], 
                    [-12475988, 3965039]
            ]]
          }
        },
        {
          attributes: {
            TRACKID: 2,
            OBJECTID: objectIdCounter++
          },
          geometry: {
            rings: [[
                   [-12475020, 3963094], 
                    [-12475019, 3964062], 
                    [-12474046, 3963093], 
                    [-12475020, 3963094]
            ]]
          }
        }
      ]
    })

  }

  return (
    &amp;lt;div className="widget-starter jimu-widget"&amp;gt;
      {
        props.useMapWidgetIds &amp;amp;&amp;amp;
        props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp; (
          &amp;lt;JimuMapViewComponent
            useMapWidgetId={props.useMapWidgetIds?.[0]}
            onActiveViewChange={activeViewChangeHandler}
          /&amp;gt;
        )
      }

      &amp;lt;button onClick={addLayer}&amp;gt;Add Layer&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={addFeatures}&amp;gt;Add Features&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default Widget&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is this a bug with the new array of client-side features for StreamLayers? (Alternatively, is there a better approach if I want to change the values in a DataSource using logic in the widget and then have the symbology on the map update accordingly?)&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Mar 2023 21:32:19 GMT</pubDate>
    <dc:creator>MarkEgge2</dc:creator>
    <dc:date>2023-03-18T21:32:19Z</dc:date>
    <item>
      <title>Add an array of client-side features to StreamLayer</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/add-an-array-of-client-side-features-to/m-p/1269228#M6488</link>
      <description>&lt;P&gt;I'm using a widget to add a StreamLayer to a map.&lt;/P&gt;&lt;P&gt;If I add a StreamLayer from a StreamServer, everything works fine. E.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layer = new StreamLayer({
    url: 'https://geoeventsample1.esri.com:6443/arcgis/rest/services/LABus/StreamServer',
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If, however, I create &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-StreamLayer.html#constructors-summary" target="_blank" rel="noopener"&gt;an array of client-side features&lt;/A&gt; and use layer.&lt;SPAN&gt;sendMessageToClient({ type: "features", features: [ ... ]}) the features do not display on the map.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's a &lt;A href="https://codepen.io/markegge/pen/mdGjpQG" target="_blank" rel="noopener"&gt;CodePen of a working version&lt;/A&gt; (outside of Experience Builder).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's my widget.tsx:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, AllWidgetProps } from 'jimu-core'
import { JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'
import FeatureLayer from 'esri/layers/FeatureLayer'
import StreamLayer from 'esri/layers/StreamLayer'
const { useState } = React

const Widget = (props: AllWidgetProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const [jimuMapView, setJimuMapView] = useState&amp;lt;JimuMapView&amp;gt;()

  const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
    if (jmv) {
      setJimuMapView(jmv)
    }
  }

  // Create the StreamLayer
  const layer = new StreamLayer({
     fields: [
      {
        name: "OBJECTID",
        alias: "OBJECTID",
        type: "oid",
      },
      {
        name: "TRACKID",
        alias: "TrackId",
        type: "long",
      }
    ],
    timeInfo: {
      trackIdField: "TRACKID"
    },
    geometryType: "polygon", // required property
    spatialReference: {
      wkid: 102100
    },
    renderer: { 
      type: "simple",
      symbol: {
            type: "simple-fill",
            color: [233, 116, 81, 0.5],
      } 
    }
  })

  let objectIdCounter = 0

  const addLayer = () =&amp;gt; {

    // Add the layer to the map (accessed through the Experience Builder JimuMapView data source)
    jimuMapView.view.map.add(layer)
  }

  const addFeatures = () =&amp;gt; {

    layer.sendMessageToClient({
      type: "features",
      features: [
        {
          attributes: {
            TRACKID: 1,
            OBJECTID: objectIdCounter++
          },
          geometry: {
            rings: [[
                    [-12475988, 3965039], 
                    [-12476958, 3965047], 
                    [-12475991, 3966004], 
                    [-12475988, 3965039]
            ]]
          }
        },
        {
          attributes: {
            TRACKID: 2,
            OBJECTID: objectIdCounter++
          },
          geometry: {
            rings: [[
                   [-12475020, 3963094], 
                    [-12475019, 3964062], 
                    [-12474046, 3963093], 
                    [-12475020, 3963094]
            ]]
          }
        }
      ]
    })

  }

  return (
    &amp;lt;div className="widget-starter jimu-widget"&amp;gt;
      {
        props.useMapWidgetIds &amp;amp;&amp;amp;
        props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp; (
          &amp;lt;JimuMapViewComponent
            useMapWidgetId={props.useMapWidgetIds?.[0]}
            onActiveViewChange={activeViewChangeHandler}
          /&amp;gt;
        )
      }

      &amp;lt;button onClick={addLayer}&amp;gt;Add Layer&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={addFeatures}&amp;gt;Add Features&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default Widget&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is this a bug with the new array of client-side features for StreamLayers? (Alternatively, is there a better approach if I want to change the values in a DataSource using logic in the widget and then have the symbology on the map update accordingly?)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 21:32:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/add-an-array-of-client-side-features-to/m-p/1269228#M6488</guid>
      <dc:creator>MarkEgge2</dc:creator>
      <dc:date>2023-03-18T21:32:19Z</dc:date>
    </item>
  </channel>
</rss>

