<?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: feature hightlight on mouseover in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377841#M83545</link>
    <description>&lt;P&gt;Thanks very much for your help.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2024 21:53:56 GMT</pubDate>
    <dc:creator>GeoffreyJoseph</dc:creator>
    <dc:date>2024-02-02T21:53:56Z</dc:date>
    <item>
      <title>feature hightlight on mouseover</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377830#M83542</link>
      <description>&lt;P&gt;Can someone please help me understand why my highlights on mouseover are not working here? I am (slowly) working on learning the js api by cobbling together a new version of an &lt;A href="https://districtfinder.youraedi.com" target="_blank" rel="noopener"&gt;app I made in leaflet&lt;/A&gt; (many years ago from the new api samples. Very interesting. I am trying to get the mouseover highlight to work as it does in that app. I know there are other things I may not be doing optimally, feel free to chime in. Eventually I want to use the reactiveUtils I think. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!doctype html&amp;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;Arkansas District Finder&amp;lt;/title&amp;gt;

  &amp;lt;script src="https://js.arcgis.com/calcite-components/1.6.1/calcite.esm.js" type="module"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/calcite-components/1.6.1/calcite.css" /&amp;gt;

  &amp;lt;script src="https://js.arcgis.com/4.28/"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.28/esri/themes/light/main.css" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;style&amp;gt;
  html,
  body,
  #viewDiv {
    padding: 0;
    margin: 0;
    height: 100%;
    width: 100%;
  }

  body {
    display: flex;
  }

  calcite-loader {
    align-self: center;
    justify-self: center;
  }

  #header-title {
    margin-left: 1rem;
    margin-right: 1rem;
  }

  #info-content {
    padding: 0.75rem;
  }

  calcite-rating {
    margin-top: 0.25rem;
  }

  #search-container.esri-search.esri-widget {
    width: 100% !important;
    align-items: flex-start;
    /* do not want scroll bar on panel. Clicking it makes
      search suggestions disappear */
    min-height: 300px;
    padding: 0px;
    overflow: auto;
    /* overflow: hidden; */
  }

  button:disabled {
    opacity: 0.4;
    -moz-opacity: 0.4;
    -webkit-opacity: 0.4;
    cursor: default;
  }

  #info {
    visibility: hidden;
  }

  .esri-feature {
    letter-spacing: 0em;
    line-height: 1.55rem;
    font-feature-settings: "liga"1, "calt"0;
    background: #fff;
    padding: 1em;
  }
&amp;lt;/style&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;calcite-loader&amp;gt;&amp;lt;/calcite-loader&amp;gt;
  &amp;lt;calcite-shell hidden&amp;gt;

    &amp;lt;calcite-shell-panel slot="panel-start"&amp;gt;
      &amp;lt;calcite-panel&amp;gt;

        &amp;lt;calcite-block open&amp;gt;
          &amp;lt;div
            style="width: 100%; background:red; color:white; max-width: 100%; display: flex; flex-direction: row; align-items: center;justify-content: center"&amp;gt;
            &amp;lt;h2&amp;gt;Arkansas District Finder&amp;lt;/h2&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/calcite-block&amp;gt;

        &amp;lt;calcite-block heading="Select Chamber" open&amp;gt;
          &amp;lt;div style="width: 360px; max-width: 100%; display: flex; flex-direction: row"&amp;gt;
            &amp;lt;calcite-button class="esri-button style-button" id="senate" type="button" disabled&amp;gt;
              State Senate
            &amp;lt;/calcite-button&amp;gt;
            &amp;lt;calcite-button class="esri-button style-button" id="house" type="button"&amp;gt;
              State House
            &amp;lt;/calcite-button&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/calcite-block&amp;gt;
        &amp;lt;calcite-block id="senBlock" heading="Search Arkansas State Senators" collapsible open&amp;gt;
          &amp;lt;calcite-label&amp;gt;
            Senators
            &amp;lt;calcite-combobox id="senSelect" selection-mode="single" placeholder="Select a Senator"&amp;gt;

            &amp;lt;/calcite-combobox&amp;gt;
          &amp;lt;/calcite-label&amp;gt;
        &amp;lt;/calcite-block&amp;gt;
        &amp;lt;calcite-block id="repBlock" heading="Arkansas State Reps" collapsible open hidden&amp;gt;
          &amp;lt;calcite-label&amp;gt;
            Representatives
            &amp;lt;calcite-combobox id="repSelect" selection-mode="single" placeholder="Select a Representative"&amp;gt;

            &amp;lt;/calcite-combobox&amp;gt;
            &amp;lt;calcite-label&amp;gt;
        &amp;lt;/calcite-block&amp;gt;
        &amp;lt;calcite-block heading="Find  My Districts" collapsible closed&amp;gt;
          &amp;lt;div id="search-container"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/calcite-block&amp;gt;
        &amp;lt;calcite-block heading="Legend" collapsible open&amp;gt;
          &amp;lt;div id="legend-container"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/calcite-block&amp;gt;

      &amp;lt;/calcite-panel&amp;gt;
    &amp;lt;/calcite-shell-panel&amp;gt;
    &amp;lt;div id="overviewDiv"&amp;gt;
      &amp;lt;div id="extentDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;calcite-shell-panel slot="panel-start" width-scale="s" id="info" align="center"&amp;gt;
      &amp;lt;calcite-panel heading="Arkansas Senate"&amp;gt;
        &amp;lt;calcite-card&amp;gt;
          &amp;lt;img slot="thumbnail" alt="Sample image alt" src="https://placebear.com/280/200"&amp;gt;
          &amp;lt;span slot="title"&amp;gt;Senator Name Here&amp;lt;/span&amp;gt;
          &amp;lt;span slot="subtitle"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;
          &amp;lt;div slot="footer-start" id="example-slotted-footer"&amp;gt;
                &amp;lt;calcite-chip id="badge-1" value="calcite chip" icon="check-circle" scale="s"&amp;gt;&amp;lt;/calcite-chip&amp;gt;
                &amp;lt;calcite-chip id="badge-2" value="calcite chip" icon="globe" scale="s"&amp;gt;&amp;lt;/calcite-chip&amp;gt;
                &amp;lt;calcite-chip id="badge-3" value="calcite chip" icon="security" scale="s"&amp;gt;&amp;lt;/calcite-chip&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div slot="footer-end"&amp;gt;
                &amp;lt;calcite-chip id="badge-4" value="calcite chip" icon="user" scale="s"&amp;gt;&amp;lt;/calcite-chip&amp;gt;
                &amp;lt;calcite-action scale="s" icon="ellipsis" id="example-slotted-action"&amp;gt;&amp;lt;/calcite-action&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/calcite-card&amp;gt;
      &amp;lt;/calcite-panel&amp;gt;
    &amp;lt;/calcite-shell-panel&amp;gt;
  &amp;lt;/calcite-shell&amp;gt;
  &amp;lt;script&amp;gt;
    require([
        "esri/core/promiseUtils",
        "esri/core/reactiveUtils",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/widgets/Home",
        "esri/widgets/Features"
    ] , function(promiseUtils, reactiveUtils, WebMap, MapView, Home, Features){
          const webmapId = new URLSearchParams(window.location.search).get("webmap")
            ?? "c7e90511a9094e14a6b373c5d47916f6";

          // Create a Map with a basemap, to be used with in the main view
          const map = new WebMap({
            portalItem: {
              id: webmapId
            }          
          });
          map.load()
          .then(() =&amp;gt; {
            map.layers
              .filter(layer =&amp;gt; { return layer.type === 'feature' })
              .map(layer =&amp;gt; {
                let featLayer = layer; 
                featLayer.outFields = ['*'];
                return featLayer; 
              });
          });
          const view = new MapView({
            container: "viewDiv",
            map: map,
            popupEnabled: false
          });

          // Provide graphic to a new instance of a Feature widget
          const featuresWidget = new Features({
            container: 'features-widget',
            view: view
          });

          const popup = "&amp;lt;div id='features-widget'&amp;gt;&amp;lt;/div&amp;gt;"
          view.ui.add(featuresWidget, "bottom-right");

          view.ui.move("zoom", "top-left");
          var home = new Home({
              view: view
          });
          view.ui.add(home, "top-left");
          view.ui.add("info", "bottom-left");    

          // Open the Features widget with features fetched from
          // the view click event location.
          reactiveUtils.on(
            () =&amp;gt; view,
            "click",
            (event) =&amp;gt; {
              featuresWidget.open({
                location: event.mapPoint,
                fetchFeatures: true
              });
            }
          );
          map.when(() =&amp;gt; {
            // 2016 election layer
            const senateLayer = map.layers.items[0];
            senateLayer.outFields = ['*'];
            view.whenLayerView(senateLayer).then((layerView) =&amp;gt; {
              let highlight;
              let objectId;

              const debouncedUpdate = promiseUtils.debounce(async (event) =&amp;gt; {
                  // Perform a hitTest on the View
                  const hitTest = await view.hitTest(event);
                  
                  // Make sure graphic is for the current layer
                  const results = hitTest.results.filter((result) =&amp;gt; {
                    return result.graphic.layer.title === "Arkansas State Senate";
                  });

                  if(results.length){
                    const result = results[0];

                    const newObjectId = result &amp;amp;&amp;amp; result.graphic.attributes[result.layer.objectIdField];
                    document.getElementById("info").style.visibility = "hidden";

                    if (!newObjectId) {
                      highlight?.remove();
                      objectId = null;
                    } else if (objectId !== newObjectId) {
                      highlight?.remove();
                      objectId = newObjectId;
                      highlight = layerView.highlight(result.graphic);
                    }
                    //result.forEach((graphicHit) =&amp;gt; {
                    const graphic = result.graphic;

                    const attributes = graphic.attributes;

                    const firstName = attributes.FirstName;
                    const lastName = attributes.LastName;
                    const email = attributes.Email;
                    const party = attributes.Party;
                    const district = attributes.district;
                    const chamber = attributes.Chamber;
                    const id = attributes.OBJECTID;

                    document.getElementById("info").style.visibility = "visible";

                    var panel = document.querySelector('#info');
                    
                    panel.children[0].heading = firstName + " " + lastName + " (" + party +")";

                    document.querySelector('[slot="title"]').innerText= "Arkansas " + chamber + " District " + district;
                    document.querySelector('[slot="subtitle"]').innerText=email;
                    document.querySelector('[slot="thumbnail"]').src=attributes.PhotoURL;
                    document.querySelector('[slot="thumbnail"]').width="320px";

                  }else{
                    highlight?.remove();
                    document.getElementById("info").style.visibility = "hidden";
                  }

              });
              // Listen for the pointer-move event on the View
              view.on("pointer-move", (event) =&amp;gt; {
                debouncedUpdate(event).catch((err) =&amp;gt; {
                  if (!promiseUtils.isAbortError(err)) {
                    throw err;
                  }
                });
              });          
            });
        });    
         


          document.querySelector("calcite-shell").hidden = false;
          document.querySelector("calcite-loader").hidden = true;
          
      });
  &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 21:24:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377830#M83542</guid>
      <dc:creator>GeoffreyJoseph</dc:creator>
      <dc:date>2024-02-02T21:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: feature hightlight on mouseover</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377838#M83544</link>
      <description>&lt;P&gt;With the following changes I got it to highlight on mouseover:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Line 215 should be:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const senateLayer = map.layers.items[3];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Line 242 should be:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;highlight = layerView.highlight([newObjectId]);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Technically not necessary, but I also changed line 227 to:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return result.graphic.layer == layerView.layer;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 21:49:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377838#M83544</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2024-02-02T21:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: feature hightlight on mouseover</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377841#M83545</link>
      <description>&lt;P&gt;Thanks very much for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 21:53:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/feature-hightlight-on-mouseover/m-p/1377841#M83545</guid>
      <dc:creator>GeoffreyJoseph</dc:creator>
      <dc:date>2024-02-02T21:53:56Z</dc:date>
    </item>
  </channel>
</rss>

