farmOS / farmOS-map

farmOS-map is an OpenLayers wrapper library designed for agricultural mapping needs. It can be used in any project that has similar requirements.
https://farmOS.github.io/farmOS-map
MIT License
39 stars 22 forks source link

Expose method for converting features to WKT and GeoJSON #172

Open paul121 opened 2 years ago

paul121 commented 2 years ago

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: https://github.com/farmOS/farmOS-map/blob/d3fcfc6790309775f4d242c5682822aff159eb07/src/control/Edit/Edit.js#L514-L521 GeoJson: https://github.com/farmOS/farmOS-map/blob/d3fcfc6790309775f4d242c5682822aff159eb07/src/control/Edit/Edit.js#L523-L531

paul121 commented 2 years ago

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.