featureEach function

void featureEach(
  1. GeoJSONObject geoJSON,
  2. FeatureEachCallback callback
)

Iterates over features in any geoJSONObject, calling callback on each iteration. Similar to Iterable.forEach. For example:

FeatureCollection featureCollection = FeatureCollection(
  features: [
    point1,
    point2,
    point3,
  ],
);
featureEach(featureCollection, (currentFeature, featureIndex) {
  someOperationOnEachFeature(currentFeature);
});

Implementation

void featureEach(GeoJSONObject geoJSON, FeatureEachCallback callback) {
  if (geoJSON is Feature) {
    callback(geoJSON, 0);
  } else if (geoJSON is FeatureCollection) {
    for (var i = 0; i < geoJSON.features.length; i++) {
      if (callback(geoJSON.features[i], i) == false) break;
    }
  } else {
    throw Exception('Unknown Feature/FeatureCollection Type');
  }
}