Select to view content in your preferred language

How to know if a Graphic is currently clustered?

1013
8
10-27-2011 02:39 PM
JohnBendiksen
Emerging Contributor
I need to be able to determine when a specified Graphic on a GraphicsLayer is currently being clustered by the FlareClusterer.  There doesn't seem to be any way to access the FlareClusterer's collection of Graphics, so I can't keep track that way.

Is there some property of the Graphic itself that will tell me whether it is currently rolled up into a FlareClusterer's collection?

Thanks in advance,
John Bendiksen
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
You can check the Graphic.Symbol type.
private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
{
 if (e.Graphic.Symbol is ESRI.ArcGIS.Client.Clustering.FlareSymbol)
 {
 }
 else
 {
 }
} 
0 Kudos
JohnBendiksen
Emerging Contributor
Thanks for the response, Jennifer.  Unfortunately, it's not going to work for me, because I'm not in a MouseDown state when I need to determine this.

My app is a GPS-tracking one where I show the current position of equipment as they move across the map.  The equipment pins update their position asynchronously as their latest GPS data comes in.  I display the equipment pin on one layer, and show another symbol (with speed and bearing info) at the same location on another layer, such that it 'floats' above the equipment pin.

My problem is that any given new position for an equipment pin may have moved it into a cluster's perimeter, so it is gobbled up into the cluster.  In that case, I don't want to display the 'info' symbol floating in space with no equipment underneath it.

I have complete access to the associated equipment pin (and its Symbol) at the time I'm about to draw the 'info' symbol, but I can't find anything in there to tell me whether it's being clustered.  I tried checking its symbol as you suggested, but it is still set to my original PictureMarkerSymbol.

JB
0 Kudos
DarinaTchountcheva
Frequent Contributor
John,

If I understand correcty what you are doing, I believe it can be acheived in a different way. Here is what I am thinking:

Instead of using a second graphics layer to add the speed and bearing info, use only one graphics layer that you cluster the way you do now. But add a TextBlock in the marker symbol (the pin) for the the standalone graphics to label them. See attached image for an example.

Of course, you can make it as pretty as you want.

Good Luck!
0 Kudos
JohnBendiksen
Emerging Contributor
Thanks, Darina.  But that won't work either, sad to say.

My 'info' symbol is not text but a real MarkerSymbol (an arrow that I build by loading a ControlTemplate on the fly) that I rotate to show the actual direction of the vehicle.  I also vary the opacity of the arrow to give an idea of the vehicle's speed.  The whole thing floats as a ghost image superimposed on the PictureMarkerSymbol that is the vehicle.

That's why I need the info symbols to be separate symbols on a separate layer.  Also I want the user to be able toggle off the arrows by hiding that layer entirely.

I still can't understand how a FlareClusterer can hide Graphics on a map, and replace them with its own symbol, without touching those Graphics (at least in any way that I can detect).  I keep thinking I'm missing something simple here.

Thanks for throwing some thought at my problem...
JB
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Could not your second layer be clustered as well with a custom cluster (sample) having a null symbol as cluster symbol?
So the clusters would not be displayed twice and the non clustered graphics would be rendered with your ghost image.
0 Kudos
JohnBendiksen
Emerging Contributor
Dominique,

Thanks for your response.  I had thought of your approach, and I may end up implementing it if I have to.  It just seems kind of 'kludgy' to have to fake out the map control that way.

Another similar approach would be to replace the original FlareClusterer with a custom clusterer; since that would give me access to the list of clustered graphics, I could easily flag those equipmentPins that were clustered so I would know not to draw their info symbols.  The problem with that is that I would then have to replicate the actions of the FlareClusterer's 'spin-up' symbol, which I quite like, but don't want to have to re-invent.

I keep going back to the idea that the FlareClusterer (or any clusterer) must have to do SOMETHING to make the Graphics it is clustering disappear from the map, and that that something should be detectable.  I've tried checking the Graphic's symbol, its opacity, its inclusion on the GraphicLayer, etc.... nothing seems to work.

I'm still hoping that one of the ESRI programmers (or some other knowledgeable person) will see this and just tell me what they do to hide the Graphic being clustered.

Thanks again,
JB
0 Kudos
DanielWalton
Frequent Contributor
John,

I believe that the graphicslayer checks for a clusterer with each render pass, and overrides the symbols for each graphic with cluster symbols (and thus doesn't render the individual symbols for clustered graphics). Nothing is really changed on the individual graphic objects. Dominique's approach would be the least amount of custom coding, but it would involve double duty as 2 clusterers would be working in parallel doing the same work. You might see a performance hit for large feature collections. Alternatively you should be able to override the flareclusterer methods OnCreateGraphic() and ClusterGraphicsAsync() to tag each graphic with an attribute indicating that it was clustered (don't forget to reset them each time.)
0 Kudos
JohnBendiksen
Emerging Contributor
Thanks for the insight into the internals, Daniel.

I will stop tilting at that particular windmill and just write my own clusterer, which I probably should have done in the first place.  In the time I wasted looking for an easy way out, I could have written it already...

Thanks again,
JB
0 Kudos