1

There are several feature how to grouped into categories depending on the feature?

id : "1" 
lat : 88.777 
lon : 88.777 
name : "Name company 1" 
cat_id: "12" 

id : "2" 
lat : 77.777 
lon : 77.777 
name : "Name company 2" 
cat_id: "30" 

id : "3" 
lat : 99.777 
lon : 99.777 
name : "Name company 3" 
cat_id: "12" 

cat_id = name category

There are several features how grouped by category? Depending on the category feature.

the logic of something like that:

if(value['Category'] == '12'){ 
 //put feature in a group of 12
} 
else if(value['Category'] == '30'){ 
 //put feature in a group of 30
}
2
  • It is not clear for me what did you mean, please describe your task more precisely.
    – drnextgis
    Commented Nov 6, 2016 at 3:06
  • @Drnextgis I unfortunately do not know the English language. Sorry. I need to group or add to the collection by category(cat_id) features Commented Nov 6, 2016 at 18:39

1 Answer 1

1

Example of iterating through vector layer's features:

var groups = {};

layer.getSource().forEachFeature(function (feature) {
    var cat_id = feature.getProperties().cat_id;
    groups[cat_id] = groups[cat_id] || [];
    groups[cat_id].push(feature);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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