display infowindow when mouse hover over a specific point graphic

3395
2
Jump to solution
07-18-2015 04:39 PM
LefterisKoumis
Occasional Contributor III

I have several graphics but I want to display an info window only when the mouse hover one specific graphic point.

So, I modified a code from a sample, to initiate the display only if the mouse location is the same as the point location (mypoint.lon,mypoint.lat).

When I use accuracy to 3 decimals for the lat lon, it works but it displays the infowindow when the mouse is nearby the point. If I increase the accuracy to 4 decimals, then the infowindow never displays unless you hit the exact location which is difficult. Suggestions? Do you have another approach to show the info window only for selected graphics?

Thank you.

var mp = webMercatorUtils.webMercatorToGeographic(event.mapPoint);

  if ((mp.x.toFixed(3) === mypoint.lon.toFixed(3)) && (mp.y.toFixed(3) === mypoint.lat.toFixed(3))){

                map.graphics.clear();  //use the maps graphics layer as the highlight layer

               // var graphic = event.graphic;

                map.infoWindow.setContent(myGraphicMarker.getContent());

                map.infoWindow.setTitle(myGraphicMarker.getTitle());

                var highlightGraphic = new Graphic(myGraphicMarker.geometry, pointSymbol);

                map.graphics.add(highlightGraphic);

                map.infoWindow.show(event.screenPoint,

                  map.getInfoWindowAnchor(event.screenPoint));

  }

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   Tell me more about where you currently have the code running. Is it in the layers mouse-over event? Instead of trying to match the XY why don't you get the graphics attributes and check if it is the correct graphic?

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   Tell me more about where you currently have the code running. Is it in the layers mouse-over event? Instead of trying to match the XY why don't you get the graphics attributes and check if it is the correct graphic?

LefterisKoumis
Occasional Contributor III

Thank you! Your suggestion for an attribute, turned a light bulb on. I didn't have any attributes since the graphics were just defined on the map and they were not the result of a query. So, I just set a new attribute "id".