Tamas Kosa
Tamas Kosa

Reputation: 352

leaflet count by featuretypes in featuregroup

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

Answers (1)

iH8
iH8

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

Related Questions