[go: up one dir, main page]

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

Support Maplibre GL JS 4.x #2349

Open
1 task
tordans opened this issue Feb 4, 2024 · 2 comments
Open
1 task

Support Maplibre GL JS 4.x #2349

tordans opened this issue Feb 4, 2024 · 2 comments
Labels

Comments

@tordans
Copy link
Contributor
tordans commented Feb 4, 2024

Target Use Case

Maplibre GL JS 4.0.0 was released recently. The changelog list a few things that sound like they are relevant for react-map-gl.

Proposal

I thought we can use this issue to share if everything still works … and if anything needs updating now.


A list of things to look at:

@tordans tordans added the feature label Feb 4, 2024
@tordans
Copy link
Contributor Author
tordans commented Feb 4, 2024

I updated this small Astro Project to Maplibre v4 with the newest pmtiles and it looks like all works great https://github.com/tordans/berlin-bikenetwork-monitoring https://tordans.github.io/berlin-bikenetwork-monitoring/

@andokai
Copy link
andokai commented Mar 2, 2024

One thing that might trip some people up is the change of the loadImage function from callback to promise.

So if you're doing something like this

import { useMap } from 'react-map-gl/maplibre';

export function MapImage({ name, url, sdf }) {
   const { current: map } = useMap();

   if (!map.hasImage(name)) {
     map.loadImage(url, (error, image) => {
       if (error) {
         throw error;
       }
       if (!map.hasImage(name)) {
         map.addImage(name, image, { sdf });
       }
     });
   }
  return null;
}

It needs to be changed to something more like this

import { useMap } from 'react-map-gl/maplibre';

export function MapImage({ name, url, sdf }) {
   const { current: map } = useMap();

   if (!map.hasImage(name)) {
     map.loadImage(url).then(({ data }) => {
       if (!map.hasImage(name)) {
         map.addImage(name, data, { sdf });
       }
     });
   }
  return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants