toGeoJsonWithExtentCalculated<T extends GeoJson<Geometry> > method
T?
toGeoJsonWithExtentCalculated<T extends GeoJson<Geometry> >({})
Get GeoJson data from this feature
x0, y0, size: is tile numbers and tile zoom that already calculated with layer extent x0, y0, size was used to calculate lon/lat pairs
Return generic GeoJson type, there are two ways to to read data returned from this method:
- Explicit given a generic type:
var geojson = feature.toGeoJson<GeoJsonPoint>(3262, 1923, 12); var coordinates = geojson.geometry.coordinates;
- Cast to specific GeoJson type after got returned data:
var geojson = feature.toGeoJson(3262, 1923, 12); var coordinates = (geojson as GeoJsonPoint).geometry.coordinates;
Implementation
T? toGeoJsonWithExtentCalculated<T extends GeoJson>(
{required int x0, required int y0, required int size}) {
if (this.geometry == null) {
this.decodeGeometry();
}
switch (this.geometryType) {
case GeometryType.Point:
(this.geometry as GeometryPoint).coordinates = this._projectPoint(
size, x0, y0, (this.geometry as GeometryPoint).coordinates);
return GeoJsonPoint(
geometry: this.geometry,
properties: this.properties,
) as T;
case GeometryType.MultiPoint:
(this.geometry as GeometryMultiPoint).coordinates = this._project(
size, x0, y0, (this.geometry as GeometryMultiPoint).coordinates);
return GeoJsonMultiPoint(
geometry: this.geometry,
properties: this.properties,
) as T;
case GeometryType.LineString:
(this.geometry as GeometryLineString).coordinates = this._project(
size, x0, y0, (this.geometry as GeometryLineString).coordinates);
return GeoJsonLineString(
geometry: this.geometry,
properties: this.properties,
) as T;
case GeometryType.MultiLineString:
(this.geometry as GeometryMultiLineString).coordinates =
(this.geometry as GeometryMultiLineString)
.coordinates
.map((line) => this._project(size, x0, y0, line))
.toList(growable: false);
return GeoJsonMultiLineString(
geometry: this.geometry,
properties: this.properties,
) as T;
case GeometryType.Polygon:
(this.geometry as GeometryPolygon).coordinates =
(this.geometry as GeometryPolygon)
.coordinates
.map((line) => this._project(size, x0, y0, line))
.toList(growable: false);
return GeoJsonPolygon(
geometry: this.geometry,
properties: this.properties,
) as T;
case GeometryType.MultiPolygon:
(this.geometry as GeometryMultiPolygon).coordinates =
(this.geometry as GeometryMultiPolygon)
.coordinates!
.map((polygon) => polygon
.map((ring) => this._project(size, x0, y0, ring))
.toList(growable: false))
.toList(growable: false);
return GeoJsonMultiPolygon(
geometry: this.geometry,
properties: this.properties,
) as T;
default:
}
return null;
}