<?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: Access layer features and data in Experience Builder Widget Development in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1346791#M9227</link>
    <description>&lt;P&gt;Thanks for the feedback, appreciate it, however I'm still struggling to grasp scope and get your example plugged into my code.&lt;BR /&gt;Below is my widget.tsx which may not be written pretty but works for my testing.&lt;BR /&gt;In my custom widget when the button is pressed the selected map view extent is sent to an api server which returns GeoJSON that gets added to the map and the featuretable.&lt;BR /&gt;2 days now and I still can't fathom how to capture in the widget when the new layer is selected in the map that I can get the selected features data and show it in the lineDetailsTab.&lt;BR /&gt;I've tried plugging in your code but scope is proving confusing to me as I don't know where to get the featurelayerview from and the view.toMap scope is wrong as it always return undefined!!&lt;BR /&gt;&lt;BR /&gt;I have also being trying to get this approach integrated:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/arcgis-experience-builder-questions/get-selected-features-in-custom-widget/td-p/1049525" target="_blank"&gt;Solved: Get Selected Features in Custom Widget - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;but I don't understand how to capture the datasource dynamically, as my geojson data source doesn't exist until the widget is run.&lt;BR /&gt;So 2 different directions being worked on but maybe I'm just grasping things wrong, when I add new geojson data to the mapview I want my widget to pick up when a feature is selected from that layer so could really do with another pointer on which approach is best to take?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, FormattedMessage, defaultMessages as jimuCoreDefaultMessage, type AllWidgetProps, css, jsx, styled } from 'jimu-core';
import { type IMConfig } from '../config';
import { Tabs, Tab, Button } from 'jimu-ui';
import { loadArcGISJSAPIModules, type JimuMapView, JimuMapViewComponent } from 'jimu-arcgis';
import * as projection from "@arcgis/core/geometry/projection.js";
import SpatialReference from "@arcgis/core/geometry/SpatialReference.js";
import esriRequest from "@arcgis/core/request.js";
import FeatureTable from "@arcgis/core/widgets/FeatureTable.js";
import LayerView from "@arcgis/core/views/layers/LayerView.js";
import defaultMessages from './translations/default';

interface IState {
	bbox: string
	latitude: string
	longitude: string
	scale: number
	zoom: number
	mapViewReady: boolean
	featureServiceUrlInput: string
	jimuMapView: JimuMapView
	linesLayer: geojson
}
projection.load();

export default class Widget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;IMConfig&amp;gt;, IState&amp;gt; {
	GeoJSONLayer: typeof __esri.GeoJSONLayer
	SpatialReference: typeof __esri.SpatialReference
	state = {
		bbox: '',
		latitude: '',
		longitude: '',
		zoom: 0,
		scale: 0,
		mapViewReady: false,
		featureServiceUrlInput: '',
		jimuMapView: null,
		linesLayer: null
	}
	
	activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
		if (jmv){
			this.setState({
				jimuMapView: jmv
			})
			/* When the extent moves, update the state with all the updated values.*/
			jmv.view.watch('extent', evt =&amp;gt; {
				const cs1 = new SpatialReference({
					wkid: 4326 //WGS_84
				});
				/* EXTENT/BBOX conversion to Geometry Polygon:
					BBOX(xMin,yMin,xMax,yMax)
					POLYGON((xMin yMin,xMin yMax,xMax yMax,xMax yMin,xMin yMin))
				*/
				const extentClone = jmv.view.extent.clone();
				const newExtent = projection.project(extentClone, cs1);
				//console.log(JSON.stringify(newExtent.toJSON()));
				const mapBBOX = "POLYGON((" + newExtent.xmin.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "," + newExtent.xmin.toFixed(4) + " " + newExtent.ymax.toFixed(4) + "," + newExtent.xmax.toFixed(4) + " " + newExtent.ymax.toFixed(4) + "," + newExtent.xmax.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "," + newExtent.xmin.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "))";
				this.setState({
					bbox: mapBBOX,
					latitude: jmv.view.center.latitude.toFixed(3),
					longitude: jmv.view.center.longitude.toFixed(3),
					scale: Math.round(jmv.view.scale * 1) / 1,
					zoom: jmv.view.zoom,
					mapViewReady: true
				})
			})
		 }
	}
	
	onLineListClick = (jmv: JimuMapView) =&amp;gt; {
		const linePopupTemplate = {
			title: "Line details",
			content:[{
				type: "fields",
				fieldInfos:[
					{fieldName: "date_time", label: "Date:"},
					{fieldName: "title", label: "Title:"},
					{fieldName: "length", label: "Distance:"},
					{fieldName: "user_name", label: "Owner:"},
					{fieldName: "description", label: "Details:"},
				]
			}]
		}
		const requestURL = "https://api.example.com/route/api/"
		// Lazy-loading (only load if/when needed) the ArcGIS API for JavaScript modules
		// that we need - only once the "Get Lines" button is pressed.
		loadArcGISJSAPIModules([
			'esri/layers/GeoJSONLayer',
			'esri/geometry/SpatialReference'
		]).then((modules) =&amp;gt; {
			[this.GeoJSONLayer, this.SpatialReference] = modules;
			if(this.state.linesLayer === null){
				const layer = new this.GeoJSONLayer({
					url: requestURL,
					customParameters: {
						auth: this.props.config.apiToken,
						request: this.state.bbox,
						type: 'geometry'
					},
					title: "API Lines",
					renderer: {
					  type: "simple",
					  symbol: {
						  type: "simple-line",
						  width: 2,
						  color: "blue"
					  }
					},
					popupTemplate: linePopupTemplate
				});
				this.state.jimuMapView.view.map.add(layer);
				this.setState({tracksLayer: layer}, () =&amp;gt; {
					//console.log("In Set state.");
					//console.log(this.state);
				});
				// After the layer is created, create the feature table in the UI
				layer.on('layerview-create', (event) =&amp;gt; {					
					// Create the feature table
					const featureTable = new FeatureTable({
						view: this.state.jimuMapView.view, // Required for feature highlight to work
						layer: layer,
						visibleElements: {
							// Autocast to VisibleElements
							menuItems: {
								clearSelection: true,
								refreshData: false,
								toggleColumns: true,
								selectedRecordsShowAllToggle: true,
								selectedRecordsShowSelectedToggle: true,
								zoomToSelection: true
							}
						},
						tableTemplate: {
							// Autocast to TableTemplate
							columnTemplates: [
								// Takes an array of FieldColumnTemplate and GroupColumnTemplate
								{
									// Autocast to FieldColumnTemplate.
									type: "field",
									fieldName: "title",
									label: "Title",
									direction: "asc"
								},
								{
									type: "field",
									fieldName: "date_time",
									label: "Date"
								},
								{
									type: "field",
									fieldName: "description",
									label: "Description"
								}
							]
						},
						container: document.getElementById("lineList")
					});
				})
			}else{
				this.state.tracksLayer.customParameters.request = this.state.bbox;
				this.state.tracksLayer.refresh();
			}
		})
	}		
	
	render () {
		const StyledButton = styled.button`
			color: white;
			background-color: #1074B2;
			transition: 0.15s ease-in all;
			&amp;amp;:hover {
				background-color: #579EC8;
			}
		`
		return &amp;lt;div className="widget-demo jimu-widget" style={{ overflow: 'auto' }}&amp;gt;
			&amp;lt;Tabs&amp;gt;
				&amp;lt;Tab id="listTab" title="tab1"&amp;gt;
					&amp;lt;StyledButton onClick={this.onLineListClick}&amp;gt;Get Linework&amp;lt;/StyledButton&amp;gt;
						{this.props.hasOwnProperty('useMapWidgetIds') &amp;amp;&amp;amp; this.props.useMapWidgetIds &amp;amp;&amp;amp; this.props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp;
						(&amp;lt;JimuMapViewComponent useMapWidgetId={this.props.useMapWidgetIds?.[0]}	onActiveViewChange={this.activeViewChangeHandler}/&amp;gt;)
						}
					&amp;lt;div id="lineList" style={{ width: '100%', height: '600px', overflow: 'hidden' }}&amp;gt;
						{this.props.intl.formatMessage({ id: '_widgetLabel', defaultMessage: defaultMessages._widgetLabel })}
					&amp;lt;/div&amp;gt;
				&amp;lt;/Tab&amp;gt;
				&amp;lt;Tab id="lineDetailsTab" title="tab2"&amp;gt;					
					&amp;lt;div id="lineDetailsContainer" style={{ width: '100%', height: '600px', overflow: 'hidden' }}&amp;gt;
						{lineDetails}
					&amp;lt;/div&amp;gt;
				&amp;lt;/Tab&amp;gt;
			&amp;lt;/Tabs&amp;gt;
		&amp;lt;/div&amp;gt;
	}
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 07 Nov 2023 17:34:45 GMT</pubDate>
    <dc:creator>diplonics</dc:creator>
    <dc:date>2023-11-07T17:34:45Z</dc:date>
    <item>
      <title>Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1345095#M9133</link>
      <description>&lt;DIV&gt;Long background in Openlayers but taking on the Experience Builder Widget development challenge and so far okay. However can't fathom how to access a layers data after its added to the map. Could someone point me to a tutorial or resource on what I thought I could easily where I want to generate a UI element containing some of the layer attribute data after it loads. So I need to get the data and loop through it. I can get the data fine and display it on the map but can't seem to access it through the layer, view or layerView objects.&lt;DIV&gt;&amp;nbsp;&lt;DIV&gt;Code currently using to get the data is as follows:&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layer = new this.GeoJSONLayer({
	url: requestURL,
	customParameters: {
		request: this.state.bbox,
	},
	title: "New data",
	renderer: {
		type: "simple",
		symbol: {
			type: "simple-line",
			width: 2,
			Color: "blue"
		}
	}
});
JimuMapView.view.map.add(layer);
// After the layer is created try to build UI element from layer data.
layer.on('layerview-create', (event) =&amp;gt; {
	try{
		const results = event.layerView.queryFeatures();
		const graphics = results.features;
		console.log(graphics);				//Just returns null
	}catch (error){
		console.error("query failed: ", error);
	}
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 17:01:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1345095#M9133</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-02T17:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1345149#M9137</link>
      <description>&lt;P&gt;There are two issues with your query.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You need to define your query so it knows what you are looking for.&lt;/LI&gt;&lt;LI&gt;You need to create a .then() statement, so that Javascript will wait for the query to run before moving on to the next lines of code.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Something like this example block.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on("pointer-move", function(event){
  let query = featureLayer.createQuery();
  query.geometry = view.toMap(event);  // the point location of the pointer
  query.distance = 2;
  query.units = "miles";
  query.spatialRelationship = "intersects";  // this is the default
  query.returnGeometry = true;
  query.outFields = [ "POPULATION" ];

  featureLayerView.queryFeatures(query)
    .then(function(response){
      // returns a feature set with features containing the
      // POPULATION attribute and each feature's geometry
    });
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-GeoJSONLayerView.html#queryFeatures" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-GeoJSONLayerView.html#queryFeatures&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 18:05:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1345149#M9137</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-11-02T18:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1346791#M9227</link>
      <description>&lt;P&gt;Thanks for the feedback, appreciate it, however I'm still struggling to grasp scope and get your example plugged into my code.&lt;BR /&gt;Below is my widget.tsx which may not be written pretty but works for my testing.&lt;BR /&gt;In my custom widget when the button is pressed the selected map view extent is sent to an api server which returns GeoJSON that gets added to the map and the featuretable.&lt;BR /&gt;2 days now and I still can't fathom how to capture in the widget when the new layer is selected in the map that I can get the selected features data and show it in the lineDetailsTab.&lt;BR /&gt;I've tried plugging in your code but scope is proving confusing to me as I don't know where to get the featurelayerview from and the view.toMap scope is wrong as it always return undefined!!&lt;BR /&gt;&lt;BR /&gt;I have also being trying to get this approach integrated:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/arcgis-experience-builder-questions/get-selected-features-in-custom-widget/td-p/1049525" target="_blank"&gt;Solved: Get Selected Features in Custom Widget - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;but I don't understand how to capture the datasource dynamically, as my geojson data source doesn't exist until the widget is run.&lt;BR /&gt;So 2 different directions being worked on but maybe I'm just grasping things wrong, when I add new geojson data to the mapview I want my widget to pick up when a feature is selected from that layer so could really do with another pointer on which approach is best to take?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, FormattedMessage, defaultMessages as jimuCoreDefaultMessage, type AllWidgetProps, css, jsx, styled } from 'jimu-core';
import { type IMConfig } from '../config';
import { Tabs, Tab, Button } from 'jimu-ui';
import { loadArcGISJSAPIModules, type JimuMapView, JimuMapViewComponent } from 'jimu-arcgis';
import * as projection from "@arcgis/core/geometry/projection.js";
import SpatialReference from "@arcgis/core/geometry/SpatialReference.js";
import esriRequest from "@arcgis/core/request.js";
import FeatureTable from "@arcgis/core/widgets/FeatureTable.js";
import LayerView from "@arcgis/core/views/layers/LayerView.js";
import defaultMessages from './translations/default';

interface IState {
	bbox: string
	latitude: string
	longitude: string
	scale: number
	zoom: number
	mapViewReady: boolean
	featureServiceUrlInput: string
	jimuMapView: JimuMapView
	linesLayer: geojson
}
projection.load();

export default class Widget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;IMConfig&amp;gt;, IState&amp;gt; {
	GeoJSONLayer: typeof __esri.GeoJSONLayer
	SpatialReference: typeof __esri.SpatialReference
	state = {
		bbox: '',
		latitude: '',
		longitude: '',
		zoom: 0,
		scale: 0,
		mapViewReady: false,
		featureServiceUrlInput: '',
		jimuMapView: null,
		linesLayer: null
	}
	
	activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
		if (jmv){
			this.setState({
				jimuMapView: jmv
			})
			/* When the extent moves, update the state with all the updated values.*/
			jmv.view.watch('extent', evt =&amp;gt; {
				const cs1 = new SpatialReference({
					wkid: 4326 //WGS_84
				});
				/* EXTENT/BBOX conversion to Geometry Polygon:
					BBOX(xMin,yMin,xMax,yMax)
					POLYGON((xMin yMin,xMin yMax,xMax yMax,xMax yMin,xMin yMin))
				*/
				const extentClone = jmv.view.extent.clone();
				const newExtent = projection.project(extentClone, cs1);
				//console.log(JSON.stringify(newExtent.toJSON()));
				const mapBBOX = "POLYGON((" + newExtent.xmin.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "," + newExtent.xmin.toFixed(4) + " " + newExtent.ymax.toFixed(4) + "," + newExtent.xmax.toFixed(4) + " " + newExtent.ymax.toFixed(4) + "," + newExtent.xmax.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "," + newExtent.xmin.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "))";
				this.setState({
					bbox: mapBBOX,
					latitude: jmv.view.center.latitude.toFixed(3),
					longitude: jmv.view.center.longitude.toFixed(3),
					scale: Math.round(jmv.view.scale * 1) / 1,
					zoom: jmv.view.zoom,
					mapViewReady: true
				})
			})
		 }
	}
	
	onLineListClick = (jmv: JimuMapView) =&amp;gt; {
		const linePopupTemplate = {
			title: "Line details",
			content:[{
				type: "fields",
				fieldInfos:[
					{fieldName: "date_time", label: "Date:"},
					{fieldName: "title", label: "Title:"},
					{fieldName: "length", label: "Distance:"},
					{fieldName: "user_name", label: "Owner:"},
					{fieldName: "description", label: "Details:"},
				]
			}]
		}
		const requestURL = "https://api.example.com/route/api/"
		// Lazy-loading (only load if/when needed) the ArcGIS API for JavaScript modules
		// that we need - only once the "Get Lines" button is pressed.
		loadArcGISJSAPIModules([
			'esri/layers/GeoJSONLayer',
			'esri/geometry/SpatialReference'
		]).then((modules) =&amp;gt; {
			[this.GeoJSONLayer, this.SpatialReference] = modules;
			if(this.state.linesLayer === null){
				const layer = new this.GeoJSONLayer({
					url: requestURL,
					customParameters: {
						auth: this.props.config.apiToken,
						request: this.state.bbox,
						type: 'geometry'
					},
					title: "API Lines",
					renderer: {
					  type: "simple",
					  symbol: {
						  type: "simple-line",
						  width: 2,
						  color: "blue"
					  }
					},
					popupTemplate: linePopupTemplate
				});
				this.state.jimuMapView.view.map.add(layer);
				this.setState({tracksLayer: layer}, () =&amp;gt; {
					//console.log("In Set state.");
					//console.log(this.state);
				});
				// After the layer is created, create the feature table in the UI
				layer.on('layerview-create', (event) =&amp;gt; {					
					// Create the feature table
					const featureTable = new FeatureTable({
						view: this.state.jimuMapView.view, // Required for feature highlight to work
						layer: layer,
						visibleElements: {
							// Autocast to VisibleElements
							menuItems: {
								clearSelection: true,
								refreshData: false,
								toggleColumns: true,
								selectedRecordsShowAllToggle: true,
								selectedRecordsShowSelectedToggle: true,
								zoomToSelection: true
							}
						},
						tableTemplate: {
							// Autocast to TableTemplate
							columnTemplates: [
								// Takes an array of FieldColumnTemplate and GroupColumnTemplate
								{
									// Autocast to FieldColumnTemplate.
									type: "field",
									fieldName: "title",
									label: "Title",
									direction: "asc"
								},
								{
									type: "field",
									fieldName: "date_time",
									label: "Date"
								},
								{
									type: "field",
									fieldName: "description",
									label: "Description"
								}
							]
						},
						container: document.getElementById("lineList")
					});
				})
			}else{
				this.state.tracksLayer.customParameters.request = this.state.bbox;
				this.state.tracksLayer.refresh();
			}
		})
	}		
	
	render () {
		const StyledButton = styled.button`
			color: white;
			background-color: #1074B2;
			transition: 0.15s ease-in all;
			&amp;amp;:hover {
				background-color: #579EC8;
			}
		`
		return &amp;lt;div className="widget-demo jimu-widget" style={{ overflow: 'auto' }}&amp;gt;
			&amp;lt;Tabs&amp;gt;
				&amp;lt;Tab id="listTab" title="tab1"&amp;gt;
					&amp;lt;StyledButton onClick={this.onLineListClick}&amp;gt;Get Linework&amp;lt;/StyledButton&amp;gt;
						{this.props.hasOwnProperty('useMapWidgetIds') &amp;amp;&amp;amp; this.props.useMapWidgetIds &amp;amp;&amp;amp; this.props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp;
						(&amp;lt;JimuMapViewComponent useMapWidgetId={this.props.useMapWidgetIds?.[0]}	onActiveViewChange={this.activeViewChangeHandler}/&amp;gt;)
						}
					&amp;lt;div id="lineList" style={{ width: '100%', height: '600px', overflow: 'hidden' }}&amp;gt;
						{this.props.intl.formatMessage({ id: '_widgetLabel', defaultMessage: defaultMessages._widgetLabel })}
					&amp;lt;/div&amp;gt;
				&amp;lt;/Tab&amp;gt;
				&amp;lt;Tab id="lineDetailsTab" title="tab2"&amp;gt;					
					&amp;lt;div id="lineDetailsContainer" style={{ width: '100%', height: '600px', overflow: 'hidden' }}&amp;gt;
						{lineDetails}
					&amp;lt;/div&amp;gt;
				&amp;lt;/Tab&amp;gt;
			&amp;lt;/Tabs&amp;gt;
		&amp;lt;/div&amp;gt;
	}
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Nov 2023 17:34:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1346791#M9227</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-07T17:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1346837#M9230</link>
      <description>&lt;P&gt;I don't think this current code is salvageable. It is time to start over. I could follow your code much better and this whole process should be easier if you could rewrite it in function based React.&lt;/P&gt;&lt;P&gt;So if I understand your goal, you want the user to click a button. Then the current map extents would be captured and sent to an API which would send back a GeoJSON of data that you would then add to your map.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know how to do all of that, but I am willing to try to help you through it.&lt;/P&gt;&lt;P&gt;Could you instead load the GeoJSON layer first maybe even include it in your webmap and then query the data in your extent area? This will likely be a much simpler task.&lt;/P&gt;&lt;P&gt;I think you are making this more complicated than it needs to be. Here is what a add/remove layer widget looks like in function based React. Maybe you can use it as a base for your widget.&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'

const { useState } = React

const Widget = (props: AllWidgetProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const [jimuMapView, setJimuMapView] = useState&amp;lt;JimuMapView&amp;gt;()
  const item = new FeatureLayer({
      url: 'URL1'
    })
  const [layer

  const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
    if (jmv) {
      setJimuMapView(jmv)
    }
  }

  const formSubmit = (evt) =&amp;gt; {
    evt.preventDefault()
    jimuMapView.view.map.add(layer)
  }
  
const formSubmit3 = (evt) =&amp;gt; {
    evt.preventDefault()

    jimuMapView.view.map.remove(layer)
  }
  
  
  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;form onSubmit={formSubmit}&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;button&amp;gt;Add Layer&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/form&amp;gt;
	   &amp;lt;form onSubmit={formSubmit3}&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;button&amp;gt;Delete&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/form&amp;gt; 
	  
    &amp;lt;/div&amp;gt;
  )
}

export default Widget&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Nov 2023 18:47:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1346837#M9230</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-11-07T18:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347090#M9247</link>
      <description>&lt;P&gt;Thanks again here for your input, helpful pointers and offer. Agree the current code is a mess but generally learning my way into stuff is messy but once I grasp the structures it all gets cleaned up. So yep, your example of functional react is much nicer and helpful as a first step, so I'll revisit my code and build to this style today.&lt;/P&gt;&lt;P&gt;"So if I understand your goal, you want the user to click a button. Then the current map extents would be captured and sent to an API which would send back a GeoJSON of data that you would then add to your map." Yes, currently the above code does this fine, I just can't get an on-map click event to report back to the widget what line feature was clicked on.&lt;/P&gt;&lt;P&gt;However,I think your point on the bigger picture of my data flow is very relevant too, so maybe a solution on pre-defining the data source in the widget settings would work better. Maybe the API data source gets added, in the background, as the widget loads and doesn't have to wait on the button click. The button click just views the data and filters it based on extent as in requirements below.&lt;/P&gt;&lt;P&gt;At the minute I only require the user to set a 'Select Map Widget' onto which my widget should draw/interact.&lt;/P&gt;&lt;P&gt;General requirements though are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The layer shouldn't load/view unless the user turns it on.&lt;/LI&gt;&lt;LI&gt;It should only load data (lines) relevant to the map extents.&lt;/LI&gt;&lt;LI&gt;It is GeoJson data coming from an external API.&lt;/LI&gt;&lt;LI&gt;If the layer is loaded and a feature selected it should load into my widget the details of the feature selected but only for my geojson data not for any other layer a user might have setup or added.&lt;/LI&gt;&lt;LI&gt;If a user has built an EB dashboard with a standard set of widgets, that link and filter other data sources, then, that should all work as EB currently does. If my widget is included it does not need to interact in this way. Its use-case is to load a specific data source for a specific extent and hold that view regardless of what the rest of the dashboard interaction does. So if a user pans the map my widget will not reload or change its data dynamics, unless the user clicks the button to reload to the new extent.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Hopefully this helpful but as I say I'll rewrite functionally, post and see what you think.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 12:48:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347090#M9247</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-08T12:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347095#M9248</link>
      <description>&lt;P&gt;If the only piece you are missing is finding what the user clicked on, the mapView.hitTest() method will return a list of all the graphics at a single point.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Something like this example should do what you are looking for.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get screenpoint from view's click event
view.on("click", function(event){
  // Search for all features only on included layers at the clicked location
  view.hitTest(event, {include: featureLayer}).then(function(response){
    // if features are returned from the featureLayer, do something with results
    if (response.results.length){
       // do something
       console.log(response.results.length, "features returned");
    }
  })
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 13:17:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347095#M9248</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-11-08T13:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347673#M9304</link>
      <description>&lt;P&gt;Okay, still working on rewriting code to the functional pattern and get working what had been, quite close but not quite there...&lt;BR /&gt;The functional pattern is much clearer for me to grasp so thanks for the template.&lt;BR /&gt;Anyway couple of specific issues around scope again, below changes/additions to your template are working for my purposes currently but I'm having to set the bbox state to var instead of const to use the updated bbox outside the extent watch event.&lt;BR /&gt;var is not recommended I read but can't seem to find the correct pattern to update it and follow recommended forms...&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const [	jimuMapView, setJimuMapView ] = useState&amp;lt;JimuMapView&amp;gt;();
var [ bbox, setBBOX ] = useState('');

const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
	if (jmv) {
		setJimuMapView(jmv)
		/* When the extent moves, update the state with all the updated values.*/
		jmv.view.watch('extent', evt =&amp;gt; {
			const cs1 = new SpatialReference({
				wkid: 4326 //WGS_84
			});
			/* EXTENT/BBOX conversion to Geometry Polygon:
				BBOX(xMin,yMin,xMax,yMax)
				POLYGON((xMin yMin,xMin yMax,xMax yMax,xMax yMin,xMin yMin))
			*/
			const extentClone = jmv.view.extent.clone();
			const newExtent = projection.project(extentClone, cs1);
			const mapBBOX = "POLYGON((" + newExtent.xmin.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "," + newExtent.xmin.toFixed(4) + " " + newExtent.ymax.toFixed(4) + "," + newExtent.xmax.toFixed(4) + " " + newExtent.ymax.toFixed(4) + "," + newExtent.xmax.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "," + newExtent.xmin.toFixed(4) + " " + newExtent.ymin.toFixed(4) + "))";
			setBBOX(mapBBOX);
		})
	}
}&lt;/LI-CODE&gt;&lt;P&gt;Other bit is as follows where the add layer functions work fine but I get a new layer for every button click where the extent has been change, scope again maybe but when I apply a layer refresh it doesn't refresh.&lt;BR /&gt;You should see below I'm trying to remove and re-add the layer but not quite working either and figure that's just a hack anyway..&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var [ lineLayerAdded, setLineLayerAdded ] = useState(false);
const formSubmit = (evt) =&amp;gt; {
	evt.preventDefault();
	//If layer has already been added to map then just refresh it.
	if(lineLayerAdded){
		console.log("In layer refresh");
		//Now update layer parames and get new data
		layer.customParameters.request = bbox;
		//This is not refreshing
		layer.refresh();
		
                //Other approach here was to try and remove
                //then re-add layer.
                //So trying to add layer again after new bbox request.
		//New layer works but now have 2+ layers now!!
		jimuMapView.view.map.remove(layer);
		jimuMapView.view.map.add(layer);
	}else{
		console.log("In layer add");
		jimuMapView.view.map.add(layer);
		setLineLayerAdded(true);
	}
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Nov 2023 13:50:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347673#M9304</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-09T13:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347687#M9306</link>
      <description>&lt;P&gt;So, that add/remove layer widget is code from a introduction to React I was writing. I was making a point in that section that if the reference to layer is not stored in state it will become lost on re-render. I think that is exactly why your layer will not delete.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/experience-builder-tips-and-tricks/react-for-experience-builder-developer-edition/ba-p/1346222" target="_blank"&gt;https://community.esri.com/t5/experience-builder-tips-and-tricks/react-for-experience-builder-developer-edition/ba-p/1346222&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 14:11:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347687#M9306</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-11-09T14:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347720#M9309</link>
      <description>&lt;P&gt;Ahh, lots in that article to pour over and once probably won't do it for me either&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&lt;BR /&gt;Anyway, got it working as I want but some changes as I originally thought&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const [layer&lt;/LI-CODE&gt;&lt;P&gt;was a typo, but trying to add it in is giving me an error on using the Widget in EB.&lt;BR /&gt;Seems something is trying to close off the brace and not sure where you are adding in the 'item' featureLayer to that structure.&lt;/P&gt;&lt;P&gt;***********************&lt;/P&gt;&lt;P&gt;Load module error. Error: Module parse failed: Identifier 'layer' has already been declared (60:11)&lt;BR /&gt;File was processed with these loaders:&lt;BR /&gt;* ./node_modules/ts-loader/index.js&lt;BR /&gt;* ./node_modules/thread-loader/dist/cjs.js&lt;BR /&gt;* ./webpack/update-webpack-public-path-loader.js&lt;BR /&gt;You may need an additional loader to handle the result of these loaders.&lt;BR /&gt;| popupTemplate: videoPopupTemplate&lt;BR /&gt;| });&lt;BR /&gt;&amp;gt; const [layer];&lt;BR /&gt;| const activeViewChangeHandler = (jmv) =&amp;gt; {&lt;BR /&gt;| if (jmv) {&lt;BR /&gt;**************************&lt;BR /&gt;&lt;BR /&gt;So I adapted to the other approach I was using and the following is working fine now to add layer on first click, then only update/refresh layer with new data on an extent change and subsequent new click.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const [layer, setLayer ] = useState&amp;lt;GeoJSONLayer&amp;gt;();
const lineLayer = new GeoJSONLayer({
	url: requestURL,
	customParameters: {
		request: bbox
	},
	title: "API Lines",
	renderer: {
		type: "simple",
		symbol: {
			type: "simple-line",
			width: 2,
			color: "blue"
		}
	},
	popupTemplate: linePopupTemplate
});
const formSubmit = (evt) =&amp;gt; {
	evt.preventDefault();
	//If layer has already been added to map then just refresh it.
	if(lineLayerAdded){
		//Now get new data
		layer.customParameters.request = bbox;
		layer.refresh();
	}else{
		jimuMapView.view.map.add(lineLayer);
		setLineLayerAdded(true);
		setLayer(lineLayer);
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 15:12:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347720#M9309</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-09T15:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347728#M9310</link>
      <description>&lt;P&gt;Just added in your get feature clicked example and it works perfect, so lots of struggling to grasp react sorted so thank you &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/677423"&gt;@JeffreyThompson2&lt;/a&gt;. Onto the next bit, sort through clicked features returned and build some UI elements from it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;jmv.view.on("click", function(event){
	// Search for all features only on included layers at the clicked location
	jmv.view.hitTest(event, {include: layer}).then(function(response){
		// if features are returned from the featureLayer, do something with results
		if (response.results.length){
			// do something
			console.log(response.results.length, "features returned");
		}
	})
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 15:44:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347728#M9310</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-09T15:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347729#M9311</link>
      <description>&lt;P&gt;Yes, that const [layer line was an error. It has been corrected in the React guide. The correct line there was.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const [layer, setLayer] = useState(item)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Nov 2023 15:23:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1347729#M9311</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-11-09T15:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1350304#M9415</link>
      <description>&lt;P&gt;Coming back to this after a week with loads of progress, got a great Widget built that does what we want...except...I can't preview it because of a load error which probably means I'll not be able to publish it as well.&lt;/P&gt;&lt;P&gt;So I took the code back to basics and am using your base example from here and same error shows up:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/experience-builder-tips-and-tricks/react-for-experience-builder-developer-edition/ba-p/1346222" target="_blank"&gt;https://community.esri.com/t5/experience-builder-tips-and-tricks/react-for-experience-builder-developer-edition/ba-p/1346222&lt;/A&gt;&lt;BR /&gt;In the Developer/Draft UI your code works fine (as does my widget) but once I try and preview it, which opens in a new tab, both widgets 'fail to load'.&lt;/P&gt;&lt;P&gt;Could you check if you are getting the same issue?&lt;/P&gt;&lt;P&gt;The featurelayer URL I'm using with your example code is:&lt;BR /&gt;'&lt;A href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0" target="_blank"&gt;http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0&lt;/A&gt;'&lt;BR /&gt;The dev-console error stack is this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="diplonics_0-1700152457133.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/86220i8D897C00CC7065A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="diplonics_0-1700152457133.png" alt="diplonics_0-1700152457133.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 16:35:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1350304#M9415</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-16T16:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1350318#M9416</link>
      <description>&lt;P&gt;&lt;A href="https://developers.arcgis.com/experience-builder/guide/add-layers-to-a-map/#change-the-widget-name" target="_blank"&gt;https://developers.arcgis.com/experience-builder/guide/add-layers-to-a-map/#change-the-widget-name&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Based on the error, I am guessing that you did not include jimu-arcgis in your dependencies in manifest.json as shown in the link.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 16:49:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1350318#M9416</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-11-16T16:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1350822#M9436</link>
      <description>&lt;P&gt;Yep, that fixed it, thanks again for your input and help on all bits, its appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 15:00:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1350822#M9436</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-17T15:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1381124#M10827</link>
      <description>&lt;P&gt;Just back working on this project and stuck on how to highlight a map feature in the GeoJson layer that has been added to the map as detailed in earlier post.&lt;BR /&gt;So, in code I have access to both the 'JimuMapView.view.map' and the 'layer' but what I need to do is when a feature is clicked in a table in my widget i need to highlight it in the map.&lt;BR /&gt;Each feature has a feature_id attribute that's unique and I can access from the table in my custom widget so I should be able to loop through the layers feature in the mapView and highlight it but what I've tried so far isn't working.&lt;BR /&gt;I'm currently trying this approach:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311211#M145" target="_blank"&gt;https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311211#M145&lt;/A&gt;&lt;BR /&gt;but can't figure it out?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 16:32:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1381124#M10827</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2024-02-12T16:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1381172#M10830</link>
      <description>&lt;P&gt;That link is from a separate API, so the methods are going to be different. You should query the layer and then use the .highlight() method.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-GeoJSONLayerView.html#highlight" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-GeoJSONLayerView.html#highlight&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 17:35:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1381172#M10830</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-02-12T17:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1384050#M10945</link>
      <description>&lt;P&gt;Hopefully another easy fix can be applied to help me again learn and raise my inexperienced React codebase skills!!!&lt;BR /&gt;I'm getting following error:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Load module error. Error: Module parse failed: The keyword 'yield' is reserved (86:28)&lt;BR /&gt;File was processed with these loaders:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Issue is I'm trying to recode various bits to fully understand scope etc., basically do things properly.&lt;/P&gt;&lt;P&gt;So I managed to use your suggestion of the .highlight() method which was a big help, thank you as per usual. However, I put it together as a hack that seemed to work but I'm certainly not sensibly implementing it as the layerView scope doesn't exist in numerous contexts.&lt;/P&gt;&lt;P&gt;Sample code below shows the that the error kicks in because of the await request line 17.&lt;/P&gt;&lt;P&gt;If I comment it out and use line 16 instead then things run fine for the table click situation to highlighting the map feature, however layerView is still null in lots of other contexts so I obviously have something scope wise badly wrong!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layer = new this.GeoJSONLayer({
	url: requestURL,
	customParameters: {
		request: this.state.bbox,
	},
	title: "New data",
	renderer: {
		type: "simple",
		symbol: {
			type: "simple-line",
			width: 2,
			Color: "blue"
		}
	}
});
JimuMapView.view.map.add(layer);
//var layerView = null;   //THIS WORKS
const layerView = await jimuMapView.view.whenLayerView(layer);   //THIS DOES NOT WORK
// After the layer is created try to build UI element from layer data.
layer.on('layerview-create', (event) =&amp;gt; {
	try{
		const results = event.layerView.queryFeatures();
		const graphics = results.features;
		console.log(graphics);				//Just returns null
	}catch (error){
		console.error("query failed: ", error);
	}
})
jimuMapView.view.whenLayerView(layer).then(function(layerView){console.log(layerView);});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:19:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1384050#M10945</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2024-02-19T16:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1384325#M10958</link>
      <description>&lt;P&gt;I'm not sure what you are trying to accomplish, so here is some general information you may find helpful.&lt;/P&gt;&lt;P&gt;The await keyword can only be used inside a function declared with the async keyword.&lt;/P&gt;&lt;P&gt;The layer and the layerView are not the same thing. Roughly speaking, the layer is the data and the layerView is how the data is displayed. In most cases, you should run queries on the layer, rather than the layerView.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 14:05:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1384325#M10958</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-02-20T14:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1387301#M11091</link>
      <description>&lt;P&gt;Thanks again and eventually worked it out to get what I need working. Into code exception handling now and stuck on the case where no GeoJSON features are returned. Is there an example of catching/handling errors you can point to.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layer = new this.GeoJSONLayer({
	url: requestURL,
	customParameters: {
		request: this.state.bbox,
	},
	title: "New data",
	renderer: {
		type: "simple",
		symbol: {
			type: "simple-line",
			width: 2,
			Color: "blue"
		}
	}
});

JimuMapView.view.map.add(layer);

//Following code is actioned by a button click event to make a new GeoJson query and load it into the layer:
//bbox changes based on the mapview extents.
layer.customParameters.request = bbox;
layer.refresh();
const query = layer.createQuery();
query.where = "1=1";
layer.queryFeatures(query)
	.then(function(response){
		if(response.features.length &amp;gt; 0){
			console.log("The GeoJSON API has sent NEW data, Update Map &amp;amp; Widget UI!");
		}else{
			console.log("The GeoJSON API has sent NO data, Clear Map &amp;amp; reset widget UI!");
		}				
	}).catch(function(e){console.log(e);});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an image of the console errors. When the widget first loads there is no GeoJson data. If the load data button is clicked a layer refresh occurs and is fine as long as features are returned, if none are returned then these errors occur and further updates to the layer fail. Is there a correct way to handle exception cases where a query that returns no features just clears the map and shows a message of 'no data top load'.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-02-27 110521.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/95944i5AB58F4EA51B1E89/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-02-27 110521.png" alt="Screenshot 2024-02-27 110521.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 11:12:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1387301#M11091</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2024-02-27T11:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Access layer features and data in Experience Builder Widget Development</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1387357#M11094</link>
      <description>&lt;P&gt;If I understand your problem, you have code that functions and does additional analysis if the API returns data, but errors out if there is no data, and you want to know how to handle a no data senario. Practically, the best option would be to inform the user that there is no data to work with and allow them to start over. There are several ways to accomplish this (if/else, try/catch, or moving part of your code down the React tree), but they are all fundamentally just different ways to make an if statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 14:14:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-layer-features-and-data-in-experience/m-p/1387357#M11094</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-02-27T14:14:31Z</dc:date>
    </item>
  </channel>
</rss>

