PushPin clustering

Coordinator
Mar 20, 2009 at 4:35 PM
I got a question on another forum about clustering VEPushPins so figured I'd copy it here as well.

For clustering, it isn't automatic but you can use the MinAltitude, MaxAltitude, and ParentPushPin properties of VEPushPin to achieve clustering.  Min/Max altitudes default to double.MinValue and double.MaxValue, respectively.

Create a VEPushPin to act as the parent and give it appropriate content, like "People (15)".  Once you create all the child pushpins, set their ParentPushPin properties to your parent pushpin.  Also set the parent's lat/long appropriately, to perhaps the average lat/long of all children.

Now just set Min/MaxAltitudes as necessary.  The altitude is in feet.  20000 feet or so is about city-wide.  (Look at VEMap.Altitude to get an idea.)  In general, set the same value to both MinAltitude on the parent pushpin and MaxAltitude on the child pushpins.  This will cause the child pushpins to transition to visible at the same time the parent pushpin transitions to invisible.

The ParentPushPin property is used when transitioning in or out of the MaxAltitude range.  If there is a parent, the the child will animate to/from the ParentPushPin's lat/long, establishing a visual cue of the parent/child relationship.

If you wanted to you could have multiple layers of parent/child pushpins, creating clusters of clusters for different altitudes.  For this you would give the parent pushpins a parent and set the max altitude on them as well.

Finally note you could, if you wanted, not have the parent/child pushpins have the same min/max altitudes, respectively.  If you overlapped the ranges then the parent would be visible in the overlap range after the children appear.  I don't know when this would make sense though, so recommend you match parent/child min/max altitudes.


Apr 29, 2009 at 3:48 PM
This works fine, when i manualy zoom in on a Parent point it nicely splits up.

The only thing i dont seem to get working is to atach a click event to a PushPin.

ppNL.Click += new EventHandler<VEPushPinClickedEventArgs>(ppNL_Click);    // ppNL = VePushPin with a textblock as content
map.Items.Add(ppNL);

 

above shows the pushpin, but isnt clickable ??? what am i doing wrong?

 

Coordinator
Apr 29, 2009 at 3:51 PM
It is clickable regardless of the event handler.

If you're developing for Surface, make sure you instantiate a SurfaceVEPushPin.  You can just say
VEPushPin ppNL = new SurfaceVEPushPin(...)
May 4, 2009 at 9:39 AM
My fault, i used VEPushPin  on the Surface.

It works great now.
Jan 10, 2011 at 4:45 PM

This looks to be an older discussion but in my opinion, one that is still relevant since I am trying to do the same thing. I cannot get the parent push pin to appear. I have added it to the map and have done everything else in the first part of this discussion. Can somebody please help?

Jan 11, 2011 at 10:27 PM
Edited Jan 11, 2011 at 10:29 PM

 

Hi cbodine,

First add a ParentPushPin:

 

VePushPin parentPushpin = new VePushPin();
parentPushpin.MinAltitude = 100000;
parentPushpin.Latitude = //set a latitude maybe the average of child pushpins
parentPushpin .Longitude = //set a longitude maybe the average of child pushpins

map.items.add(parentPushpin) // add the parent pushpin to the map


Then add a child pushpin

VePushPin childPushpin = new VePushPin();
childPushpin.MinAltitude = 0;
childPushpin.MaxAltitude = 100000;
childPushpin.Latitude = //set a lat
childPushpin.Longitude = //set a long
childPushpin.ParentPushPin = parentPushpin; //here you set the parent to the child

   map.items.add(childPushpin) // add the child pushpin to the map


I hope it is clear to you :)

 


 

 

VePushPin VePushPin
Jan 12, 2011 at 1:38 PM

joshb:

Thanks for the reply. I had attempted this before as this is just a variation of some of the prior posts. However, I am getting an error when I add an item to the map ("Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead"). Of course, when I follow the instructions given in the exception, I find that ItemsSource does not contain an Add method. In my routines, I am capturing the SurfaceVEPushPin size changed event, detecting push pin collisions, and then attempting to condense child push pins into a parent or vice versa. Obviously, I have to find a time when the collection is not in use to insert the parent. Any ideas on when to do this or on any other ways to get around this exception?

Coordinator
Jan 13, 2011 at 12:39 AM

cbodine:

The error message indicates that the ItemsControl is data bound to a collection. You need to add or remove your pushpins or business objects from the collection instead.

Detecting collisions is one technique for clustering I haven't seen done before. The control is not designed for that scenario, though with some experience or trial and error you might be able to make it work. I'd recommend trying out the standard parent/child pushpin relationship as described by johan2011 (thanks!) first to see if that will work for you. You could change the parent/child relationship and the min/max altitudes dynamically based upon the pushpins present, but in most cases I have not needed to do that in my applications.