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

Zoom issue #249

Open
soreana opened this issue Feb 4, 2022 · 3 comments
Open

Zoom issue #249

soreana opened this issue Feb 4, 2022 · 3 comments

Comments

@soreana
Copy link

soreana commented Feb 4, 2022

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
Copy link
Author

soreana commented Feb 7, 2022

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 soreana changed the title Zoom issue Sample code in a website has Zoom issue Feb 7, 2022
@soreana soreana changed the title Sample code in a website has Zoom issue Zoom issue Feb 7, 2022
@soreana
Copy link
Author

soreana commented Feb 7, 2022

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
Copy link
Author

soreana commented Feb 7, 2022

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;
  }
};

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

1 participant