<?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 polygon features with pointer events in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405302#M84220</link>
    <description>&lt;P&gt;Thanks for the codepen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A few things. First you already have the layer in your webmap. So there is no need to add another instance of it to your map. You can simply get the instance of the layer once the webmap is loaded. Then you have to set the outFields of the layer to all. &amp;nbsp;I sent you the modified codepen directly.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2024 16:25:23 GMT</pubDate>
    <dc:creator>UndralBatsukh</dc:creator>
    <dc:date>2024-04-03T16:25:23Z</dc:date>
    <item>
      <title>Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1404857#M84199</link>
      <description>&lt;P&gt;Hi, I'm trying to modify the &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/view-hittest/" target="_blank" rel="noopener"&gt;Access features with pointer events&lt;/A&gt;&amp;nbsp;sample code from the ArcGIS Developers site. I want it to work with an existing webmap and with a polygon layer instead of a line. I've run the code through ChapGPT, which had me make some changes from the original structure, but the code isn't working either way. (Feature layer url and portal item id have been removed from the code below, but both do load in codepen.)&lt;/P&gt;&lt;P&gt;Any help would be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta 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;Access features with pointer events | RH Planning Areas&amp;lt;/title&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #info {
        background-color: black;
        opacity: 0.75;
        color: lightBlue;
        font-size: 18pt;
        padding: 8px;
        visibility: hidden;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.29/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script&amp;gt;
      require(["esri/WebMap", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/symbols/SimpleFillSymbol"],
      (WebMap, MapView, FeatureLayer, SimpleFillSymbol) =&amp;gt; {
        
        const PlanningAreasLayer = new FeatureLayer({
          url: "https://.../FeatureServer/0",
          outFields: ["*"]
        });

        const webmap = new WebMap({
          portalItem: {
            id: "itemID",
            portal: "https://www.arcgis.com",
            layers: [PlanningAreasLayer]
          }
        });

        const view = new MapView({
          container: "viewDiv",
          map: webmap,
          center: [-83.1563078,42.6645259],
          zoom: 12,
          highlightOptions: {
            color: "lightBlue"
          }
        });
        
        view.ui.add("info", "top-right");
        
        view
          .when()
          .then(() =&amp;gt; {
            return PlanningAreasLayer.when();
          })
          .then((layer) =&amp;gt; {
            const renderer = layer.renderer.clone();
            const fillSymbol = {
              type: "simple-fill",
              color: [255, 0, 255, 0], //transparent fill
              outline: {
                color: [255, 0, 0, 0], //red
                width: 4
              }
            };
          renderer.symbol = fillSymbol;
          layer.renderer = renderer;
                  

            // Set up an event handler for pointer-down (mobile)
            // and pointer-move events (mouse)
            // and retrieve the screen x, y coordinates
            return view.whenLayerView(layer);
          })
          .then((layerView) =&amp;gt; {
            view.on("pointer-move", eventHandler);
            view.on("pointer-down", eventHandler);

            function eventHandler(event) {
              // only include graphics from PlanningAreasLayer in the hitTest
              const opts = {
                include: PlanningAreasLayer
              }
              // the hitTest() checks to see if any graphics from the PlanningAreasLayer
              // intersect the x, y coordinates of the pointer
              view.hitTest(event, opts).then(getGraphics);
            }
            let highlight, currentName;

            function getGraphics(response) {
              // the topmost graphic from the PlanningAreasLayer
              // and display select attribute values from the
              // graphic to the user
              if (response.results.length) {
                const graphic = response.results[0].graphic;
                const attributes = graphic.attributes;
                const areaName = attributes.Neighbor_1;
                const mapLink = attributes.Neighborho
                const id = attributes.OBJECTID;
                
                if (highlight &amp;amp;&amp;amp; currentName !== areaName) {
                  //Check if a highlight exists (is not null or undefined)
                  //Checks if the current name is not equal to the name
                  //If true, name has changed so highlight should be removed
                  //If condition is true, execute the following code
                  highlight.remove(); //Remove the highlight from the graphic
                  highlight = null; //Set the highlight variable to null
                  return; //Exit the current function
                }
                
                if (highlight) {
                  const query = layerView.createQuery();
                  query.where = "NAME = '" + areaName + "'";
                  layerView.queryObjectIds(query).then((ids) =&amp;gt; {
                    if (highlight) {
                      highlight.remove()
                    }
                    highlight = layerView.highlight(ids);
                    currentName = areaName;
                  })
                }
                
                //diplay information about the feature
                document.getElementById("info").style.visibility = "visible";
                document.getElementById("name").innerHTML = areaName;
                document.getElementById("link").innerHTML = mapLink;

              } else {
                // remove the highlight if no features are
                // returned from the hitTest
                if (highlight){
                  highlight.remove();
                  highlight = null;
                }
                document.getElementById("info").style.visibility = "hidden";
              }
            }
          });
      });
    &amp;lt;/script&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;div id="info"&amp;gt;
      &amp;lt;span id="name"&amp;gt;&amp;lt;/span&amp;gt; &amp;lt;br /&amp;gt;
      &amp;lt;span id="link"&amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 02 Apr 2024 20:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1404857#M84199</guid>
      <dc:creator>ArianaToth</dc:creator>
      <dc:date>2024-04-02T20:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1404937#M84201</link>
      <description>&lt;P&gt;What is the error you are getting? Looks like the query might not be running successfully just looking at your code. &amp;nbsp;Here you are saying the &lt;EM&gt;areaName&lt;/EM&gt; is coming from &lt;EM&gt;Neighbor_1&lt;/EM&gt; field. &amp;nbsp;&lt;/P&gt;&lt;PRE&gt; const areaName = attributes.Neighbor_1;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But later you are using the following query where the field name is &lt;EM&gt;NAME&lt;/EM&gt;. &amp;nbsp;Which one is it?&lt;/P&gt;&lt;PRE&gt; query.where = "NAME = '" + areaName + "'";&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 22:40:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1404937#M84201</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-04-02T22:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405199#M84208</link>
      <description>&lt;P&gt;I don't know JavaScript well so I thought I was inputting a string, not a variable with "NAME." I've changed that to "areaName" as well but I still don't get features to show on my map.&lt;/P&gt;&lt;P&gt;The message in the console is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;"[esri.views.2d.layers.MediaLayerView2D]" // [object Object]&lt;BR /&gt;{&lt;BR /&gt;"name": "element-load-error",&lt;BR /&gt;"message": "Element cannot be displayed",&lt;BR /&gt;"details": "[object]"&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 14:13:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405199#M84208</guid>
      <dc:creator>ArianaToth</dc:creator>
      <dc:date>2024-04-03T14:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405216#M84211</link>
      <description>&lt;P&gt;This error has nothing to do with the query action. The error is saying you have a MedialLayer in your app and that its media element cannot be displayed. You should remove the MediaLayer and start with a simpler app.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 14:37:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405216#M84211</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-04-03T14:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405261#M84214</link>
      <description>&lt;P&gt;I turned off the media layer and now I get zero warnings or errors in the console. But I still don't get any popups either.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 15:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405261#M84214</guid>
      <dc:creator>ArianaToth</dc:creator>
      <dc:date>2024-04-03T15:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405272#M84215</link>
      <description>&lt;P&gt;What exactly are you trying to do? The sample you referenced does not display popup. It rather displays just a few info in a DIV tag as user moves the mouse over the features. Can you provide a working codepen so that I can help you further?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 15:52:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405272#M84215</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-04-03T15:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405286#M84217</link>
      <description>&lt;P&gt;Yes, that's what I mean by pop-up. It should display 2 attribute values and highlight the feature. Right now it does neither.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 16:04:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405286#M84217</guid>
      <dc:creator>ArianaToth</dc:creator>
      <dc:date>2024-04-03T16:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405290#M84219</link>
      <description>&lt;P&gt;I won't be able to help without an actual reproducible case. Can you provide one?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 16:06:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405290#M84219</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-04-03T16:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405302#M84220</link>
      <description>&lt;P&gt;Thanks for the codepen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A few things. First you already have the layer in your webmap. So there is no need to add another instance of it to your map. You can simply get the instance of the layer once the webmap is loaded. Then you have to set the outFields of the layer to all. &amp;nbsp;I sent you the modified codepen directly.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 16:25:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405302#M84220</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-04-03T16:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405375#M84221</link>
      <description>&lt;P&gt;I just had time to look at this some more and I realized that the attributes are showing up in the info Div but the layer still isn't highlighting. Can you please help with that?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 18:28:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405375#M84221</guid>
      <dc:creator>ArianaToth</dc:creator>
      <dc:date>2024-04-03T18:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Access polygon features with pointer events</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405488#M84223</link>
      <description>&lt;P&gt;You have to update the field names for the query in your app. You are using wrong field names. For example, your service does not have a field called areaName. In any case, I updated the same codepen to reflect these changes. Please create a new question if you need further help on this.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 21:33:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/access-polygon-features-with-pointer-events/m-p/1405488#M84223</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-04-03T21:33:48Z</dc:date>
    </item>
  </channel>
</rss>

