I'm trying to merge two functions that are displayed as OL's samples, the Advanced View Positioning and the View Animation. I can successfully change the view with the animation method, but I can't fix the zoom as in the Advanced View Postitioning method. I'm using these methods to change the view of some rasters loaded in OL. My problem is related only with the zoom level, how can I make it fit to the raster that I'm using? I believe that I need to get the raster extent (already did it) and somehow calculate and link to the zoom section in the flyTo()
function.
OL version: 5.3
Function I'm using for the animation:
//This is one of the locations I using with the View Animation method
var randomLocation = transform(getCenter([565280.904542, 6924581.621580, 565319.267400, 6924554.342636]), 'EPSG:31982', 'EPSG:3857');
function flyTo(location, done) {
var duration = 3000;
var zoom = view.getZoom();
var parts = 2;
var called = false;
function callback(complete) {
--parts;
if (called) {
return;
}
if (parts === 0 || !complete) {
called = true;
done(complete);
}
}
view.animate({
center: location,
duration: duration
}, callback);
view.animate({
zoom: zoom - 2,
duration: duration / 2
}, {
zoom: zoom,
duration: duration / 2
}, callback);
}
Some links that are related but did not help me (most of them use the fit(extent)
function. I tried to use it but it cancels the animate()
function):
- Open Layers 4 fit to extent zoom too much out
- https://stackoverflow.com/questions/49746970/openlayers-4-fit-to-extent-of-selected-features
- OpenLayers-3 setting zoom so layers fit in map window
- https://stackoverflow.com/questions/42369647/openlayers-animate-getview-fit
- https://stackoverflow.com/questions/49361669/openlayers-map-jitters-on-dynamic-centering-of-feature-movement-animation
- OpenLayers - Setting View Correctly Extent GEOJSon
- https://stackoverflow.com/questions/44763661/openlayers-fit-extent-with-bounce
- https://stackoverflow.com/questions/41190146/view-fit-using-view-animate-in-openlayers-3-20
- https://stackoverflow.com/questions/38291471/openlayers-3-zoom-map-to-coordinates-in-array
- View Animation of OpenLayers
location
you should fly to where the full map will be centered if location is centered in the padded area. An offset ofn
pixels on the screen isn * view.getResolution()
in map coordinates. You will needmap.getSize()
and the padding array to calculate the horizontal and vertical values for n.view.fit()
function. I wonder if it is not possible to do the same with a raster and apply in thisflyTo()
function.