Map Marker Mouse Click

2307
8
08-02-2017 08:59 AM
KayugaSolution
New Contributor

The attached code displays a Map with markers that you can click on to get more information. This code works but I'm trying to find the best way to make sure that when the user clicks on a marker that I interpret the click correctly as there may be a couple of markers close together. Currently I am dividing the extent height by 100 in order to calculate my hit area. This doesn't seem like the best way. Also, going through all of the JSON data to find a match isn't great either. Is there some way to associate a marker with some data and then handle the event when the marker is clicked on?

0 Kudos
8 Replies
dotMorten_esri
Esri Notable Contributor

> Currently I am dividing the extent height by 100 in order to calculate my hit area

I'm curious why you are basing it on the extent? A larger window would mean a larger hit area. Also the Identify call takes a location in screen coordinates, and the "tolerance" is in device-independent pixels (usually 1/96 of an inch). 

Generally you use a smaller hit area when using a mouse, and a larger area when using touch, but those values will always be the same regardless of screen size, map extent and Screen DPI.

0 Kudos
dotMorten_esri
Esri Notable Contributor

oh I see now you're just brute-forcing your way through all the graphics and looking whether they are inside an extent.

Instead use the MapView.IdentifyGraphicsOverlaysAsync method. It'll use the size of the symbol, so you'd have to hit an actual pixel where the geometry gets rendered, and if you set the maxHits parameter to 1, you'll get the top-most one.

0 Kudos
KayugaSolution
New Contributor

Thanks.  I'll check it out.

0 Kudos
KayugaSolution
New Contributor

I found this example for IdentifyGraphicsOverlayAsync.  I only care about the points so I set the polygon symbol fill to null.  Now I have the situation where someone could click in the polygon area that is not on one of the points.  How do I narrow the click down to to just the points and not the area in the polygon?

0 Kudos
KayugaSolution
New Contributor

I found this example for IdentifyGraphicsOverlayAsync.  I only care about the points so I set the polygon symbol fill to null.  Now I have the situation where someone could click in the polygon area that is not on one of the points.  How do I narrow the click down to to just the points and not the area in the polygon?

0 Kudos
dotMorten_esri
Esri Notable Contributor

I suggest you split points and polygons in two separate graphics overlays (this also makes it easier to ensure points are on top of polygons). You can then use the overload that takes a single overlay and pass in the point one

KayugaSolution
New Contributor

Thanks.  Since I'm new to all this, if you can point me to an example, that would be great.  Otherwise I'll try to work through it.

0 Kudos
KayugaSolution
New Contributor

I have the two overlays working now so I only get the OnMapViewTapped handler called when a point is clicked on.  My question now is what is the best way to determine the point that was clicked on?  Can I associate an identifier with each point or do I have to still go through all my points manually and determine which one is the closest to the location that was clicked on?

0 Kudos