lineSegment function

FeatureCollection<LineString> lineSegment(
  1. GeoJSONObject geoJson, {
  2. bool combineGeometries = false,
})

Creates a FeatureCollection of 2-vertex LineString segments from a LineString or MultiLineString or Polygon and MultiPolygon Returns FeatureCollection<LineString> 2-vertex line segments For example:

var polygon = Polygon.fromJson({
    'coordinates': [
      [
        [0, 0],
        [1, 1],
        [0, 1],
        [0, 0],
      ],
    ];
var segments = lineSegment(polygon);
//addToMap
var addToMap = [polygon, segments]

Implementation

FeatureCollection<LineString> lineSegment(GeoJSONObject geoJson,
    {bool combineGeometries = false}) {
  List<Feature<LineString>> features = [];
  segmentEach(
    geoJson,
    (currentSegment, featureIndex, multiFeatureIndex, geometryIndex,
        segmentIndex) {
      features.add(currentSegment);
    },
    combineNestedGeometries: combineGeometries,
  );
  return FeatureCollection(features: features);
}