build<T extends Geometry> static method
FeatureCollection<Feature<T> >
build<T extends Geometry>(
- WriteFeatures features, {
- int? count,
- Box? bounds,
- Map<
String, dynamic> ? custom,
Builds a feature collection from the content provided by features
.
Feature items on a collection have an optional primary geometry of T
.
Only Feature items of Feature<T>
provided by features
are built,
any other objects are ignored.
An optional expected count
, when given, specifies the number of feature
objects in the content. Note that when given the count MUST be exact.
An optional bounds
can used set a minimum bounding box for a feature
collection.
Use an optional custom
parameter to set any custom or "foreign member"
properties.
Examples:
// a feature collection with two features
FeatureCollection.build(
count: 2,
(feat) => feat
// a feature with an id and a point geometry (2D coordinates)
..feature(
id: '1',
geometry: (geom) => geom.point([10.0, 20.0].xy),
)
// a feature with properties and a line string geometry (3D)
..feature(
geometry: (geom) => geom.lineString(
// three (x, y, z) positions
[10.0, 20.0, 30.0, 12.5, 22.5, 32.5, 15.0, 25.0, 35.0]
.positions(Coords.xyz),
),
// properties for a feature containing JSON Object like data
properties: {
'textProp': 'this is property value',
'intProp': 10,
'doubleProp': 29.5,
'arrayProp': ['foo', 'bar'],
},
),
);
Implementation
static FeatureCollection<Feature<T>> build<T extends Geometry>(
WriteFeatures features, {
int? count,
Box? bounds,
Map<String, dynamic>? custom,
}) {
// NOTE: use optional count to create a list in right size at build start
// build any feature items on a list
final list =
FeatureBuilder.buildList<Feature<T>, T>(features, count: count);
// create a feature collection with features and optional custom props
return FeatureCollection<Feature<T>>(
list,
custom: custom,
bounds: bounds,
);
}