Coder Social home page Coder Social logo

Comments (3)

jpsc avatar jpsc commented on May 30, 2024 1

@phegman thank you for the the answer. It helped changing to map-init. I still think that it is odd that the load has that behavior.

Regarding the id that makes sense, but I just thought that mapbox would be transformed into the #map container. Why element with the id created is not created by the ?

Thanks!

from vue-mapbox-gl.

phegman avatar phegman commented on May 30, 2024 1

The div with an ID of map is created by the Mapbox component so there is no need to wrap the component in a div with an ID of map.

from vue-mapbox-gl.

phegman avatar phegman commented on May 30, 2024

Hi João,

That is very weird, I will have to dig deeper into this to find out why this would happen. I played around with it and discovered if you use the @map-init event to set the map object then the bug is no longer there.

I also noticed you are wrapping the mapbox component in a div with an ID of map. The mapbox component by default gets rendered with an ID of map so this would cause a duplicate ID. You can pass a custom container ID to the mapbox component through the options prop.

See below example for bug fix and passing custom container

<template>
  <div id="map" class="map">
    <mapbox 
        access-token=""
        :map-options="{
            style: 'mapbox://styles/mapbox/streets-v9',
            center: [-96, 37.8],
            zoom: 9,
            container: 'map2'
          }"
          @map-init="mapInitialized"
        >
      </mapbox>
      <button @click="flyTo">Center</button>
    </div>
</template>

<script>
  import Mapbox from 'mapbox-gl-vue';

  export default {
    data() {
      return {
        map: {}
      }
    },
    components: { Mapbox },
    methods: {
      mapInitialized(map) {
        this.map = map
      },
      flyTo () {
        this.map.flyTo({
          center: [4.498558399999999, 51.9220879]
        })
      }
    }
  }
</script>

Hope that is helpful!

from vue-mapbox-gl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.