Reputation: 352
Is there any way in leaflet to get the number of rectangles in a feature group? I know this code that work: drawnItems.getLayers().length;
but it counts all the objects within the drawnItems featuregroup. I only need the a specific type of features, for example rectangle
Upvotes: 1
Views: 458
Reputation: 28638
Iterate your group, check the instance of each layer and count:
var rectangleCount = 0;
drawnItems.eachLayer(function (layer) {
if (layer instanceof L.Rectangle) {
rectangleCount++;
}
});
Upvotes: 3