<?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: How can I get layerId in Experience Builder (Developer Edition) in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1250262#M80002</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;Hi!&lt;/P&gt;&lt;P&gt;Thank you very much for this advice! I have been sitting on this task for several weeks...&lt;/P&gt;&lt;P&gt;Actually, I want to create universal popup widget for any map that we add to the Map widget in Experience Builder (Dev edition; see attachment). My problem is that I can't (don't know) how to declare, specify the layer / featureLayer.&lt;/P&gt;&lt;P&gt;In your example featureLayer declare in simple way. It's cool! But when I do that I get the error.&lt;/P&gt;&lt;P&gt;Does the Experience Builder allow to create a pop-up window for some specific graphic layer? How can this be done?&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Just in case, I am attaching the widget code.&lt;/P&gt;</description>
    <pubDate>Sun, 22 Jan 2023 20:38:06 GMT</pubDate>
    <dc:creator>Nadia_Matsiuk</dc:creator>
    <dc:date>2023-01-22T20:38:06Z</dc:date>
    <item>
      <title>How can I get layerId in Experience Builder (Developer Edition)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1248701#M79932</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I try to create hover pop up in custom widget (related post: &lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hover-popup-experience-builder-dev/m-p/1248642" target="_blank"&gt;https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hover-popup-experience-builder-dev/m-p/1248642&lt;/A&gt;). In my opinion, one possible way of implementation is layerId tracking. For example, hitTest() look for layerId on map, if there is graphic element popup is open. When mouse move out from layer popup is close. If there isn't any layer pop up isn't call.&lt;/P&gt;&lt;P&gt;I use these components in code but I can't do anything in right way. It doesn't work. I can't found layerId option and add it to equally method.&lt;/P&gt;&lt;P&gt;Thanks a lot for any advice!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;/** @jsx jsx */
import { React, AllWidgetProps, jsx, IMDataSourceInfo, DataSource, DataSourceManager, DataSourceStatus, FeatureLayerQueryParams, DataSourceComponent } from 'jimu-core'
import { JimuMapViewComponent, JimuMapView, FeatureLayerDataSource } from "jimu-arcgis";
import { result } from 'lodash-es';
import View from 'esri/views/View';
import {DataSourceSelector, AllDataSourceTypes, FieldSelector} from 'jimu-ui/advanced/data-source-selector';
import { viewChangeBufferCompare } from 'dist/widgets/arcgis/bookmark/src/setting/utils';

export const myFeatureLayer={} as const

export default class Widget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;any&amp;gt;, any&amp;gt;{

    state = {
      jimuMapView: null,
      timer: null,
      allLayer: [],
      lyr: null
    };

    getDataSourceByLayer: (layerId: string | number, layerOfSubLayerId?: string) =&amp;gt; DataSource

    onDataSourceCreated = (ds: DataSource) =&amp;gt; {
      const datasrc=this.props.useDataSources[0]
      const myDatasrc=DataSourceManager.getInstance().getDataSource(dataSrc.dataSourceId) as FeatureLayerDataSource
      const myFeatureLayer = myDataSrc.layer
      this.setState({ allLayer: myFeatureLayer.layerId, lyr: myFeatureLayer })
    }

    doHitTest = (evt: PointerEvent) =&amp;gt; {
      if(this.state.jimuMapView){
        // Run hitTest on the map view using the pointer event
        this.state.jimuMapView.view.hitTest(evt).then((response) =&amp;gt; {
          if(response.results.length){
            const graphic = response.results.filter(function (result) {
              return result.graphic.layer === myFeatureLayer;
            })[0].graphic
            this.state.jimuMapView.view.popup.open({
              location: graphic.geometry.centroid, 
              features: [graphic]
            });
          } else {
            this.state.jimuMapView.view.popup.close();
          }
        })
      }
    }

    activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
      if (jmv) {
        this.setState({
          jimuMapView: jmv
        });
        // register the pointer-move event handler on the map view
        jmv.view.on("pointer-move", (evt) =&amp;gt; {
          // if there is already a timer, cancel it
          if(this.state.timer){
            clearTimeout(this.state.timer)
          }
          // set new timer that will call doHitTest after the interval
          // pass the pointer-move event as the parameter to doHitTest
          this.setState({
            timer: setTimeout(this.doHitTest, 0, evt)
          })
        });
      }
    };

    render() {
      return (
        &amp;lt;div className="widget-hoverPopup jimu-widget"&amp;gt;
          {this.props.hasOwnProperty("useMapWidgetIds") &amp;amp;&amp;amp;
            this.props.useMapWidgetIds &amp;amp;&amp;amp;
            this.props.useMapWidgetIds[0] &amp;amp;&amp;amp; (
              &amp;lt;JimuMapViewComponent
                useMapWidgetId={this.props.useMapWidgetIds?.[0]}
                onActiveViewChange={this.activeViewChangeHandler}
              /&amp;gt;
            )
          }
        &amp;lt;/div&amp;gt;
      );
    }

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 14:58:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1248701#M79932</guid>
      <dc:creator>Nadia_Matsiuk</dc:creator>
      <dc:date>2023-01-17T14:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get layerId in Experience Builder (Developer Edition)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1249948#M79975</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So I tried my best to understand what problem you are trying to solve. I apologize if I did not understand the issue you are trying to solve. Seems like you want to display popupTemplate for only selected layers when user moves the mouse over the map? At least I think this is what you are asking.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Displaying popupTemplate from pointer-move is intense. So I suggest you use &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-promiseUtils.html#debounce" target="_self"&gt;debounce&lt;/A&gt; method to improve the app performance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest" target="_self"&gt; MapView.hittest&lt;/A&gt; method lets you specify which layers you want to include in the hittest result. So you can specify the layers there. This way the hittest will return results only for those layers. You can also set the exclude to specify layers to be excluded from the hittest. Hope this helps!&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following codepen app displays popupTemplate from pointer-move event. It uses include parameter to specify to only include cities feature layer to be included in the hittest. It also uses debounce for the hittest so&lt;SPAN&gt;&amp;nbsp;you can "debounce", or cancel the function execution, until the previous execution of the same function call finishes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/U_B_U/pen/KKBZmzq?editors=1000" target="_blank"&gt;https://codepen.io/U_B_U/pen/KKBZmzq?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 16:31:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1249948#M79975</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2023-01-20T16:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get layerId in Experience Builder (Developer Edition)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1250262#M80002</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;Hi!&lt;/P&gt;&lt;P&gt;Thank you very much for this advice! I have been sitting on this task for several weeks...&lt;/P&gt;&lt;P&gt;Actually, I want to create universal popup widget for any map that we add to the Map widget in Experience Builder (Dev edition; see attachment). My problem is that I can't (don't know) how to declare, specify the layer / featureLayer.&lt;/P&gt;&lt;P&gt;In your example featureLayer declare in simple way. It's cool! But when I do that I get the error.&lt;/P&gt;&lt;P&gt;Does the Experience Builder allow to create a pop-up window for some specific graphic layer? How can this be done?&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Just in case, I am attaching the widget code.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 20:38:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-can-i-get-layerid-in-experience-builder/m-p/1250262#M80002</guid>
      <dc:creator>Nadia_Matsiuk</dc:creator>
      <dc:date>2023-01-22T20:38:06Z</dc:date>
    </item>
  </channel>
</rss>

