<?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 bespoke Widget click events in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353262#M9547</link>
    <description>&lt;P&gt;Below is relevant code, hopefully its enough as I think the logic it defines is whats got me.&lt;/P&gt;&lt;P&gt;Definitely react naive issue as not my standard framework as you'll see by the 'cheating' using jQuery to manage div updates!!!&lt;/P&gt;&lt;P&gt;Happy to rework all if pointers/advice possible so thanks for help so far!!&lt;/P&gt;&lt;P&gt;layer in below code is a geoJsonLayer of polylines added at the start of the code.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
	if (jmv) {
		setJimuMapView(jmv);
		/*************MAP CLICK - START****************
		 * When the map is clicked get map coodinates.
		 */
		jmv.view.on("click", tracksLayerClickHandler);

		function tracksLayerClickHandler(event){
			//only include graphics from Tracks Layer
			const opts = {
				include: layer
			};
			jmv.view.hitTest(event, opts).then(tracksLayerFeatureHandler);
		};

		function tracksLayerFeatureHandler(response){
			if (response.results.length == 1){
				/*Response Attributes include:
					date_time: "2022-07-20 13:00:00+00"
					feature_id: int
					title: string
				*/
				let message = `Getting Details for feature: ${response.results[0].graphic.attributes.feature_id}&amp;lt;br \&amp;gt;
					Date: ${new Date(response.results[0].graphic.attributes.date_time).toLocaleDateString()}&amp;lt;br \&amp;gt;
					Title: ${response.results[0].graphic.attributes.title}
				`;
				$('#trackList').html(message);
				getDetails(response.results[0].graphic.attributes.feature_id, response.results[0].mapPoint.latitude.toFixed(4), response.results[0].mapPoint.longitude.toFixed(4));
			}else{
				let message = response.results.length + " Features here.&amp;lt;br \&amp;gt;";
				for(let index = 0; index &amp;lt; response.results.length; ++index){
					message += "Feature: " + response.results[index].graphic.attributes.feature_id + ":&amp;lt;br \&amp;gt;";
					message += "Date: " + new Date(response.results[index].graphic.attributes.date_time).toLocaleDateString() + "&amp;lt;br \&amp;gt;";
					message += "Title: " + response.results[index].graphic.attributes.title;
					message += '&amp;lt;Button onClick="(e) =&amp;gt; getDetails(\'' + response.results[index].graphic.attributes.feature_id + '\', ' + response.results[index].mapPoint.latitude.toFixed(4) + ', ' + response.results[index].mapPoint.longitude.toFixed(4) + ')" size="default"&amp;gt;Get Details&amp;lt;/Button&amp;gt;&amp;lt;hr /&amp;gt;';
				}
				$('#trackList').html(message);
			}
		};
		/*************MAP CLICK - END****************/
	}
}

const getDetails = (featureID, clickPointLat, clickPointLon) =&amp;gt; {
	console.log("In getDetails");
	//Can use esriRequest now to make external API call for feature details
	//API request results will then be loaded into the featureDetails div!!!
	//This works fine where the click result is only 1 feature.
	//Can't reach this method from the button created from a multi-feature response.
}

return (
	&amp;lt;div className="widget-starter jimu-widget" style={{ overflow: 'auto', display: 'flex', flexWrap: 'wrap', justifyContent: 'center'}}&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;div id="trackList"&amp;gt;
			No Track Features Selected.
		&amp;lt;/div&amp;gt;
		&amp;lt;div id="featureDetails"&amp;gt;
			No Feature Details.
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 Nov 2023 01:14:45 GMT</pubDate>
    <dc:creator>diplonics</dc:creator>
    <dc:date>2023-11-25T01:14:45Z</dc:date>
    <item>
      <title>Access bespoke Widget click events</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353190#M9542</link>
      <description>&lt;P&gt;I have a bespoke widget that adds a GeoJson layer to a mapview.&lt;/P&gt;&lt;P&gt;When the map is clicked and features from the GeoJson layer are identified they are loaded back into the widget UI as the list of features selected.&lt;/P&gt;&lt;P&gt;The UI output is made like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let message = response.results.length + " Feature selected here.&amp;lt;br \&amp;gt;";
for(let index = 0; index &amp;lt; response.results.length; ++index){
	message += "ID: " + response.results[index].graphic.attributes.feature_id + ":&amp;lt;br \&amp;gt;";
	message += "Date: " + response.results[index].graphic.attributes.date_time + "&amp;lt;br \&amp;gt;";
	message += '&amp;lt;Button onClick="getDetails(\'' + response.results[index].mapPoint.latitude.toFixed(4) + ', ' + response.results[index].mapPoint.longitude.toFixed(4))" size="default"&amp;gt;Load&amp;lt;/Button&amp;gt;';
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All this loads into the UI fine but the scope on the button onClick fails with this message:&lt;/P&gt;&lt;P&gt;Uncaught ReferenceError: getDetails is not defined&lt;BR /&gt;at HTMLButtonElement.onclick (0/?draft=true:1:1)&lt;BR /&gt;onclick @ 0/?draft=true:1&lt;BR /&gt;&lt;BR /&gt;Sorry but lost as to how I can get scope back on the button click, tried so many approaches and just more confused now.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 16:35:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353190#M9542</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-24T16:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Access bespoke Widget click events</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353198#M9543</link>
      <description>&lt;P&gt;Is this a functional component or a class component?&amp;nbsp;&lt;/P&gt;&lt;P&gt;If its a class component, you could try:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;message += '&amp;lt;Button onClick="this.getDetails(\'' + response.results[index].mapPoint.latitude.toFixed(4) + ', ' + response.results[index].mapPoint.longitude.toFixed(4))" size="default"&amp;gt;Load&amp;lt;/Button&amp;gt;';&lt;/LI-CODE&gt;&lt;P&gt;Otherwise you can try:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;message += '&amp;lt;Button onClick="(e) =&amp;gt; getDetails(\'' + response.results[index].mapPoint.latitude.toFixed(4) + ', ' + response.results[index].mapPoint.longitude.toFixed(4))" size="default"&amp;gt;Load&amp;lt;/Button&amp;gt;';&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of those might work.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 17:59:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353198#M9543</guid>
      <dc:creator>Grant-S-Carroll</dc:creator>
      <dc:date>2023-11-24T17:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Access bespoke Widget click events</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353211#M9544</link>
      <description>&lt;P&gt;Its a functional component and the error is gone on button click, so thanks for that bit.&lt;/P&gt;&lt;P&gt;Unfortunately the function getDetails is not executing it seems as I've stripped it down to just output a console.log and no output on click, but no error either.&lt;/P&gt;&lt;P&gt;Will poke about some more to understand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 19:46:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353211#M9544</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-24T19:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Access bespoke Widget click events</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353214#M9545</link>
      <description>&lt;P&gt;The function being called currently only look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const getDetails = (clickPointLat, clickPointLon) =&amp;gt; {
	console.log("In getDetails");
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 Nov 2023 20:05:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353214#M9545</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-24T20:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Access bespoke Widget click events</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353216#M9546</link>
      <description>The part where you build the button, it looks like it’s the result of a call to a service. Can you show the full code for that please?&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Nov 2023 20:14:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353216#M9546</guid>
      <dc:creator>Grant-S-Carroll</dc:creator>
      <dc:date>2023-11-24T20:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Access bespoke Widget click events</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353262#M9547</link>
      <description>&lt;P&gt;Below is relevant code, hopefully its enough as I think the logic it defines is whats got me.&lt;/P&gt;&lt;P&gt;Definitely react naive issue as not my standard framework as you'll see by the 'cheating' using jQuery to manage div updates!!!&lt;/P&gt;&lt;P&gt;Happy to rework all if pointers/advice possible so thanks for help so far!!&lt;/P&gt;&lt;P&gt;layer in below code is a geoJsonLayer of polylines added at the start of the code.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
	if (jmv) {
		setJimuMapView(jmv);
		/*************MAP CLICK - START****************
		 * When the map is clicked get map coodinates.
		 */
		jmv.view.on("click", tracksLayerClickHandler);

		function tracksLayerClickHandler(event){
			//only include graphics from Tracks Layer
			const opts = {
				include: layer
			};
			jmv.view.hitTest(event, opts).then(tracksLayerFeatureHandler);
		};

		function tracksLayerFeatureHandler(response){
			if (response.results.length == 1){
				/*Response Attributes include:
					date_time: "2022-07-20 13:00:00+00"
					feature_id: int
					title: string
				*/
				let message = `Getting Details for feature: ${response.results[0].graphic.attributes.feature_id}&amp;lt;br \&amp;gt;
					Date: ${new Date(response.results[0].graphic.attributes.date_time).toLocaleDateString()}&amp;lt;br \&amp;gt;
					Title: ${response.results[0].graphic.attributes.title}
				`;
				$('#trackList').html(message);
				getDetails(response.results[0].graphic.attributes.feature_id, response.results[0].mapPoint.latitude.toFixed(4), response.results[0].mapPoint.longitude.toFixed(4));
			}else{
				let message = response.results.length + " Features here.&amp;lt;br \&amp;gt;";
				for(let index = 0; index &amp;lt; response.results.length; ++index){
					message += "Feature: " + response.results[index].graphic.attributes.feature_id + ":&amp;lt;br \&amp;gt;";
					message += "Date: " + new Date(response.results[index].graphic.attributes.date_time).toLocaleDateString() + "&amp;lt;br \&amp;gt;";
					message += "Title: " + response.results[index].graphic.attributes.title;
					message += '&amp;lt;Button onClick="(e) =&amp;gt; getDetails(\'' + response.results[index].graphic.attributes.feature_id + '\', ' + response.results[index].mapPoint.latitude.toFixed(4) + ', ' + response.results[index].mapPoint.longitude.toFixed(4) + ')" size="default"&amp;gt;Get Details&amp;lt;/Button&amp;gt;&amp;lt;hr /&amp;gt;';
				}
				$('#trackList').html(message);
			}
		};
		/*************MAP CLICK - END****************/
	}
}

const getDetails = (featureID, clickPointLat, clickPointLon) =&amp;gt; {
	console.log("In getDetails");
	//Can use esriRequest now to make external API call for feature details
	//API request results will then be loaded into the featureDetails div!!!
	//This works fine where the click result is only 1 feature.
	//Can't reach this method from the button created from a multi-feature response.
}

return (
	&amp;lt;div className="widget-starter jimu-widget" style={{ overflow: 'auto', display: 'flex', flexWrap: 'wrap', justifyContent: 'center'}}&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;div id="trackList"&amp;gt;
			No Track Features Selected.
		&amp;lt;/div&amp;gt;
		&amp;lt;div id="featureDetails"&amp;gt;
			No Feature Details.
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2023 01:14:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/access-bespoke-widget-click-events/m-p/1353262#M9547</guid>
      <dc:creator>diplonics</dc:creator>
      <dc:date>2023-11-25T01:14:45Z</dc:date>
    </item>
  </channel>
</rss>

