AlexLavoie42 / Nuxt-Mapbox

Elegant Mapbox integration with Nuxt
81 stars 11 forks source link

`MapboxDefaultMarker` LatLng doesn't respond to changes #26

Closed agracia-foticos closed 1 year ago

agracia-foticos commented 1 year ago

We have this reproduction link example https://stackblitz.com/edit/nuxt-starter-zfc59i

When i'm trying to refresh v-for MapboxDefaultMarker object, throws me and error image

The object pickpoints is refreshed, but throws an error image

AlexLavoie42 commented 1 year ago

At the moment none of the component properties are reactive to changes since the mapbox objects are created on initialization and passed a copy of the properties. This is something I will work on adding at some point (Some components will probably need to be reloaded entirely).

I was not able to reproduce the same error you showed after fixing the reproduction (missing setup tag in script & invalid API key) but the markers do not respond to changes.

For a marker to move its position right now, I believe you need to call setLngLat on the marker with the changed coordinates.

AlexLavoie42 commented 1 year ago

Fixed in #28

agracia-foticos commented 1 year ago

@AlexLavoie42 don't runs with new version :(

AlexLavoie42 commented 1 year ago

If you are referring to the reproduction you sent, you need to make sure you use setup in your script tag or the vue composition api wont work https://vuejs.org/guide/typescript/composition-api.html

Also, the markers wont render unless you give a valid api key. After fixing it here it seems to work for me just fine.

agracia-foticos commented 1 year ago

https://stackblitz.com/edit/nuxt-starter-zfc59i

I change this reproduction link, updating to latest version, but the markers don`t refresh :(

Obviously I'm not going to show my mapbox AKI key in the link :P

<MapboxMap :map-id="mapId" :options="optionsMap" >
                   <MapboxDefaultMarker :lnglat="[pickpoint.geo_2, pickpoint.geo_1]" v-for="pickpoint in pickpoints.items" :marker-id="`marker-${pickpoint.pickpoint_id}`" :key="pickpoint.pickpoint_id" /> 
                </MapboxMap>

If i change the pickpoints, dont refresh them

AlexLavoie42 commented 1 year ago

You still have the same issue, you are putting template in your script tag instead of setup. This will break the composition API in Vue entirely. https://vuejs.org/guide/introduction.html#composition-api image

Once again after fixing that and using my own API key (you can use the one in the playground if you dont want to provide your own) it works fine. https://stackblitz.com/edit/nuxt-starter-4qtfrz