ESRI point clustering example using featurelayer or querytask as input?

16679
42
Jump to solution
10-05-2012 08:32 AM
TracySchloss
Frequent Contributor
I have tried to implement the ESRI forum example for clustering "Clustering with Javascript API" http://www.arcgis.com/home/item.html?id=c546bc8d4f0b4c0fbdf149b92223e681 with mixed results.  Sometimes the cluster layer draws fine and sometimes it doesn't draw at all.  Even when it draws it's very slow and I'm not sure the users will be satisfied.  There seems to be mixed reviews on this.  The fact that it's display seem to be intermittent for me is enough for me to look to another clustering solution. 

More recently, the ESRI sample "Point Clustering" was posted. http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/layers_point_c... I like the way this looks, but I'm having a hard time understanding how to make it work with a layer as input, since my data is already in a service.  It seems like either I should add a function to step through all my features to create properly formatted input data, or I should edit the custom layer to handle features of a featureset or featurelayer instead.

Has anyone modified ESRI's point clustering example to use something besides the input JSON file?
42 Replies
BrianFischer
New Contributor II
I noticed the link doesn't work, display's a blank map.  Is there a different link to look at?

We have the clustering working well on 100,000+ points but noticed that when the cluster marker has more than 1000 count it drops the marker graphic and only displays the label.  Is this a limitation of the Javascript api or a bug with it?  Could it be it is droping it because it can't fit a 4 digit label inside the graphic?  I noticed ESRI example doesn't go over 999 either. https://developers.arcgis.com/en/javascript/jssamples/layers_point_clustering.html

Anyone have suggestions on how to get the marker to work for counts of more than 999?

Thanks,
Brian
0 Kudos
WuxuanXiang
New Contributor
I would like to know the answer to the last question too. Any updates?

Thanks!

-Aster

I noticed the link doesn't work, display's a blank map.  Is there a different link to look at?

We have the clustering working well on 100,000+ points but noticed that when the cluster marker has more than 1000 count it drops the marker graphic and only displays the label.  Is this a limitation of the Javascript api or a bug with it?  Could it be it is droping it because it can't fit a 4 digit label inside the graphic?  I noticed ESRI example doesn't go over 999 either. https://developers.arcgis.com/en/javascript/jssamples/layers_point_clustering.html

Anyone have suggestions on how to get the marker to work for counts of more than 999?

Thanks,
Brian
0 Kudos
StephenLead
Regular Contributor III
We have the clustering working well on 100,000+ points but noticed that when the cluster marker has more than 1000 count it drops the marker graphic and only displays the label.  Is this a limitation of the Javascript api or a bug with it?  Could it be it is droping it because it can't fit a 4 digit label inside the graphic?  I noticed ESRI example doesn't go over 999 either. https://developers.arcgis.com/en/javascript/jssamples/layers_point_clustering.html

Anyone have suggestions on how to get the marker to work for counts of more than 999?


I think there are 2 reasons why people aren't seeing more than 1000 markers:

- by default ArcGIS Server / ArcGIS Online only return the first 1000 features from a query
- if you've circumvented this (which it sounds like you have, if you're seeing 100k markers) check the renderer.

The renderer in the sample above contains:

renderer.addBreak(200, 1001, red);


Try adding class breaks which contain a valid range for your data.
0 Kudos
WuxuanXiang
New Contributor
changing this line

renderer.addBreak(200, 1001, red)

did solve the problem. Thanks!

aster

I think there are 2 reasons why people aren't seeing more than 1000 markers:

- by default ArcGIS Server / ArcGIS Online only return the first 1000 features from a query
- if you've circumvented this (which it sounds like you have, if you're seeing 100k markers) check the renderer.

The renderer in the sample above contains:

renderer.addBreak(200, 1001, red);


Try adding class breaks which contain a valid range for your data.
0 Kudos
TracySchloss
Frequent Contributor
When I posted that example, 1001 was more than enough for what I had in my data.  I'm not sure of the code off the top of my head, but maybe there would be a way to first determine the maximum and use that as a variable instead of hard coding it?
0 Kudos
firstlast1
New Contributor II
I have been trying to use the re-created cluster function that was posted above and that makes use of QueryTask as input, but without success. The only difference is that I tried to implement Dojo's new AMD pattern as opposed to the legacy one used in the initial code. I have attached the full code in the zip file for reference. After debugging over and over I think it boils down to the following part:

queryTask.on("complete", function(featureSet) {
   
   var inputInfo = {};
   inputInfo.data = arrayUtils.map(featureSet.features, function(feature) {
    var pointX = feature.geometry.x;
    var pointY = feature.geometry.y;
    var att = feature.attributes;
    return {
     "x": pointX,
     "y": pointY,
     "attributes": att
    };
   });


My QueryTask returns the featureSet features alright. I'm seeing every single feature in there. The problem is assigning it to inputInfo.data...it just doesn't pass it through. There are no other errors while running this, basemap loads fine and nothing else. The attached code can be run directly in a browser, everything is in there.

This may be something very simple to fix, I'm new at this as well. I'm just wondering if I missed something earlier in the code, like a loading a module or anything like that.
TracySchloss
Frequent Contributor
I haven't quite wrapped my brain around the difference, but it doesn't look like the exact same object type is getting returned from

queryTask.on("complete", function(results) 

as opposed to the dojo non-AMD
 dojo.connect(queryTask, "onComplete", function(featureSet)


What I noticed was in this section
queryTask.on("complete", function(featureSet) {
   
   var inputInfo = {};
   inputInfo.data = arrayUtils.map(featureSet.features, function(feature) {
    var pointX = feature.geometry.x;
    var pointY = feature.geometry.y;
    var att = feature.attributes;
    return {
     "x": pointX,
     "y": pointY,
     "attributes": att
    };
   });

was the object 'featureSet' was not declared as a the class featureSet.  Instead it was an object that contained the featureSet.

I edited your code to this, and it works for me:
queryTask.on("complete", function(results) {
   
   var inputInfo = {};
   inputInfo.data = arrayUtils.map(results.featureSet.features, function(feature) {
    var pointX = feature.geometry.x;
    var pointY = feature.geometry.y;
    var att = feature.attributes;
    return {
     "x": pointX,
     "y": pointY,
     "attributes": att
    };
   });
  
0 Kudos
firstlast1
New Contributor II
Yes, it does work for me as well. Brilliant! Thank you!
0 Kudos
WuxuanXiang
New Contributor
I have a relevant question regarding how to turn on/off the cluster layer. I would like the cluster layer to be turned off when map first loads, and to be turned on when a button click happens. I tried adding this line

clusterLayer.clear();

in

map.on("load", function() {
         
     origExtent=map.extent;
            var photos = esriRequest({
              "url": "data/GeocodeOutput_1_7_2014.json",
              "handleAs": "json"
            });
            photos.then(addClusters, error);
     initToolbar();
     clusterLayer.clear();
          });

however this does not turn off the cluster layer, but it results in the basemap fail to load. If I put this line in the button click function, it will remove the cluster layer,  however when the map extent changes, the cluster layer will be added back.

Is there a way to turn off the cluster layer when the map first loads (better remain off when map extent change), and turn the cluster layer back on a button click event?

Thanks in advance.
0 Kudos
ReneRubalcava
Frequent Contributor
You could use hide() when the map loads and show() on a button click.

I should also mention there has been some (non-esri) work recently to modify the ClusterLayer to work more like a FeatureLayer.
https://github.com/odoe/esri-clusterfeaturelayer