toGeoJSON method

Map<String, Object?> toGeoJSON()

Implementation

Map<String, Object?> toGeoJSON() {
  final Map<String, Object?> output = <String, Object?>{
    "type": "FeatureCollection",
    "features": <dynamic>[],
  };
  final List<dynamic> data2 = data['features'] as List<dynamic>;
  final int fl = data2.length;
  int i = 0;
  while (fl > i) {
    final Map<String, dynamic> ft =
        data['features'][i] as Map<String, dynamic>;
    /* as only ESRI based products care if all the features are the same type of geometry, check for geometry type at a feature level*/
    final Map<String, Object?> outFT = <String, Object?>{
      "type": "Feature",
      "properties": _prop(ft['attributes'] as Map<String, dynamic>),
    };
    final Map<String, dynamic> geometry =
        ft['geometry'] as Map<String, dynamic>;
    if (geometry['x'] != null) {
      //check if it's a point
      outFT['geometry'] = _point2D(geometry);
    } else if (geometry['points'] != null) {
      //check if it is a multipoint
      outFT['geometry'] = _points2D(geometry);
    } else if (geometry['paths'] != null) {
      //check if a line (or "ARC" in ESRI terms)
      outFT['geometry'] = _line2D(geometry);
    } else if (geometry['rings'] != null) {
      outFT['geometry'] = _polygon(geometry);
    }
    final List<dynamic> outPut2 = output['features'] as List<dynamic>;
    outPut2.add(outFT);
    i++;
  }
  Console.log('outPut = ${json.encode(output)}');
  return output;
}