vue-mapbox icon indicating copy to clipboard operation
vue-mapbox copied to clipboard

Zoom issue

Open soreana opened this issue 2 years ago • 3 comments

I used the examples in documentation to create new project. As you can see in the following gif when I zoom in, my map get corrupted without any exceptions or error in console. Could you please help me debug this strange issue? 😄

Let me know if you need any part of the source code.

ezgif com-gif-maker

soreana avatar Feb 04 '22 15:02 soreana

Here is the code:

<template>
    <MglMap id="map"
          :accessToken="accessToken"
          :mapStyle="mapStyle"
          :center="center"
          :zoom="zoom"
          @load="onMapLoaded"
          @click="userClick">
</template>

<script>
import Mapbox from "mapbox-gl";
import { MglMap } from "vue-mapbox";

export default {
  components: {
    MglMap
  },
  data() {
    return {
      accessToken: process.env.VUE_APP_MAPBOX_ACCESS_TOKEN, // my access token
      mapStyle: 'mapbox://styles/mapbox/streets-v11',
      center: [4.7500, 52.2900], // starting position
      map: null,
      zoom: 10, // starting zoom
      coordinates: [4.7828,52.2557],
      popupTxt: "",
    };
  },
  methods:{
    onMapLoaded(event) {
      this.map = event.map;
    }
  },
  created() {
    // We need to set mapbox-gl library here in order to use it in template
    this.mapbox = Mapbox;
  }
};

soreana avatar Feb 07 '22 21:02 soreana

I found the cause and solution. I missed the parentheses in @load="onMapLoaded" as a result onMapLoaded event failed to execute. It should be @load="onMapLoaded()"

<template>
    <MglMap id="map"
...
          @load="onMapLoaded()"
...
</template>

soreana avatar Feb 07 '22 21:02 soreana

I was wrong !! This documentation is incorrect. Map load documentation has to be something like the following sample. More information is available here.

<template>
    <MglMap id="map"
          :accessToken="accessToken"
          :mapStyle="mapStyle"
          :center="center"
          :zoom="zoom"
          @load="onMapLoaded"
          @click="userClick">
</template>

<script>
import Mapbox from "mapbox-gl";
import { MglMap } from "vue-mapbox";

let map;

export default {
  components: {
    MglMap
  },
  data() {
    return {
      accessToken: process.env.VUE_APP_MAPBOX_ACCESS_TOKEN, // my access token
      mapStyle: 'mapbox://styles/mapbox/streets-v11',
      center: [4.7500, 52.2900], // starting position
      zoom: 10, // starting zoom
      coordinates: [4.7828,52.2557],
      popupTxt: "",
    };
  },
  methods:{
    onMapLoaded(event) {
      map = event.map;
    }
  },
  created() {
    // We need to set mapbox-gl library here in order to use it in template
    this.mapbox = Mapbox;
  }
};

soreana avatar Feb 07 '22 22:02 soreana