Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transforming coordinates of feature in openlayers

I want to transform the coordinates for an entire feature in openlayers. I have had success using ol.proj.transform to transform a single coordinate to a different projection, but is there any function that you can feed an entire feature, and all the coordinates within that feature will be transformed to the desired projection? Thanks in advance for any help you can provide!

like image 576
Stephen Fricke Avatar asked Mar 21 '16 15:03

Stephen Fricke


1 Answers

I think you need ol.geom.Geometry.transform

If you have your feature, then you can do:

src = 'EPSG:3857'
dest = 'EPSG:4326'
feature.getGeometry().transform(src, dest)

The docs are here:

http://openlayers.org/en/latest/apidoc/module-ol_geom_Geometry-Geometry.html#transform

If you do not want the geometry modified in place, first clone() it and then use this function on the clone.

like image 187
sifriday Avatar answered Jan 02 '23 23:01

sifriday