How to cluster graphics

908
6
03-18-2011 05:39 AM
JamesBurton
New Contributor
I am drawing hundreds of graphics (points) on a map and it's too slow in IE -- I get the alert asking if you want to stop the script. So I want to cluster the points and draw one for each set that falls within a certain offset. Are there libs and /or techniques readily available for doing this, or do I have to write it myself? I can see it wouldn't be too difficult to do the clustering but then the graphics need to have an infoWindow, so when clicking on a clustered point I need to display the option to view the attributes for each real data point.

Thanks,
0 Kudos
6 Replies
JamesBurton
New Contributor
There's obviously more to clustering than I imagined and I'm glad to have found this clustering lib: http://www.arcgis.com/home/item.html?id=c546bc8d4f0b4c0fbdf149b92223e681 . I have a problem though -- When I create a clusterLayer I get this alert:

Input Spatial Reference Must Be in Either WKID: 102110 or WKID: 4326

My graphics have got the same spatialReference as the map, which the docs say should be OK. Anyone know why this is?

Thanks,
0 Kudos
StephenLead
Regular Contributor III
Hi James,

I still haven't gotten this sample code to work 100%, but it looks promising.

I found I needed to make a change in the code, which was hard-coded to expect certain spatial references (despite the mention in the text of supporting multiple spatial references).

In my case I made this change to work with my known spatial reference of 102113:

//this function may not be needed exactly as is below.  somehow, the attributes need to be mapped to the points.
    setFeatures: function(features) {
        this._features = [];
        var wkid = features[0].geometry.spatialReference.wkid;
        if (wkid != 102113) {


Let us all know how you go with the clustering - I'd love to see a real-world example in action. I hope to deploy it soon on my own site.

Steve
0 Kudos
JoyC
by
New Contributor
I haven't got the code to work either. The query is not drawing anything. Wonder if anyone else has got this working?

Thanks,
Joy
0 Kudos
derekswingley1
Frequent Contributor
I played with this a little but didn't take it too far. I used it in an app that uses web mercator base maps. Maybe someone will find this helpful:  http://swingley.appspot.com/phish
0 Kudos
StephenLead
Regular Contributor III
Hi all,

We've updated our site to use the clustering sample - see http://atlas.nsw.gov.au/public/nsw/home/map/national-parks.html

I had to make some tweaks to the sample clustering script, to avoid the infoWindow flicking on/off on mouse hover, but otherwise I'm pretty happy with the way it works.

Let me know if you have any questions.

Cheers,
Steve
0 Kudos
nicogis
MVP Frequent Contributor
0 Kudos