-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: zoom to map content on dashboard item resize #3440
base: master
Are you sure you want to change the base?
Conversation
🚀 Deployed on https://pr-3440.maps.netlify.dhis2.org |
src/components/map/Map.js
Outdated
@@ -74,6 +74,9 @@ class Map extends Component { | |||
if (isPlugin) { | |||
map.toggleMultiTouch(true) | |||
map.on('fullscreenchange', this.onFullscreenChange) | |||
window.addEventListener('resize', () => { | |||
this.onFullscreenChange(map, { isFullscreen: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will isFullscreen
always be true? I guess that means that the window resize
event only triggers when entering FS, and not leaving FS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, line 78 is not calling the function with the correct params. Since it is calling the component's own onFullscreenChange
(not the one in util/map), then `isFullscreen is always false since the functions args don't match up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure how this is working, but I think what you want is:
this.onFullscreenChange({ isFullscreen: false })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First thing is, you are right, it should have been: this.onFullscreenChange({ isFullscreen: false })
And I investigated a little more!
Above is the button triggering the fullscreenchange
event. The prop isFullscreen
is true
when you switch to fullscreen and false
when you go back to normal mode.
I believe the button is hidden in all scenario where map is used in plugin, so the event listener defined below never gets triggered:
maps-app/src/components/map/Map.js
Lines 74 to 82 in b781ff3
if (isPlugin) { | |
map.toggleMultiTouch(true) | |
map.on('fullscreenchange', this.onFullscreenChange) | |
window.addEventListener('resize', () => { | |
this.onFullscreenChange(map, { isFullscreen: true }) | |
}) | |
} else { | |
map.on('contextmenu', this.onRightClick, this) | |
} |
Next place onFullscreenChange
is used is here:
maps-app/src/components/map/Map.js
Lines 125 to 136 in b781ff3
componentDidUpdate(prevProps) { | |
const { resizeCount, isFullscreen, isPlugin } = this.props | |
if (resizeCount !== prevProps.resizeCount) { | |
this.map.resize() | |
} | |
// From map plugin resize method | |
if (isPlugin && isFullscreen !== prevProps.isFullscreen) { | |
onFullscreenChange(this.map, isFullscreen) | |
} | |
} |
The thing is, isFullscreen
property is set to false
for plugins and never changes, so it is never used either:
maps-app/src/components/plugin/Map.js
Lines 126 to 135 in b781ff3
<MapView | |
isPlugin={true} | |
isFullscreen={false} | |
basemap={basemap} | |
layers={layers.current} | |
controls={controls} | |
bounds={defaultBounds} | |
openContextMenu={setContextMenu} | |
resizeCount={resizeCount} | |
/> |
It looks like I can try to clean things up a little, and if resizeCount
gets updated properly, I may be able to use onFullscreenChange
in componentDidUpdate
instead of adding the event listener. Let's see tomorrow.
Here you can see that the correct size briefly flashes before it is changed to too large. So it is sizing initially to the org unit bounds, and then resizing to the thematic layer bounds. But regardless, this is not due to this PR and should be looked at separaytely brief.size.correction.mov |
Comment 1:
Comment 2:
I believe what is happening is layers get loaded one by one (from top to bottom in the layer's panel) and the map is fitted to the layer's bounding box each time. As discussed, this is not a behavior affected by the PR. |
Implement: DHIS2-18641
Listen to 'resize' event on window and use map.fitBounds() when triggered.
Before:
After: