MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Clustering Pushpins with the Virtual Earth Map Control API

This is a discussion on Clustering Pushpins with the Virtual Earth Map Control API within the Virtual Earth Blogs forums, part of the Blogs category; One of the new features introduced in the Virtual Earth Map Control API is Pushpin Clustering.  When there are hundreds ...


Go Back   MapPoint Forums > Blogs > Virtual Earth Blogs

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (2) Thread Tools Display Modes
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 10-12-2008
Junior Member
Site Admin
 
Join Date: Sep 2008
Posts: 0
Clustering Pushpins with the Virtual Earth Map Control API

One of the new features introduced in the Virtual Earth Map Control API is Pushpin Clustering.  When there are hundreds of pushpin shapes on the map in a dense area, the map can become very cluttered. The pushpins can overlap each other and obscure the map view and make the map difficult to use.  Previously, to solve this problem, developers using the Virtual Earth map control would have to either divide groups of pushpins into VEShapeLayers and manually control which layers to show and hide at different zoom levels, or just not show Pushpins at zoom levels if there were too many on the screen.  With the v6.2 Virtual Earth Map Control API, this situation has gotten a lot easier to manage with the addition of the pushpin clustering feature.

In the v6.2 Virtual Earth Map Control API, we introduced two new methods on the VEShapeLayer to support pushpin clustering.  In a previous blog post awhile back, I talked about the VEShapeLayer class which is designed to group a set of VEShapes so they can be managed as a collective group.  The two new methods for pushpin clustering are VEShapeLayer.SetClusteringConfiguration and VEShapeLayer.GetClusteredShapes.  The v6.2 Virtual Earth Map Control API is reverse compatible with the previous v6.1 and v6 APIs and does not cluster pushpins by default.

The SetClusteringConfiguration method allows you to specify how you want to cluster shapes in a shape layer.  The first parameter is either a VEClusteringType enumeration specifying a known clustering algorithm supported by Virtual Earth, or it can be a reference to a custom function which does the clustering.  Currently VEClusteringType can either be VEClusteringType.Grid to specify a grid-based clustering algorithm or VEClusteringType.None which turns off clustering.  By default clustering is off if you do not call SetClusteringConfiguration on a VEShapeLayer.

So, you can turn on grid clustering with a single call to SetClusteringConfiguration.  Assuming you have a VEShapeLayer reference called shapeLayer, here's the syntax:

shapeLayer.SetClusteringConfiguration(VEClustering Type.Grid);

The built-in grid based clustering algorithm divides the screen into equal-sized squares.  If there are more than one VEShape pushpins in a square, they are combined into a cluster.  So, at the highest altitude, you will see more clusters and at the lowest altitude (highest level of detail) you will see less clusters, but more individual shapes.  So, as you zoom in on clusters to highest level of detail, they will eventually break up and show individual shapes.  So, with one line of code, this simple algorithm now reduces clutter on the map significantly and divides shapes up into manageable chunks.  By default, pushpin clusters will have a special cluster pushpin icon just like VEShape pushpins have their own default pin icon also.  Each cluster will also have a default popup balloon with information about the cluster.  The default popup shows the number of shapes in the cluster.  In a future blog post, I will show you how to override some of these default settings to provide more advanced customization to pushpin clustering.

Figure 1 below shows a set of pushpins that are not clustered.  Figure 2 shows the same set of pushpins clustered with Grid clustering: 

Figure 1. Unclustered Pushpins Figure 2. Clustered Pushpins

 

If you want to turn off pushpin clustering after you have turned it on, you just have to make the following call:

shapeLayer.SetClusteringConfiguration(VEClustering Type.None);

If you want to know what shapes are in each pushpin cluster, you can do so with the GetClusteredShapes method on the VEShapeLayer which also takes in a VEClusteringType parameter.  For example:

var shapeClusters = shapeLayer.GetClusteredShapes(VEClusteringType.Gri d)

This call returns an array of VEClusterSpecification objects representing the set of shape clusters with the passed in clustering type.  Each VEClusterSpecification object in the array represents a cluster.  The Shapes property on the object specifies the pushpins in the cluster.  The LatLong property is a VELatLong and specifies the Latitude, Longitude location of the center of the cluster where the cluster icon is positioned.  This provides all the information you have for a cluster, so no information is lost when pushpins are clustered. Also, this method works even when clustering is off. So, if you want to have a complete custom rendering for a cluster, or just know what shapes would be clustered if you turned clustering on, you can use this method.

Click on the link below to see a sample of pushpin clustering with Virtual Earth.

Virtual Earth Map Control API Clustering Sample

Keith Kinnan

Software Development Lead, Virtual Earth Platform



VE Platform Team Blog Entry...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/clustering-pushpins-virtual-earth-map-control-api-8848.html

Posted By For Type Date
Reverse Geocoding, Pt. III - MapPoint Articles - MP2K Magazine This thread Refback 10-15-2008 02:55 AM
Working With Excel and MapPoint - MP2K Magazine This thread Refback 10-13-2008 12:40 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Lancement de Virtual Earth Web Service et du Virtual Earth Map Control 6.2 Virtual Earth Europe Virtual Earth Blogs 0 09-25-2008 04:22 AM
Announcing The Virtual Earth Web Service and Virtual Earth Map Control 6.2 VirtualEarth MSDN Blog Virtual Earth Blogs 0 09-25-2008 01:21 AM
Virtual Earth Map Control Script Eric Frost MapPoint Web Service and Virtual Earth 1 04-24-2006 11:34 PM
Virtual Earth Map Control Test Eric Frost MapPoint Web Service and Virtual Earth 0 08-12-2005 11:06 AM
Getting Started with the Virtual Earth Map Control Eric Frost MP2K Magazine Articles 0 08-02-2005 04:39 PM


All times are GMT -5. The time now is 02:16 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54