0
votes

In OpenLayers 5, when getting the view extent using const extent = this.view.calculateExtent(this.map.getSize()) and then converting it to latLng using toLonLat() the result values are clamped (-180 to 180 for longitudes) if the map is at a very low zoom level.

Is there any way of avoiding this clamping, like for example using another projection, or another function?

1
You can use ol.proj.transform() or ol.proj.transformExtent() to transform to 'EPSG:4326'. Unlike toLonLat() they won't normalise the longitude.Mike

1 Answers

0
votes

I will answer myself. Looking at the code toLonLat() applies a transform equivalent to transform(coordinate, 'EPSG:3857', 'EPSG:4326') and then clamps the Longitude. So the answer is to use transform() instead of toLonLat(). Additionally, there is also a transformExtent() function.