truncate function

GeoJSONObject truncate(
  1. GeoJSONObject geojson, {
  2. int precision = 6,
  3. int coordinates = 3,
  4. bool mutate = false,
})

Takes a Feature or FeatureCollection and truncates the precision of the geometry. precision sets the coordinate decimal precision coordinates sets the maximum number of coordinates (primarly used to remove z coordinates) mutate allows GeoJSONObject input to be mutated (significant performance increase if true) Returns GeoJSONObject layer with truncated geometry

Example:

var point = Point(coordinates: Position.of([
    70.46923055566859,
    58.11088890802906,
    1508
]));
var truncated = truncate(point, precision: 3, coordinates: 2);
//=truncated.geometry.coordinates => [70.469, 58.111]
//addToMap
var addToMap = [truncated];

Implementation

GeoJSONObject truncate(
  GeoJSONObject geojson, {
  int precision = 6,
  int coordinates = 3,
  bool mutate = false,
}) {
  GeoJSONObject geom = mutate ? geojson : geojson.clone();

  // Truncate Coordinates
  if (coordAll(geom).isNotEmpty) {
    _replaceCoords(precision, coordinates, geom);
    return geom;
  } else {
    return geom;
  }
}