Similar to #171. Right now there is no way to return the geometry of feature(s) in a usable WKT or GeoJSON format unless using the edit behavior. You can get a simple array of coordinates for a feature using layer.getSource().getFeatureById(id).getGeometry().getCoordinates(); which is fine for Point geometries but less convenient for Polygon and other more complex geometries.
Because the edit control already has functions for this perhaps this could be easier to expose than my request in #171. I think the only consideration is if & how we export these functions and what impact it will have on the bundle size(s). I believe this would require including the openalyers WKT and GeoJSON classes which could be quite large.
WKT:
|
/** |
|
* Getter that returns the geometry of all features in the drawing layer in |
|
* Well Known Text (WKT) format. |
|
* @api |
|
*/ |
|
getWKT() { |
|
return new WKT().writeFeatures(this.getFeatures(), projection); |
|
} |
GeoJson:
|
/** |
|
* Getter that returns the geometry of all features in the drawing layer in |
|
* GeoJSON format. |
|
* @api |
|
*/ |
|
getGeoJSON() { |
|
const features = this.layer.getSource().getFeatures(); |
|
return new GeoJSON().writeFeatures(features, projection); |
|
} |
Similar to #171. Right now there is no way to return the geometry of feature(s) in a usable WKT or GeoJSON format unless using the edit behavior. You can get a simple array of coordinates for a feature using
layer.getSource().getFeatureById(id).getGeometry().getCoordinates();which is fine forPointgeometries but less convenient forPolygonand other more complex geometries.Because the
editcontrol already has functions for this perhaps this could be easier to expose than my request in #171. I think the only consideration is if & how we export these functions and what impact it will have on the bundle size(s). I believe this would require including the openalyersWKTandGeoJSONclasses which could be quite large.WKT:
farmOS-map/src/control/Edit/Edit.js
Lines 514 to 521 in d3fcfc6
GeoJson:
farmOS-map/src/control/Edit/Edit.js
Lines 523 to 531 in d3fcfc6