Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outFields values #6

Open
dhunink opened this issue Apr 12, 2014 · 4 comments
Open

outFields values #6

dhunink opened this issue Apr 12, 2014 · 4 comments

Comments

@dhunink
Copy link

dhunink commented Apr 12, 2014

To be honest i'm not completely sure if this is really a bug/issue; perhaps i'm misinterpreting something....

When the fields are outputted and grouped as a cluster, they do not get a correct value. Instead of an array of unique values or a sum of alle values (when numeric), the value of the last point that's added to the cluster is given as value.

For example, let's say in choose a extra outField called FATALITIES. When the clusters are created, and we're looping over them, the clusterCount field works perfect and shows the exact number (sum) of points that's inside the cluster. But the FATALITIES field has the value of the latest point that was added in the cluster. Therefore, and since the features are only present as graphics, it is impossible to do any calculations with the fields, other then with the clusterCount field.

So in the example below the clusterCount will return a total of almost 80.000, which equals almost 80.000 that occurred in Africa between 1997 and 2012. But the fatality count will give a very low number in the range of hundreds; unfortunalty a lot more people died due tot those 80.000 conflicts.

var ext = map.extent;
var features = [];
var conflictCount = 0;
var fatalitiesCount = 0;

for (var i = 0; i < clusterLayer.graphics.length; i++) {
var gra = clusterLayer.graphics[i];
if (ext.intersects(gra.geometry)) {
features.push(gra);
}
for (var i = 0; i< features.length; i++){
conflictCount += features[i].attributes.clusterCount;
fatalitiesCount += features[i].attributes.FATALITIES;
}
console.log(conflictCount+' '+fatalitiesCount);
}

@odoe
Copy link
Owner

odoe commented Apr 12, 2014

That's difficult to do with the clustered graphic, but there is an array property called _clusterData on the layer that has each individual graphic with attriubtes and an added field called clusterId that tells you which cluster it is a part of. That might help you to better do the calculations. I'll look into removing the native attributes from the cluster graphic because as you've said, it may cause some confusion, it was kind of sloppy on my part.

Thanks.

@dhunink
Copy link
Author

dhunink commented Apr 12, 2014

This did indeed make stuff works!

clusterLayer.on("clusters-shown", countAttributes);

  function countAttributes(features){
      //Calculate fatalitites and since l is the number of points, it's also the number of conflicts
      var fatalitiesCount = 0;
      for(var l = 0; l < clusterLayer._clusterData.length; l++){
        //console.log(clusterLayer._clusterData[l].attributes.FATALITIES);
        fatalitiesCount += clusterLayer._clusterData[l].attributes.FATALITIES;
      }
      document.getElementById("counter0").innerHTML = l;
      document.getElementById("counter1").innerHTML = fatalitiesCount;
  } 

I did saw that the graphics layer as a 'attributes' field which is empty, wouldn't that be a more logical place to store things, which makes it easier for coders to find?

@odoe
Copy link
Owner

odoe commented Apr 13, 2014

This actually gave me an idea to also add a new event called cluster-click that will return all graphics that make up a cluster when a cluster graphic is clicked. 7b149b3

@dhunink
Copy link
Author

dhunink commented Apr 13, 2014

Super cool!
I do still believe that some kind of statistics would be very helpful. If you take a look at https://github.com/Esri/summary-viewer-template, I believe the way they give options to provide statistics on fields is pretty straight forward and doable. Providing that option would really give this cluster layer a extra feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants