You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But if I move to a different pseudo-route (say from /#/Map to /#/Profile and back), some of the map layers specified by my mapStyle (roads, city names,..) are not rendered anymore (default layers instead). The map also stops honoring any change of the mapStyle url, even when I specify mapStyle.sync in my template.
If I hit the browser's reload button it loads the layers as expected as the entire app is reloaded from scratch, but I unfortunately cannot afford to do this by default.
Any ideas are greatly appreciated.
The text was updated successfully, but these errors were encountered:
I found a solution, in the example of vue-mapbox, the variable map (this.map) is set by "event.map" which causes an error because the card is not refreshed afterwards.
In my case i just remove that (this.map = event.map) in my onMapLoaded function and this is great.
@Pierre-Saigot is correct. Caching the map in the data of the component as the documentation suggests will cause further refresh attempts to fail as it will get observed by Vue, and therefore no longer point to the actual object reference at play directly.
This can be avoided by caching the map outside of the Vue instance's state so it doesn't get observed.
Example:
<template><MglMap:accessToken="accessToken"
@load="onMapLoaded"></MglMap></template><script>importMapboxfrom'mapbox-gl'import{MglMap,MglMarker}from'vue-mapbox'import*asMAPfrom'@/constants/map'letmap=null// could live anywhere where it would not be observed by Vueexportdefault{name: 'Map',components: {
MglMap,
MglMarker
},data(){return{accessToken: MAP.ACCESS_TOKEN,// map should not be observed, must be cached externally}},beforeDestroy(){// do something with the map later if necessaryconstlastPosition=map.getCenter()},methods: {onMapLoaded(event){// cache mapmap=event.map}}}</script>
Not closing this issue yet as the documentation likely needs to be updated accordingly.
I am using VueMapbox (0.4.1) to utilize Mapbox GL in a Vue project.
On the first load, everything works as expected:
But if I move to a different pseudo-route (say from
/#/Map
to/#/Profile
and back), some of the map layers specified by mymapStyle
(roads, city names,..) are not rendered anymore (default layers instead). The map also stops honoring any change of themapStyle
url, even when I specifymapStyle.sync
in my template.If I hit the browser's reload button it loads the layers as expected as the entire app is reloaded from scratch, but I unfortunately cannot afford to do this by default.
Any ideas are greatly appreciated.
The text was updated successfully, but these errors were encountered: