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!
Transforming coordinates of feature in openlayers
Asked Answered
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.
Thanks! That is the solution. –
Miller
Great, glad that worked for you. Could you mark the answer as 'accepted'? This help other users know that the question is solved, which makes it more useful. –
Hunch
© 2022 - 2024 — McMap. All rights reserved.