getCoords function

List getCoords(
  1. dynamic coords
)

Unwraps coordinates from a Feature, GeometryObject or a List Gets a List<dynamic>, GeometryObject or a Feature or a List<dynamic> and returns List<dynamic>. For example:

var polygon = Polygon(coordinates: [
   [
    Position(119.32, -8.7),
    Position(119.55, -8.69),
    Position(119.51, -8.54),
    Position(119.32, -8.7)
    ]
 ]);

var coords = getCoords(poly);
/* [[Position(119.32, -8.7),
 Position(119.55, -8.69),
 Position(119.51, -8.54),
 Position(119.32, -8.7)]] */

Implementation

List<dynamic> getCoords(dynamic coords) {
  if (coords == null) {
    throw Exception("coords is required");
  }

  if (coords is List) {
    return coords;
  }

  if (coords is Feature && coords.geometry != null) {
    return _getCoordsForGeometry(coords.geometry!);
  }

  if (coords is GeometryObject) {
    return _getCoordsForGeometry(coords);
  }

  throw Exception(
      "Parameter must be a List<dynamic>, Geometry, Feature. coords Feature, Geometry Object or a List");
}