isCollectionOf method

bool isCollectionOf(
  1. String type
)

Returns whether all the Features in the FeatureCollection are of the specified type. If the FeatureCollection is empty, returns false. If the type is not a valid geometry type, returns false.

Example:

FeatureCollection([

Implementation

bool isCollectionOf(String type) {
  if (![
    Point.type,
    MultiPoint.type,
    LineString.type,
    MultiLineString.type,
    Polygon.type,
    MultiPolygon.type
  ].contains(type)) {
    return false;
  } else if (isEmpty) {
    return false;
  }

  switch (type) {
    case 'Point':
      return features.every((f) => f is Point);
    case 'MultiPoint':
      return features.every((f) => f is MultiPoint);
    case 'LineString':
      return features.every((f) => f is LineString);
    case 'MultiLineString':
      return features.every((f) => f is MultiLineString);
    case 'Polygon':
      return features.every((f) => f is Polygon);
    case 'MultiPolygon':
      return features.every((f) => f is MultiPolygon);
    default:
      return false;
  }
}