toJson method

Map<String, dynamic> toJson()

Converts the GeoJsonFeatureGeometry to a Map with keys 'type' and 'coordinates'.

The coordinates are converted to a List of Lists of Lists of 2 elements.

Implementation

Map<String, dynamic> toJson() {
  switch (internalType) {
    case GsonFeatureGeometryCoordinatesType.listList:
      return <String, dynamic>{
        'type': type,
        'coordinates': coordinates
            .map<List<List<double>>>(
              (List<ORSCoordinate> c) => c
                  .map<List<double>>(
                    (ORSCoordinate c) => c.toList(),
                  )
                  .toList(),
            )
            .toList(),
      };
    case GsonFeatureGeometryCoordinatesType.list:
      return <String, dynamic>{
        'type': type,
        'coordinates': coordinates
            .map<List<double>>(
              (List<ORSCoordinate> c) => c.first.toList(),
            )
            .toList(),
      };
    case GsonFeatureGeometryCoordinatesType.single:
      return <String, dynamic>{
        'type': type,
        'coordinates': coordinates.first.first.toList(),
      };
  }
}