Select to view content in your preferred language

Let's talk clusters.

2631
3
07-08-2014 09:02 AM
Labels (1)
ReneRubalcava
Esri Frequent Contributor
2 3 2,631

cluster.png

I made a similar blog post not too long ago, but thought I might share this here. Clustering of point data is a pretty neat way of being able to deal with displaying large amounts of data on a map in a simple way. This capability is a staple in the Flex and Silverlight Esri APIs, but the JS API has not gotten the same sort of love.

The Esri Solution

The Esri solution is a neat little module used in this sample you can download and customize as needed. This works pretty nicely and I have seen it used in quite a few apps that Esri puts out. It's not part of the core API, mainly because the use cases can differ so much as to what someone wants to do with it. It doesn't link directly to a map service, as it requires you to provide it a data source of coordinates and customize the behavior from there. Which works pretty well if you are dealing with spreadsheets of data that has x/y locations associated with it, ala GPS data. But I needed something a little more flexible (in my opinion) that could take my existing FeatureServices or regular Dynamic Map Services and act more like a FeatureLayer. So I did what any good dev would do. I stole their stuff and tweaked it.

The ClusterFeatureLayer

With the ClusterLayer code in hand, I started chipping away at the innards, taking out stuff I didn't need and Frankensteining together features I did need. It started simply enough, rigging it to take in a FeatureService URL or a MapService URL and using that as the source for the point data. That wasn't too hard, although it was a little slow. So I took (stole) some stuff the FeatureLayer where I would load the data via multiple requests using objectids1000 at a time and cache the data. Then I added options to either download all the data at once or as needed, ala MODE_SNAPSHOT in the FeatureLayer module.

The Beast

You can view the project on github here. There are some details in the README and more details in the comments to the code. There has already been a few contributions to the code, which is the beauty of github. You can view a demo of basic clustering here. Did I also mention that it will accept services with polygon geometries and convert them to points and cluster them for you? Yeah, it can do that too.

Pleas feel free to log issues or contributes. I'm currently testing out some options to try and speed up some bottlenecks and generally refactor the code.

3 Comments
StuartThomson1
Emerging Contributor

This looks good.. but I can't get the demo working properly.

3 questions:

1. Your demo link asks for a login, after logging in the map focuses on Chicago but no points load. Any ideas?

2. Does your algorithm cluster and draw only the points visible on the screen? I think the basic esri cluster layer seems to make clusters for the entire map every time you zoom in.

3. Also, what does the polygon geometries demo do?

ReneRubalcava
Esri Frequent Contributor

Thanks for the questions!

I just fixed the demos and updated them to use the latest 3.11 Esri JS API.

odoe/esri-clusterfeaturelayer · GitHub

  1. The AGO URL I was using for demo has since been secured. It's kind of tough finding a URL with that many points to demo, but rest assured it handles it. I've now updated the sample with a service that does not require a login.
  2. It has the ability to add a MODE_SNAPSHOT just like a regular FeatureLayer. The default is true, so it will attempt to download ALL points and cluster them. The benefit here is that all data is then cached and no new requests are made. This is one of those things you'll need to play with in your dataset to see what works better.
  3. This demo seems to timeout on the requests sometimes. It takes a while to load. I'll look into replacing this with a smaller dataset, but the idea was to show that it could actually cluster them. Once all the polygon data is downloaded, the ClusterFeatureLayer will convert the polygons to points in order to cluster them. This process is actually fast, but making all the requests including the geometries can take a while.

Here is a current working demo using about 2,300 points.

Cluster

Like I said, the slowest part is actually downloading the data, clustering is pretty quick.

Please provide any feedback or report any bugs, thanks!

veenahosur1
Deactivated User

can you provide me demo using about 60 lac points

About the Author
Softwhere Developer at Esri working on cool stuff! Author: Introducing ArcGIS API 4 for JavaScript: Turn Awesome Maps into Awesome Apps https://amzn.to/2qwihrV ArcGIS Web Development - https://amzn.to/2EIxTOp Born and raised in East L.A.