AlexLavoie42 / Nuxt-Mapbox

Elegant Mapbox integration with Nuxt
81 stars 11 forks source link

Map components don't get re-added on map reload #42

Closed johnghr closed 1 year ago

johnghr commented 1 year ago

I was just wondering if you had any suggestions regarding how to handle changing the the map style with the mapbox setStyle method while using the MapboxLayer and MapboxSource components? The problem being if I access the map instance with useMapInstance and set the style, my MapboxLayer and MapboxSource components become redundant because the data gets removed when the map gets reinstantiated.

Is there a way to use the components and progmatically set the style or is just using vanila mapbox-gl recommended for this use case?

johnghr commented 1 year ago

I've found a solution to this is to force the MapboxMap component to rerender when the style changes

AlexLavoie42 commented 1 year ago

Reopening as a feature request for next update.

Just reloading layers and sources should be much more efficient than reloading the entire component, and will make changing styles simple.

AlexLavoie42 commented 1 year ago

Also, you can use the new beforeLayer prop to ensure layer order.

johnghr commented 1 year ago

Awesome! You're also a mind reader because I was 100% going to ask about the layer order.

AlexLavoie42 commented 1 year ago

Fixed in #45