8000 Migrate map rendering from Leaflet to MapLibre GL by muimsd · Pull Request #673 · gramps-project/gramps-web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate map rendering from Leaflet to MapLibre GL #673

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

Merged

Conversation

muimsd
Copy link
@muimsd muimsd commented Jun 6, 2025

Description: This pull request migrates the map rendering engine from Leaflet to MapLibre GL. It updates all relevant components, utilities, and dependencies to support MapLibre GL, providing improved performance, vector map rendering, and enhanced interactivity.

Key changes:

Replaced Leaflet map components and utilities with MapLibre GL equivalents
Updated dependencies and configuration files to remove Leaflet and add MapLibre GL
Refactored custom map logic as needed to support the new rendering engine

muimsd added 2 commits June 5, 2025 16:53
- Removed Leaflet dependencies and related code from GrampsjsMap, GrampsjsMapMarker, and GrampsjsMapOverlay components.
- Integrated MapLibre GL for map rendering and marker management.
- Updated map style switching functionality to support MapLibre GL styles.
- Enhanced marker and overlay handling using MapLibre GL's API.
- Updated package dependencies to use MapLibre GL version 5.6.0 and removed obsolete packages.
@Copilot Copilot AI review requested due to automatic review settings June 6, 2025 12:44
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request migrates the map rendering functionality from Leaflet to MapLibre GL, eliminating legacy Leaflet dependencies and updating components to work with the new engine. Key changes include:

  • Replacing Leaflet components (map overlay, marker) with MapLibre GL implementations.
  • Updating the main map component to initialize a MapLibre GL map with new controls and style switcher.
  • Adjusting dependency versions and removing obsolete styles and packages.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/components/GrampsjsMapOverlay.js Removed Leaflet image overlay and replaced with MapLibre GL image source/layer
src/components/GrampsjsMapMarker.js Migrated marker creation from Leaflet to MapLibre GL using a custom SVG element
src/components/GrampsjsMap.js Updated map initialization, controls, and style switching for MapLibre GL
package.json Removed Leaflet and related types; updated maplibre-gl dependency
L.Control.Locate.min.css Removed obsolete CSS for Leaflet locate control
Comments suppressed due to low confidence (2)

src/components/GrampsjsMapOverlay.js:43

  • [nitpick] Consider using String.slice instead of substr as it is more standardized and future-proof.
const id = `overlay-${this.title || 'image'}-${Math.random().toString(36).substr(2, 9)}`

src/components/GrampsjsMap.js:120

  • Ensure that reversing the coordinate order from [lat, lng] to [lng, lat] aligns with MapLibre GL's expected format.
this._map.fitBounds([
          [this.longMin, this.latMin],
          [this.longMax, this.latMax],
        ])

@DavidMStraub
Copy link
Member

Great work @muimsd, thank you!

I tested it with the dev container and see only problem: when I open the map view, the map markers are not shown and the map is not automatically panned/zoomed to the center of the pins.

Now:

grafik

Before:

grafik

Can you please have a look? If this is fixed, I think this is ready! 🚀

@DavidMStraub
Copy link
Member

Sorry, I noticed some other issues.

  1. in pages where the map is not full screen, the layer switcher is fixed to the bottom left of the initial scroll position rather than to the bottom left of the map container, which means it is outside of the map:

grafik

grafik

  1. The map overlays are not working. Example: this image
    849a8142923dbc59e0a6955274719941

with the following attribute:

key: map:bounds
value: [[47.97329637715443,8.539969156741263],[47.99024202594273,8.575052170287895]]

Before:

grafik

After:

grafik

Notice also that in the old implementation, the image was added to the layer switcher if the image was within the viewport.

I'm afraid these are showstoppers as we need those features also in the new world. It would be great if you can get this to the finish line. Thanks!

@DavidMStraub
Copy link
Member

Some more observation: after a while (sometimes) the map overlay appears, but it is mirrored upside-down 🤔

grafik

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@DavidMStraub
Copy link
Member

Hi, I checked again and sometimes the pins showed up on the map, sometimes not. I think it's because of an error that piles up in the browser console:

grafik

Whenever that error occurs, obviously it will not process the rest and not display the pins. My guess is that bounds._southWest is a Leaflet-specific property.

Indeed, if I remove the problematic code from _isLayerVisible, the pins display correctly. (However, we can't just remove the code, we need to port it.)

Regarding the overlay, I get a different error:

grafik

@muimsd
Copy link
Author
muimsd commented Jun 8, 2025

Great work @muimsd, thank you!

I tested it with the dev container and see only problem: when I open the map view, the map markers are not shown and the map is not automatically panned/zoomed to the center of the pins.

Now:

grafik

Before:

grafik

Can you please have a look? If this is fixed, I think this is ready! 🚀

It is completely working on my side.
image

@muimsd
Copy link
Author
muimsd commented Jun 8, 2025

Sorry, I noticed some other issues.

  1. in pages where the map is not full screen, the layer switcher is fixed to the bottom left of the initial scroll position rather than to the bottom left of the map container, which means it is outside of the map:

grafik

grafik

  1. The map overlays are not working. Example: this image
    849a8142923dbc59e0a6955274719941

with the following attribute:

key: map:bounds value: [[47.97329637715443,8.539969156741263],[47.99024202594273,8.575052170287895]]

Before:

grafik

After:

grafik

Notice also that in the old implementation, the image was added to the layer switcher if the image was within the viewport.

I'm afraid these are showstoppers as we need those features also in the new world. It would be great if you can get this to the finish line. Thanks!

Please reply page URL to test it.

@muimsd
Copy link
Author
muimsd commented Jun 8, 2025

Some more observation: after a while (sometimes) the map overlay appears, but it is mirrored upside-down 🤔

grafik

Please send me the complete video with the browser window to see the actual route URL to track this issue, and also add the developer tool window of the browser to see console errors.

@DavidMStraub
Copy link
Member
Bildschirmaufnahme.2025-06-09.21.42.05.mp4

@DavidMStraub
Copy link
Member

Note: you need to add at least one image overlay (i.e. an image with a map:bounds attribute) to see this error, as otherwise _isVisible is never called, as you can see in the map in _renderMapLayer.

@DavidMStraub
Copy link
Member

See the comment above #673 (comment) for how to test map overlays.

  1. Download the image
  2. In the frontend, click the + in the upper right corner to add a new media object, select the image from your hard drive, click "add"
  3. In the media object view, click edit (pencil bottom right)
  4. Go to "attributes" and at an attribute with key map:bounds and value [[47.97329637715443,8.539969156741263],[47.99024202594273,8.575052170287895]]

@muimsd
Copy link
Author
muimsd commented Jun 10, 2025

Bildschirmaufnahme.2025-06-09.21.42.05.mp4

In this video GrampsjsViewMap.js file has an error, which is a view. You did not mention this file to change.

@muimsd
Copy link
Author
muimsd commented Jun 10, 2025

More errors are coming from different map files.
image

@muimsd
Copy link
Author
muimsd commented Jun 10, 2025

See the comment above #673 (comment) for how to test map overlays.

  1. Download the image
  2. In the frontend, click the + in the upper right corner to add a new media object, select the image from your hard drive, click "add"
  3. In the media object view, click edit (pencil bottom right)
  4. Go to "attributes" and at an attribute with key map:bounds and value [[47.97329637715443,8.539969156741263],[47.99024202594273,8.575052170287895]]

I have resolved this issue.
image

@DavidMStraub
Copy link
Member

Cool, thanks! The pins work now, but I still get the "Style is not done loading" both in Firefox and in Chrome, I think it is because the layer is added before the map is fully loaded:

https://stackoverflow.com/questions/40557070/style-is-not-done-loading-mapbox-gl-js
mapbox/mapbox-gl-js#9779

@muimsd
Copy link
Author
muimsd commented Jun 10, 2025

Cool, thanks! The pins work now, but I still get the "Style is not done loading" both in Firefox and in Chrome, I think it is because the layer is added before the map is fully loaded:

https://stackoverflow.com/questions/40557070/style-is-not-done-loading-mapbox-gl-js mapbox/mapbox-gl-js#9779

It will be great if you share a short screen recording.
Thank you!

@DavidMStraub
Copy link
Member
Bildschirmaufnahme.2025-06-10.20.06.27.mp4

@muimsd
Copy link
Author
muimsd commented Jun 10, 2025

Bildschirmaufnahme.2025-06-10.20.06.27.mp4

I will try to replicate it on Firefox, then fix it. Currently, this error is not happening on Chrome.

@muimsd
Copy link
Author
muimsd commented Jun 11, 2025

Bildschirmaufnahme.2025-06-10.20.06.27.mp4
#673 (comment)
I have fixed this issue of Firefox.
image

@DavidMStraub
Copy link
Member

Yes, it's working now also on my side, thanks!

@DavidMStraub DavidMStraub changed the base branch from main to maplibre June 12, 2025 10:29
@DavidMStraub
Copy link
Member

Merging this into a separate branch as I'll need to tweak a few things before merging into master.

@DavidMStraub DavidMStraub merged commit 9937f32 into gramps-project:maplibre Jun 12, 2025
1 check passed
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.

2 participants
0