0

I'm trying to label a vector layer with clustered points in OpenLayers. When the feature is clustered I want to show the value of an attribute of all the features included in the cluster. I've tried to define my label as follows:

label: function(feature){if (feature.cluster) {
                 for(i=0;i<feature.cluster.length;i++)
                {label_array += feature.cluster[i].attributes.yacimiento;
                 label = label_array.toString();
                }
            }
          else{label=feature.attributes.yacimiento;}
      return label;
      }

... and the vector layer just doesn't work

BUT, if I do the same with

label_array = feature.cluster[i].attributes.yacimiento;

it works prefectly displaying only the last item of the cluster

I don't understand what's going on (I might be missing something obvious, for I have no programming skills)

1

A solution, in case anybody is interested:

label: function(feature){if (feature.cluster) {
        var label_array = new Array();
            for(i=0;i<feature.cluster.length;i++)
            { 
            label_array.push(feature.cluster[i].attributes.yacimiento);
            label = label_array.join("\n");
            }
        }
  else{label=feature.attributes.yacimiento;}
  return label;
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.