Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose method for converting features to WKT and GeoJSON #172

Open
paul121 opened this issue Jul 20, 2022 · 1 comment
Open

Expose method for converting features to WKT and GeoJSON #172

paul121 opened this issue Jul 20, 2022 · 1 comment

Comments

@paul121
Copy link
Member

paul121 commented Jul 20, 2022

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);
}

@paul121
Copy link
Member Author

paul121 commented Jul 20, 2022

unless using the edit behavior.

I don't need the edit behavior for my use-case because I don't need the user to manipulate geometries in the map. Instead, I'm loading a GeoJSON layer of property boundaries and asking the user to select which boundaries they want to import. I need to collect the geometries of selected features when submitting the form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant