Skip to content

Commit 7839465

Browse files
committed
fix: resolve bug in zoom functionality by introducing a dedicated method for updating view state through controller widget
1 parent 7debb0b commit 7839465

1 file changed

Lines changed: 31 additions & 28 deletions

File tree

js/app.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,13 @@ class ShelterAccessApp {
651651
* Zoom in functionality
652652
*/
653653
zoomIn() {
654-
console.log('Attempting to zoom in...');
655654
try {
656655
if (!this.deckgl) {
657656
console.error('Deck.gl instance not available');
658657
return;
659658
}
660659

661-
// Use the stored current view state instead of trying to get it from deck.gl
660+
// Use the stored current view state
662661
const currentViewState = this._currentViewState || this.deckgl.props.initialViewState;
663662
if (!currentViewState) {
664663
console.error('No current view state available');
@@ -668,26 +667,16 @@ class ShelterAccessApp {
668667
const currentZoom = currentViewState.zoom || 10.5;
669668
const newZoom = Math.min(currentZoom + 1, 19);
670669

671-
console.log(`Zooming from ${currentZoom} to ${newZoom}`);
672-
673670
const newViewState = {
674671
...currentViewState,
675672
zoom: newZoom,
676673
transitionDuration: 300,
677674
transitionEasing: t => t * t
678675
};
679676

680-
// Update the view state directly
681-
this.deckgl.setProps({ viewState: newViewState });
682-
683-
// Update our stored view state
684-
this._currentViewState = newViewState;
685-
this._currentZoom = newZoom;
677+
// Update view state temporarily while preserving controller functionality
678+
this._updateViewStateWithController(newViewState);
686679

687-
// Update scale bar
688-
this.updateScaleBar();
689-
690-
console.log('Zoom in successful');
691680
} catch (error) {
692681
console.error('Error during zoom in:', error);
693682
}
@@ -697,14 +686,13 @@ class ShelterAccessApp {
697686
* Zoom out functionality
698687
*/
699688
zoomOut() {
700-
console.log('Attempting to zoom out...');
701689
try {
702690
if (!this.deckgl) {
703691
console.error('Deck.gl instance not available');
704692
return;
705693
}
706694

707-
// Use the stored current view state instead of trying to get it from deck.gl
695+
// Use the stored current view state
708696
const currentViewState = this._currentViewState || this.deckgl.props.initialViewState;
709697
if (!currentViewState) {
710698
console.error('No current view state available');
@@ -714,26 +702,16 @@ class ShelterAccessApp {
714702
const currentZoom = currentViewState.zoom || 10.5;
715703
const newZoom = Math.max(currentZoom - 1, 7);
716704

717-
console.log(`Zooming from ${currentZoom} to ${newZoom}`);
718-
719705
const newViewState = {
720706
...currentViewState,
721707
zoom: newZoom,
722708
transitionDuration: 300,
723709
transitionEasing: t => t * t
724710
};
725711

726-
// Update the view state directly
727-
this.deckgl.setProps({ viewState: newViewState });
712+
// Update view state temporarily while preserving controller functionality
713+
this._updateViewStateWithController(newViewState);
728714

729-
// Update our stored view state
730-
this._currentViewState = newViewState;
731-
this._currentZoom = newZoom;
732-
733-
// Update scale bar
734-
this.updateScaleBar();
735-
736-
console.log('Zoom out successful');
737715
} catch (error) {
738716
console.error('Error during zoom out:', error);
739717
}
@@ -1772,6 +1750,31 @@ class ShelterAccessApp {
17721750
}
17731751

17741752

1753+
/**
1754+
* Update view state while preserving controller functionality
1755+
*/
1756+
_updateViewStateWithController(newViewState) {
1757+
// Update our internal state immediately
1758+
this._currentViewState = newViewState;
1759+
this._currentZoom = newViewState.zoom;
1760+
1761+
// Set the view state directly with transition
1762+
this.deckgl.setProps({
1763+
viewState: newViewState
1764+
});
1765+
1766+
// Update scale bar immediately
1767+
this.updateScaleBar();
1768+
1769+
// After transition completes, restore normal controller behavior
1770+
setTimeout(() => {
1771+
// Remove the explicit viewState to let controller take over again
1772+
this.deckgl.setProps({
1773+
viewState: undefined // This restores controller-managed view state
1774+
});
1775+
}, newViewState.transitionDuration || 300);
1776+
}
1777+
17751778
/**
17761779
* Handle viewport changes with minimal debouncing
17771780
*/

0 commit comments

Comments
 (0)