I would like to create geodesic polygons in openlayers. This is not the same as this question although VERY similar.
Geographika was able to do it but his solution is based on a circle. I'm interested in creating polygons that aren't necessarily circles, such as squares. Or maybe even a line.
Anyone know of any javascript snippet that might convert my geometric openlayers polygons to geodesic ones?
Google Maps has the Geodesic:true property for its shapes. OpenLayers should definitely have it.
Best Answer
If you only have two points on a line you may have to create more vertices and then reproject these to EPSG:4326 and back again to create something similar to the Google example.
There is an OpenLayers example of Great Circle lines here. The source code for the algorithms is also online.
There is a getGeodesicArea function on OpenLayer polygons, and geometry collections. There is also a getGeodesicLength function. These algorithms are implemented based on the following (according to the docs):
Looking at the sourcecode it reprojects points to 4326, and then uses the OpenLayers.Util.distVincenty function to calculate the distance between points on the surface of an ellipsoid (the earth).
For polygons areas, the algorithm is in the LinearRing source, and uses the earth's radius of 6378137 and geometry to calculate the geodesic area.
The main problem I had with the circle was that I only had one reference coordinate, and there was no inbuilt way in OpenLayers to create a circle around this point apart from on a Cartesian plane. However with the OpenLayers.Util.distVincenty function it was relatively easy to calculate these.