featuresFromGeoJsonMainThread function Null safety

Future<GeoJsonFeatureCollection> featuresFromGeoJsonMainThread(
  1. String data,
  2. {String? nameProperty,
  3. bool verbose = false}
)

Get a feature collection from a geojson string using a parser in the main thread, without isolates: necessary for the web

Implementation

Future<GeoJsonFeatureCollection> featuresFromGeoJsonMainThread(String data,
    {String? nameProperty, bool verbose = false}) async {
  final featureCollection = GeoJsonFeatureCollection();
  final geojson = GeoJson();
  geojson.endSignal.listen((_) => geojson.dispose());
  try {
    await geojson.parseInMainThread(data,
        nameProperty: nameProperty, verbose: verbose);
  } catch (e) {
    rethrow;
  }
  geojson.features.forEach((f) {
    if (verbose) {
      print("Feature: ${f.type}");
    }
    featureCollection.collection.add(f);
  });
  return featureCollection;
}