Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.8] Remove force center after view animation. #9542

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2023 Camptocamp SA
// Copyright (c) 2015-2024 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -65,6 +65,7 @@ import ngeoMapFeatureOverlayMgr from 'ngeo/map/FeatureOverlayMgr';
import storeMap from 'gmfapi/store/map';
import user, {UserState, loginMessageRequired} from 'gmfapi/store/user';
import i18next from 'i18next';
import {debounce} from 'gmf/misc/debounce2';

/**
* Application abstract controller.
Expand Down Expand Up @@ -137,14 +138,14 @@ export function AbstractAppController($scope, $injector, mobile) {
return newCenter;
};

// Fix the center on the WMTS grid on animation end
const originalViewSetHint = view.setHint;
view.setHint = (hint, value) => {
originalViewSetHint.call(view, hint, value);
if (hint === ViewHint.ANIMATING && value === -1) {
view.setCenter(view.getCenter());
}
};
/**
* Base OL view.setHint function.
* Keep it to be able to reset its normal behavior if wanted.
* @private
*/
this.originalViewSetHint = view.setHint;
// Be sure the center is aligned with the grid (anti-blur effect).
this.fixCenterOnGrid(view);

const map = new olMap(
Object.assign(
Expand Down Expand Up @@ -726,6 +727,26 @@ function getLayerByLabels(layers, labels) {
return null;
}

/**
* Fix the center on the WMTS grid on animation end.
* This could help to have a not blurred map, but without
* timeout (and with map.view.constrainResolution to true), the map
* could "jump around" slightly on zooming in/out quickly.
* @param {import ('ol/View').View} view an ol view.
* @private
*/
AbstractAppController.prototype.fixCenterOnGrid = function (view) {
const debounceSetCenter = debounce((view, hint, value) => {
if (hint === ViewHint.ANIMATING && value === -1) {
view.setCenter(view.getCenter());
}
}, 50);
view.setHint = (hint, value) => {
this.originalViewSetHint.call(view, hint, value);
debounceSetCenter(view, hint, value);
};
};

/**
* @param {string} lang Language code.
*/
Expand Down
Loading