toJson method

  1. @override
Map<String, dynamic> toJson()
override

Returns a GeoJSON representation of the MultiPolygon

Example:

MultiPolygon([
  [
    LinearRing([Coordinate(1, 2), Coordinate(3, 4), Coordinate(5, 6), Coordinate(1, 2)])
  ],
  [
    LinearRing([Coordinate(7, 8), Coordinate(9, 10), Coordinate(11, 12), Coordinate(7, 8)])
  ]
]).toJson(); // {'type': 'Feature', 'geometry': {'type': 'MultiPolygon', 'coordinates': [[[[1, 2], [3, 4], [5, 6], [1, 2]]], [[[7, 8], [9, 10], [11, 12], [7, 8]]]]}, 'properties': {}}

Implementation

@override
Map<String, dynamic> toJson() {
  return {
    'type': 'Feature',
    'geometry': {
      'type': 'MultiPolygon',
      'coordinates': coordinates
          .map((poly) =>
              poly.map((ring) => ring.coordinates.map((c) => c.toJson())))
          .toList()
    },
    'properties': properties,
  };
}