Im using openlayers 6, on mounted I use map().getView().fit(extent) for some reason on every refresh the zoom level is higher. any tips how to fix this?
Before using .fit(extent) I have to transformExtent to change projection from 5514 to 3857
this.map().setView(new View({
projection: 'EPSG:3857',
center: fromLonLat([50.075710, 14.472606]),
zoom: 10,
enableRotation: false
}))
extent = transformExtent(extent, 'EPSG:5514', this.map().getView().getProjection().getCode())
this.map().getView().fit(extent)
my problem is with map.getview.fit here is my code and here are the returned values coordinates after view.fit are a bit different
console.log(transformedExtent)
this.map().getView().fit(transformedExtent, this.map().getSize())
console.log(this.map().getView().calculateExtent(this.map().getSize()))
before fit:
after fit:
You are using the same variable for the EPSG:5514 and EPSG:3857 extents so presumably corrupting the original EPSG:5514 you want to use. Using a separate variable should solve the problem.
const transformedExtent = transformExtent(extent, 'EPSG:5514', this.map().getView().getProjection().getCode())
this.map().getView().fit(transformedExtent)
Asked about this problem directly on openlayers github and it is expected behavior. https://github.com/openlayers/openlayers/issues/13503