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

Expose raw MapboxGl object

Open Maro8311 opened this issue 4 years ago • 1 comments

Hello everyone, how I can I get access to the raw MapboxGl object? Thx a lot!

<template>
  <MglMap> /* some properties */> </MglMap>
</template>

<script>
import { Mapbox } from "mapbox-gl"
import { MglMap }  from "vue-mapbox"
export default {
 name: "MapComponent",
  components: {
    MglMap
  },
 created() {
    console.log(Mapbox.getCenter()) // does not work:   Mapbox is undefined
 }
}
</script>

Maro8311 avatar May 07 '21 04:05 Maro8311

You will have to use

<template>
  <MglMap @load="handleMapLoad"> /* some properties */> </MglMap>
</template>

<script>
import { Mapbox } from "mapbox-gl"
import { MglMap }  from "vue-mapbox"
export default {
 name: "MapComponent",
  components: {
    MglMap
  },
 data(){
     return {
         map: null,
         mapbox: null
     }
 },
 created() {
    this.mapbox = Mapbox;
 },
 methods: {
    handleMapLoad(event){
        this.map = event.map
        this.ready();
    },
    ready(){
         console.log(this.map.getCenter());
    }
 }
}
</script>

hicham-saddek avatar Jul 20 '21 14:07 hicham-saddek