Reputation: 672
I'm working on a map with WMS overlays and a lot of markers, my problem is when I try to calculate the average of points clustered, I've found how to differentiate the behaviour and the label text depending on the number of clustered elements, but I don't know how to reach the "val" value of every clustered point to calculate their average and show in the clustered point.
I think values are into features.cluster array (if I look into it with .toString() I get different numbers of [object][object],[object][object] etc), but I can't understand how to reach those values.
This is the context code:
context: {
val: function(feature) {
if(feature.attributes.count>1) {
[here I should show the average]
} else return feature.attributes.val;
},
[...]
And this is just some from the OpenLayers.Style code:
var pointStyle = new OpenLayers.Style({
strokeWidth: "${strokeFunction}",
fillColor: "${fillFunction}",
label: "${val}",
[...]
Don't think it's needed, but this is the point code where I set the val variable:
[...]
var pointFeature = new OpenLayers.Feature.Vector(point);
pointFeature.attributes = {
val: mks[i].m,
align: "cm"
};
(mks[i].m is the value I get from a JSON array, it's a number with decimals)
I really appreciate any help you can provide, Alberto
Upvotes: 0
Views: 132
Reputation: 672
I've been answered on gis.stackexchange,
this is the link: https://gis.stackexchange.com/questions/79788/openlayers-get-clustered-points-val
This is what I needed (treating feature.cluster[i].attributes as an array):
var sumValue = 0;
for (var i=0; i<feature.cluster.length; i++) {
sumValue += feature.cluster[i].attributes['val'];
}
var averageValue = sumValue/feature.cluster.length;
return averageValue;
Thanks to Mingfeng
Upvotes: 0