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

Storing markers in array messes up map layout #57

Closed
Jones-S opened this issue Feb 5, 2019 · 4 comments
Closed

Storing markers in array messes up map layout #57

Jones-S opened this issue Feb 5, 2019 · 4 comments

Comments

@Jones-S
Copy link

Jones-S commented Feb 5, 2019

Hi there

I have a map with about 5 markers, of which 1 is the active one.
Now on route change I would like to update the markers to change the active one.

First I thought of creating the marker as a vue instance to bind some store data to it. But referring to this other issue this was not really successful – at least as far as I understood.

My alternative solution was to remove all markers and add them again (I only have 5 and I just need to update the active one).
Unfortunately If I store all markers in an array, I have a weird looking map:

data() {
    return {
      markers: []
    }
  },

...

const marker = new mapboxgl.Marker(el)
          .setLngLat(point.geometry.coordinates)
          .addTo(map)

this.markers.push(marker)

Adding this.markers.push(marker) will cause the map to look like this:
image

Instead of
image

Did anyone experience something like this before?

I would need an array of all markers to loop over them and remove them after a change if the binding does not work.

Like:

    removeMarkers() {
      this.markers.forEach(m => {
        m.remove()
      })
    },

Preferably I would like to see a solution with the binding, but if not, I would be definitely interested in knowing what is happening with the map layout.

Thank you in advance.
Cheers

@timvan
Copy link

timvan commented May 23, 2019

I also have this exact problem. As soon you add markers to an array, mapbox map craps itself. Very weird.

For me, I want loop over all markers to get their long/lat coordinates and create lines between them.

@phegman
Copy link
Owner

phegman commented Sep 5, 2019

Just released v2 of this package, please upgrade and see if that fixes your issue

@phegman phegman closed this as completed Sep 5, 2019
@omejiasq
Copy link

omejiasq commented Apr 4, 2020

Hi Phegman, i have the same issue. I have an application with vue js and mapbox, and the maps work well for me in windows, but when I upload the development to a server in centos 7, with the same version of vue-mapbox-gl and everything the same, the map turns gray when a new marker is automatically added. I already upgraded to version 2 of vue-mapbox-gl but I have the same problem. How can i solve this?

@vabe44
Copy link

vabe44 commented Apr 4, 2020

@omejiasq @phegman I had the same issue. This solution didn't work:

created() {
  this.map = null // here we define map as non-reactive
},

methods: {
  initMap(map) {
    this.map = map
  }
}

Neither did this one:

{
  map: null,
  methods: {
    initMap(map) {
      this.$options.map = map
  }
}

Only this fixed it:

initMap(map) {
  map._isVue = true
  this.map = map
}

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

No branches or pull requests

5 participants