<?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 FeatureLayer with hover returns extra feature in popup in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-with-hover-returns-extra-feature-in/m-p/1025367#M71719</link>
    <description>&lt;P&gt;I change the symbol on a point FeatureLayer (that has a popupTemplate) on hover (using pointer-move, hitTest and view.graphics).&amp;nbsp; For some reason, I get 2 features found in the popup on click.&amp;nbsp; Seems like it is picking up the hover graphic I added to view.graphics.&amp;nbsp;&amp;nbsp;Any suggestions as to why?&amp;nbsp; Using 4.18. Thanks.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&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;meta name="description" content="CDO v3 Demo"&amp;gt;
  &amp;lt;title&amp;gt;CDO v3 Demo&amp;lt;/title&amp;gt;
	
  &amp;lt;style&amp;gt;
	html, body, #mapContainer {
	  padding: 0;
	  margin: 0;
	  height: 100%;
	  width: 100%;
	}
		
	#info {
	  top: 15px;
	  left: 75px;
	  position: absolute;
	  z-index: 99;
	  border-radius: 6px;
	  border: 2px solid gray;
	  color: gray;
	  background: white;
	  padding: 10px;
	  opacity: 0.65;
	}
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/css/main.css"&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/dijit/themes/claro/claro.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require([
	  "esri/Graphic",
	  "esri/geometry/Point",
	  "esri/Map",
	  "esri/views/MapView",
	  "esri/layers/FeatureLayer",
	  "dojo/dom",
	  "dojo/domReady!"
	], function (
	  Graphic,
	  Point,
	  Map,
	  MapView,
	  FeatureLayer,
	  dom
	) {

	  var map = new Map({
	    basemap: "topo"
      });

      var view = new MapView({
	    container: "mapContainer",
	    map: map,
	    center: [-84, 35],
	    zoom: 7,
	    background: {
	 	  color: '#EFEFEF'
	 	},
	 	constraints: {
	 	  rotationEnabled: false
	 	}
      });

      // pseudo data
      const data = [
	    {"id": "CLT", "name": "CHARLOTTE", "latitude": 35.336944, "longitude": -80.885},
		{"id": "ATL", "name": "ATLANTA", "latitude": 33.36333, "longitude": -84.56583},
		{"id": "NSH", "name": "NASHVILLE", "latitude": 35.98, "longitude": -86.661944},
		{"id": "GRE", "name": "GREER", "latitude": 34.88306, "longitude": -82.22028},
		{"id": "KNX", "name": "KNOXVILLE", "latitude": 36.16833, "longitude": -83.40194}
      ]  

      var features = [];

      data.forEach(function(value, i) {
		var feature = {
		  geometry: {
			type: "point",
			x: value.longitude,
			y: value.latitude
		  },
		  attributes: {
			ObjectID: i,
			ID: value.id,
			Name: value.name,
			Latitude: value.latitude,
			Longitude: value.longitude
		  }
		};
		features.push(feature);
      });

      const pointRenderer = {
		type: "simple",
		symbol: {
		  type: "picture-marker",
		  url: "images/marker_default.png",
		  contentType: "image/png",
		  width: "25px",
		  height: "36px"
		}
	  };

      var template = {
        title: "{Name} ({ID})",
        content: "&amp;lt;b&amp;gt;Latitide:&amp;lt;/b&amp;gt; {Latitude}&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;Longitude:&amp;lt;/b&amp;gt; {Longitude}"
      };
      
      var featurelayer = new FeatureLayer({
		source: features,
	    renderer: pointRenderer,
	    objectIDField: "ObjectID",
	    geometryType: "point",
	    fields: [{
	      name: "ObjectID",
	      alias: "ObjectID",
	      type: "oid"
	    },
	    {
	      name: "ID",
	      alias: "ID",
	      type: "string"
	    },
	    {
	      name: "Name",
	      alias: "Name",
	      type: "string"
	    },
	    {
	      name: "Latitude",
	      alias: "Latitude",
	      type: "double"
	    },
	    {
	      name: "Longitude",
	      alias: "Longitude",
	      type: "double"
	    }],
	    outFields: ["*"],
	    popupTemplate: template
	  });

      map.add(featurelayer);

      function changeCursor(response) {
	    if (response.results.length &amp;gt; 0) {
		  document.getElementById("mapContainer").style.cursor = "pointer";
	    } else {
		  document.getElementById("mapContainer").style.cursor = "default";
	    }
      }

      function hoverGraphic(response) {
	    view.graphics.removeAll();
	    if (response.results.length &amp;gt; 0) {
		  let graphic = response.results[0].graphic;
		  graphic.symbol = {
			type: "picture-marker",
		    url: "images/marker_hover.png",
		    contentType: "image/png",
		    width: "25px",
            height: "36px"
		  }
		  view.graphics.add(graphic);
	    }
      }

      view.on("pointer-move", function (evt) {
	    var screenPoint = {
		  x: evt.x,
		  y: evt.y
	    };
     	view.hitTest(screenPoint).then(function (response) {
     	  changeCursor(response);
     	  hoverGraphic(response);
     	});
      });

    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
	&amp;lt;div id="mapContainer"&amp;gt;&amp;lt;/div&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>Wed, 10 Feb 2021 15:24:41 GMT</pubDate>
    <dc:creator>GWReid</dc:creator>
    <dc:date>2021-02-10T15:24:41Z</dc:date>
    <item>
      <title>FeatureLayer with hover returns extra feature in popup</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-with-hover-returns-extra-feature-in/m-p/1025367#M71719</link>
      <description>&lt;P&gt;I change the symbol on a point FeatureLayer (that has a popupTemplate) on hover (using pointer-move, hitTest and view.graphics).&amp;nbsp; For some reason, I get 2 features found in the popup on click.&amp;nbsp; Seems like it is picking up the hover graphic I added to view.graphics.&amp;nbsp;&amp;nbsp;Any suggestions as to why?&amp;nbsp; Using 4.18. Thanks.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&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;meta name="description" content="CDO v3 Demo"&amp;gt;
  &amp;lt;title&amp;gt;CDO v3 Demo&amp;lt;/title&amp;gt;
	
  &amp;lt;style&amp;gt;
	html, body, #mapContainer {
	  padding: 0;
	  margin: 0;
	  height: 100%;
	  width: 100%;
	}
		
	#info {
	  top: 15px;
	  left: 75px;
	  position: absolute;
	  z-index: 99;
	  border-radius: 6px;
	  border: 2px solid gray;
	  color: gray;
	  background: white;
	  padding: 10px;
	  opacity: 0.65;
	}
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/css/main.css"&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/dijit/themes/claro/claro.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require([
	  "esri/Graphic",
	  "esri/geometry/Point",
	  "esri/Map",
	  "esri/views/MapView",
	  "esri/layers/FeatureLayer",
	  "dojo/dom",
	  "dojo/domReady!"
	], function (
	  Graphic,
	  Point,
	  Map,
	  MapView,
	  FeatureLayer,
	  dom
	) {

	  var map = new Map({
	    basemap: "topo"
      });

      var view = new MapView({
	    container: "mapContainer",
	    map: map,
	    center: [-84, 35],
	    zoom: 7,
	    background: {
	 	  color: '#EFEFEF'
	 	},
	 	constraints: {
	 	  rotationEnabled: false
	 	}
      });

      // pseudo data
      const data = [
	    {"id": "CLT", "name": "CHARLOTTE", "latitude": 35.336944, "longitude": -80.885},
		{"id": "ATL", "name": "ATLANTA", "latitude": 33.36333, "longitude": -84.56583},
		{"id": "NSH", "name": "NASHVILLE", "latitude": 35.98, "longitude": -86.661944},
		{"id": "GRE", "name": "GREER", "latitude": 34.88306, "longitude": -82.22028},
		{"id": "KNX", "name": "KNOXVILLE", "latitude": 36.16833, "longitude": -83.40194}
      ]  

      var features = [];

      data.forEach(function(value, i) {
		var feature = {
		  geometry: {
			type: "point",
			x: value.longitude,
			y: value.latitude
		  },
		  attributes: {
			ObjectID: i,
			ID: value.id,
			Name: value.name,
			Latitude: value.latitude,
			Longitude: value.longitude
		  }
		};
		features.push(feature);
      });

      const pointRenderer = {
		type: "simple",
		symbol: {
		  type: "picture-marker",
		  url: "images/marker_default.png",
		  contentType: "image/png",
		  width: "25px",
		  height: "36px"
		}
	  };

      var template = {
        title: "{Name} ({ID})",
        content: "&amp;lt;b&amp;gt;Latitide:&amp;lt;/b&amp;gt; {Latitude}&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;Longitude:&amp;lt;/b&amp;gt; {Longitude}"
      };
      
      var featurelayer = new FeatureLayer({
		source: features,
	    renderer: pointRenderer,
	    objectIDField: "ObjectID",
	    geometryType: "point",
	    fields: [{
	      name: "ObjectID",
	      alias: "ObjectID",
	      type: "oid"
	    },
	    {
	      name: "ID",
	      alias: "ID",
	      type: "string"
	    },
	    {
	      name: "Name",
	      alias: "Name",
	      type: "string"
	    },
	    {
	      name: "Latitude",
	      alias: "Latitude",
	      type: "double"
	    },
	    {
	      name: "Longitude",
	      alias: "Longitude",
	      type: "double"
	    }],
	    outFields: ["*"],
	    popupTemplate: template
	  });

      map.add(featurelayer);

      function changeCursor(response) {
	    if (response.results.length &amp;gt; 0) {
		  document.getElementById("mapContainer").style.cursor = "pointer";
	    } else {
		  document.getElementById("mapContainer").style.cursor = "default";
	    }
      }

      function hoverGraphic(response) {
	    view.graphics.removeAll();
	    if (response.results.length &amp;gt; 0) {
		  let graphic = response.results[0].graphic;
		  graphic.symbol = {
			type: "picture-marker",
		    url: "images/marker_hover.png",
		    contentType: "image/png",
		    width: "25px",
            height: "36px"
		  }
		  view.graphics.add(graphic);
	    }
      }

      view.on("pointer-move", function (evt) {
	    var screenPoint = {
		  x: evt.x,
		  y: evt.y
	    };
     	view.hitTest(screenPoint).then(function (response) {
     	  changeCursor(response);
     	  hoverGraphic(response);
     	});
      });

    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
	&amp;lt;div id="mapContainer"&amp;gt;&amp;lt;/div&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>Wed, 10 Feb 2021 15:24:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-with-hover-returns-extra-feature-in/m-p/1025367#M71719</guid>
      <dc:creator>GWReid</dc:creator>
      <dc:date>2021-02-10T15:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with hover returns extra feature in popup</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-with-hover-returns-extra-feature-in/m-p/1026538#M71761</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;Yes it seems to be picking up a graphic added to view.graphics. View handles the popup for the graphics added to the view.&amp;nbsp; Please add the graphic to GraphicsLayer instead. This will ensure that the second graphic is not displayed in the the popup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;-Undral&lt;/P&gt;</description>
      <pubDate>Sat, 13 Feb 2021 00:26:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-with-hover-returns-extra-feature-in/m-p/1026538#M71761</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2021-02-13T00:26:40Z</dc:date>
    </item>
  </channel>
</rss>

