Clustering 20K+ Map Points
Was asked "what is the best way to display 20,000 markers on a map ?". Well, displaying all 20K map points does not make whole lot of sense, as you just see nothing, just a blanket of markers. A smarter approach is to cluster the points and display the clusters. Somebody pointed me to mapeed, and asked me to duplicate this using the Flex API for AGS. Here it is. I've loaded 20,000 map points from geonames and created dynamically clusters based on the scale of the map and its extent. BTW, this is all client side processing - gotta love the JIT in Flash Player :-)
[Update] Sooo many people asked me for the source code of the app - here it is. Any feedback is more than welcome.
[Update] Sooo many people asked me for the source code of the app - here it is. Any feedback is more than welcome.
Comments
thanks.
Paul Hastings is spot-on. My uncle and I both just read this blog post and thought "man, I hope he shares the source code."
Yours,
- Everybody
web design company
first of all thank you very much for sharing your work with us. I'm working on a server-side clustering method. I'm very new to this and so I would be glad if you could tell me the name of the algorithm you've used for this client-side clustering.
Much thanks in advance!
Christian
I’m using your sample to cluster entities in my project. In my case, I don’t want to determine clusters only for the current map extent and each time map extent change but for all my set of mapPoints and only when map scale change. In order to do that, I change few things in your code and I’ve got some problem…
It seems to be due of negative values for mapPoint west and/or north of the current map extent when they are converted to screenPoint. That give me some negative value for the key of the cluster dictionary determined by what I call “the magic formula” : var ci : int = (cx << 16) | cy, who is the only point of your sample that I don’t understand (specially the syntax)…
Can you explain to me this formula or/and give me some indication in order to cluster point for every point of my set of mapPoints? I think the solution is to determine unique key value even when I’m working with negative value.
Thanks a lot.
As to the "magic" formula, yeap - this is the trick - it assumes that the cx and cy values will be positive integers less that 2^16. this way, I can combine the two values (by bit shifting) into _one_ value that becomes a key value into a dictionary - cool eh ? anyway, as I said, there is that assumption which is "inherited" if u cluster the point _only_ in the extent. hope this make sense. Working on a newer version that will be part of version 2 API - maybe will backport it to 1.3.
I like this approach (http://thunderheadxpler.blogspot.com/2008/12/clustering-20k-map-points.html) better than that (http://thunderheadxpler.blogspot.com/2009/05/map-points-cubic-clustering.html), because the positioning of the clusters don't look like a grid.
However, it is disturbing to my client, that the clusters change even if I just move the map and not zoom. I tried to call "clusterMapPoints()" only if levelChange of "ExtendEvent" is true. That works, but of course clusters outside the extend will not appear. Is it anyway possible with this approach that the clusters don't change while moving the map?
Thanks