<?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: HitTest errors with VectorTileLayer and setStyleLayer in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1544422#M85799</link>
    <description>&lt;P&gt;Fantastic news! I just tried the codepen and confirmed the behavior now works as expected. I am going to mark this as resolved and look forward to the release of 4.31 and starting to use this pattern in our own applications. Thanks again.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2024 17:54:04 GMT</pubDate>
    <dc:creator>RyanSutcliffe</dc:creator>
    <dc:date>2024-10-01T17:54:04Z</dc:date>
    <item>
      <title>HitTest errors with VectorTileLayer and setStyleLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1534704#M85576</link>
      <description>&lt;P&gt;I am trying to create a map with a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-VectorTileLayer.html" target="_self"&gt;VectorTileLayer&lt;/A&gt; in it that responds to a user click by highlighting the clicked record (via style and filter updates).&lt;/P&gt;&lt;P&gt;To do this I use a combination of the View's &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest" target="_self"&gt;hitTest&lt;/A&gt; and&amp;nbsp; the VectorTileLayer's &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-VectorTileLayer.html#setStyleLayer" target="_self"&gt;setStyleLayer&lt;/A&gt; methods.&lt;/P&gt;&lt;P&gt;I cannot share publicly the source VectorTileServer service used for my VectorTileLayer and I cannot seem to find a publically available VectorTileLayer with a single polygon layer with attributes included in it. So I cannot give a working codepen of the exact problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the gist of the code is like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// setup map/mapview

// add VectorTileLayer with my own styles:

 const vtl = new VectorTileLayer({
      style: {
        //...
        layers: [
          {
            "fill-opacity": 0.6,
            id: "Accel/Fill0",
            layout: {},
            "line-opacity": 0.6,
            paint: {
              "fill-color": "rgba(255,255,25, 255)",
              "fill-opacity": 0.4,
            },
            "source-layer": "layer",
            type: "fill",
          },
          {
            "fill-opacity": 1,
            filter: ["==", ["get", "id"], 28428], // want to change this dynamically
            id: "Accel/Linehighlight", // this is the style layer to update
            layout: {},
            "line-opacity": 1,
            paint: {
              "line-color": [249, 137, 0, 255],
              "line-width": 3,
            },
            "source-layer": "layer",
            type: "line",
          },
        ],
      },
    });

map.add(vtl);

view.on("click", (event) =&amp;gt; {
    view.hitTest(event).then((response) =&amp;gt; {
      try {
        if (response.results.length) {
          console.log("found a layer");
          const vectorLayer = response.results[0].layer;
          const highlightIndex = vectorLayer.getStyleLayerIndex(
            "Accel/Linehighlight"
          );
          const newHighlightStyle = vectorLayer.getStyleLayer(
            "Accel/Linehighlight"
          );

          newHighlightStyle.filter = [
            "==",
            ["get", "id"],
            response.results[0].graphic.attributes.id,
          ];
          vectorLayer.deleteStyleLayer("Accel/Linehighlight");
          vectorLayer.setStyleLayer(newHighlightStyle, highlightIndex);
          
        } else {
          // this happens when clicking a feature inside its geometry.
          console.warn("Nothing found");
        }
      } catch (err) {
// this happens also. see error below.
        console.warn(err);
      }
    });
  });&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;The behavior I get is it works initially. The selected feature gets updated and the map redraws accordingly. After that, the subsequent click of another feature fails. Either nothing is returned or this error gets returned:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class=""&gt;VectorTileLayerView2D.js:117 &lt;/SPAN&gt;&lt;SPAN class=""&gt;Uncaught (in promise) &lt;SPAN class=""&gt;TypeError: Cannot read properties of undefined (reading 'source')&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This will happen a few times. I can make it work again after a few tries, usually in combination with some zoom/pan behavior.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use the hitTest on the same layer&amp;nbsp;&lt;EM&gt;without updating the layerStyles,&amp;nbsp;&lt;/EM&gt;everything is fine. So its something about how I am trying to update the styles above.&lt;/P&gt;&lt;P&gt;Happy to make a codepen if someone can point me to an appropriate public datasource.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is similar to patterns in &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/layers-vectortilelayer-style/" target="_self"&gt;ESRI's example here&lt;/A&gt;. However I don't think they use hitTest there (its in the code example but not working), and they don't use filters on the layers based on attributes of the layers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;--&lt;BR /&gt;Update 2024-09-06:&lt;BR /&gt;With the help of Amr at ESRI Support Canada I was able to get a Vector Tile Service example wherein I&amp;nbsp;&lt;STRONG&gt;can&amp;nbsp;&lt;/STRONG&gt;reproduce the issue. See this &lt;A href="https://codepen.io/Ryan-Sutcliffe/pen/LYKMOzd?editors=0010" target="_self"&gt;Codepen here&lt;/A&gt;. In this example the behavior is more pronounced than I describe above I think. The first click will work. After that the console will show errors or nothing found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 15:17:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1534704#M85576</guid>
      <dc:creator>RyanSutcliffe</dc:creator>
      <dc:date>2024-09-06T15:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: HitTest errors with VectorTileLayer and setStyleLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1534749#M85593</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&amp;nbsp;&amp;nbsp;I'd also like to know what the best thing to do in this situation is. All I want to do is highlight the selected feature in the VectorTileLayer, but the hittest system is not being helpful by not sharing any geometry information for polygons.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 22:40:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1534749#M85593</guid>
      <dc:creator>cdbj</dc:creator>
      <dc:date>2024-09-03T22:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: HitTest errors with VectorTileLayer and setStyleLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1537107#M85650</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am able to reproduce the issue you described. We will look into it and will update you once we have a fix or solution.&amp;nbsp; Thank you for reporting the issue.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2024 21:28:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1537107#M85650</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-09-10T21:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: HitTest errors with VectorTileLayer and setStyleLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1543925#M85789</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This issue is addressed at version 4.31 which will be released in mid November. You can test the fix using our &lt;A href="https://github.com/Esri/feedback-js-api-next" target="_self"&gt;next&lt;/A&gt; version. Here is your codepen updated to point to the next version:&amp;nbsp;&lt;A href="https://codepen.io/U_B_U/pen/abgMmpq?editors=1000" target="_blank"&gt;https://codepen.io/U_B_U/pen/abgMmpq?editors=1000&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 18:06:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1543925#M85789</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-09-30T18:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: HitTest errors with VectorTileLayer and setStyleLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1544422#M85799</link>
      <description>&lt;P&gt;Fantastic news! I just tried the codepen and confirmed the behavior now works as expected. I am going to mark this as resolved and look forward to the release of 4.31 and starting to use this pattern in our own applications. Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 17:54:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hittest-errors-with-vectortilelayer-and/m-p/1544422#M85799</guid>
      <dc:creator>RyanSutcliffe</dc:creator>
      <dc:date>2024-10-01T17:54:04Z</dc:date>
    </item>
  </channel>
</rss>

