geomEach function

void geomEach(
  1. GeoJSONObject geoJSON,
  2. GeomEachCallback callback
)

Iterates over each geometry in geoJSON, calling callback on each iteration. Similar to Iterable.forEach

For example:

FeatureCollection featureCollection = FeatureCollection(
  features: [
    point1,
    point2,
    point3,
  ],
);
geomEach(featureCollection, (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
  someOperationOnEachPoint(currentGeometry);
});

Implementation

void geomEach(GeoJSONObject geoJSON, GeomEachCallback callback) {
  try {
    if (geoJSON is FeatureCollection) {
      _forEachGeomInFeatureCollection(geoJSON, callback);
    } else if (geoJSON is Feature) {
      _forEachGeomInFeature(geoJSON, callback, 0);
    } else if (geoJSON is GeometryObject) {
      _forEachGeomInGeometryObject(geoJSON, callback, {}, null, null, 0);
    } else {
      throw Exception('Unknown Geometry Type');
    }
  } on ShortCircuit {
    return;
  }
}