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

feat: zoom to map content on dashboard item resize #3440

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

BRaimbault
Copy link
Collaborator

@BRaimbault BRaimbault commented Jan 9, 2025

Implement: DHIS2-18641


Listen to 'resize' event on window and use map.fitBounds() when triggered.


Before:
image

After:
image

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Jan 9, 2025

🚀 Deployed on https://pr-3440.maps.netlify.dhis2.org

@dhis2-bot dhis2-bot temporarily deployed to netlify January 9, 2025 16:20 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify January 9, 2025 16:31 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify January 9, 2025 17:00 Inactive
@jenniferarnesen
Copy link
Collaborator

jenniferarnesen commented Jan 14, 2025

Entering fullscreen on dashboards looks good. I did notice that in normal dashboard mode, some maps (e.g. the one in upper left) don't have the exact same bounds as before.

After:
image
Before:
image

And I see the same problem in the maps app

image

@@ -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 })
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Collaborator

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 })

Copy link
Collaborator Author

@BRaimbault BRaimbault Jan 23, 2025

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!

image
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:

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:

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:

<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.

@jenniferarnesen
Copy link
Collaborator

jenniferarnesen commented Jan 14, 2025

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

@dhis2-bot dhis2-bot temporarily deployed to netlify January 21, 2025 16:21 Inactive
@BRaimbault
Copy link
Collaborator Author

BRaimbault commented Jan 24, 2025

Comment 1:

Entering fullscreen on dashboards looks good. I did notice that in normal dashboard mode, some maps (e.g. the one in upper left) don't have the exact same bounds as before.
After: #Image1#
Before: #Image2#

And I see the same problem in the maps app
#Image3#

Comment 2:

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

#Video#

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.

@BRaimbault BRaimbault closed this Jan 24, 2025
@BRaimbault BRaimbault reopened this Jan 24, 2025
@dhis2-bot dhis2-bot temporarily deployed to netlify January 24, 2025 08:39 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify January 24, 2025 15:49 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants