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:
final geometryPoint = this.geometry as GeometryPoint;
geometryPoint.coordinates =
this._projectPoint(size, x0, y0, geometryPoint.coordinates);
return GeoJsonPoint(
geometry: geometryPoint,
properties: this.properties,
) as T;
case GeometryType.MultiPoint:
final geometryMultiPoint = this.geometry as GeometryMultiPoint;
geometryMultiPoint.coordinates =
this._project(size, x0, y0, geometryMultiPoint.coordinates);
return GeoJsonMultiPoint(
geometry: geometryMultiPoint,
properties: this.properties,
) as T;
case GeometryType.LineString:
final geometryLineString = this.geometry as GeometryLineString;
geometryLineString.coordinates =
this._project(size, x0, y0, geometryLineString.coordinates);
return GeoJsonLineString(
geometry: geometryLineString,
properties: this.properties,
) as T;
case GeometryType.MultiLineString:
final geometryLineString = this.geometry as GeometryMultiLineString;
geometryLineString.coordinates = geometryLineString.coordinates
.map((line) => this._project(size, x0, y0, line))
.toList(growable: false);
return GeoJsonMultiLineString(
geometry: geometryLineString,
properties: this.properties,
) as T;
case GeometryType.Polygon:
final geometryPolygon = this.geometry as GeometryPolygon;
geometryPolygon.coordinates = geometryPolygon.coordinates
.map((line) => this._project(size, x0, y0, line))
.toList(growable: false);
return GeoJsonPolygon(
geometry: geometryPolygon,
properties: this.properties,
) as T;
case GeometryType.MultiPolygon:
final geometryMultiPolygon = this.geometry as GeometryMultiPolygon;
geometryMultiPolygon.coordinates = geometryMultiPolygon.coordinates
?.map((polygon) => polygon
.map((ring) => this._project(size, x0, y0, ring))
.toList(growable: false))
.toList(growable: false);
return GeoJsonMultiPolygon(
geometry: geometryMultiPolygon,
properties: this.properties,
) as T;
default:
}
return null;
}