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

Non-mapbox basemaps tiles get disappeared #111

Open
vinayakkulkarni opened this issue Apr 16, 2019 · 12 comments
Open

Non-mapbox basemaps tiles get disappeared #111

vinayakkulkarni opened this issue Apr 16, 2019 · 12 comments

Comments

@vinayakkulkarni
Copy link

Here's my data object:

data() {
    return {
      map: null,
      accessToken: null, // your access token. Needed if you using Mapbox maps
      mapStyle:`https://maps.tilehosting.com/styles/voyager/style.json?key={KEY}`, // your map style
    };
  },

When the map is zoomed, the tiles aren't being fetched.
Demo: https://bit.ly/soal-vue-mapbox

@vinayakkulkarni
Copy link
Author

bump

@vinayakkulkarni
Copy link
Author

🛎

@ajotka
Copy link

ajotka commented Apr 30, 2019

I have the same issue.
And only sattelite-v9 style works properly - I don't know why.

@soal
Copy link
Owner

soal commented May 4, 2019

Anything in console?

@vinayakkulkarni
Copy link
Author

Anything in console?

Nope. All clear

Also, i tried using mapbox styles, as @ajotka said, only mapbox://styles/mapbox/satellite-streets-v9 works correctly...!

@vinayakkulkarni
Copy link
Author

vinayakkulkarni commented May 17, 2019

With Vuex:

<template>
  <MglMap
    :access-token="accessToken"
    :map-style.sync="mapStyle"
    @load="onMapLoaded"
  >
    <MglNavigationControl position="bottom-right" />
    <MglGeolocateControl position="top-right" />
    <MglScaleControl position="bottom-left" />
  </MglMap>
</template>

<script>
import {
  MglMap,
  MglNavigationControl,
  MglGeolocateControl,
  MglScaleControl,
} from 'vue-mapbox';
import { mapState } from 'vuex';

export default {
  name: 'DashboardMap',
  components: {
    MglMap,
    MglNavigationControl,
    MglGeolocateControl,
    MglScaleControl,
  },
  data() {
    return {
      accessToken: process.env.mapToken,
      mapStyle: 'mapbox://styles/mapbox/satellite-streets-v9',
    };
  },
  computed: {
    ...mapState('map', ['map']),
  },
  beforeDestroy() {
    this.$store.commit('map/destroyMap');
  },
  methods: {
    onMapLoaded(event) {
      this.$store.commit('map/initializeMap', event.map);
    },
  },
};
</script>

Without Vuex:

<template>
  <MglMap
    :access-token="accessToken"
    :map-style.sync="mapStyle"
    @load="onMapLoaded"
  >
    <MglNavigationControl position="bottom-right" />
    <MglGeolocateControl position="top-right" />
    <MglScaleControl position="bottom-left" />
  </MglMap>
</template>

<script>
import {
  MglMap,
  MglNavigationControl,
  MglGeolocateControl,
  MglScaleControl,
} from 'vue-mapbox';

export default {
  name: 'DashboardMap',
  components: {
    MglMap,
    MglNavigationControl,
    MglGeolocateControl,
    MglScaleControl,
  },
  data() {
    return {
      localMap: null,
      accessToken: process.env.mapToken,
      mapStyle: 'mapbox://styles/mapbox/satellite-streets-v9',
    };
  },
  created() {
    this.localMap = null;
  },
  beforeDestroy() {
    this.localMap = null;
  },
  methods: {
    onMapLoaded(event) {
      this.localMap = event.map;
    },
  },
};
</script>

@vinayakkulkarni
Copy link
Author

bump

@TheNoim
Copy link

TheNoim commented May 27, 2019

Experienced the same issue

@vinayakkulkarni
Copy link
Author

Ok, after removing any and all map related variables from data(), it seems to be working. But I'm unable to access the map object :(

@danielholmes
Copy link

This Stack Overflow question appears to be related: https://stackoverflow.com/questions/50824353/mapbox-style-changes-breaks-on-zoom-when-a-layer-is-added

@danielholmes
Copy link

@vinayakkulkarni My temporary solution was to access the map via refs. e.g.:

<mgl-map ref="mglMap" ... />
this.$refs.mglMap.map.fitBounds(...);

@maximelebreton
Copy link

maximelebreton commented Jul 23, 2020

After hours spent on this problem, here is my working solution to access map instance from a store (thanks to vuejs/vue#2637 (comment) and vuejs/vue#2637 (comment)):

const state = reactive({
  map: Object.freeze({ wrapper: /* PUT THE MAP INSTANCE HERE */ });
});

Here is an example with Vue Composition Api:

index.js

import { reactive, computed } from "@vue/composition-api";

export const state = reactive({
  map: null
});

export const setMap = (map) => {
  state.map = Object.freeze({ wrapper: map});
};

export const getMap = computed(() => state.map.wrapper);

export const initMap = (event) => {
  setMap(event.map);

  // now you can access to map instance from the "getMap" getter!
  getMap.value.addSource("satellite-source", {
    type: "raster",
    url: "mapbox://mapbox.satellite",
  }); 
  getMap.value.addLayer({
    id: "satellite-layer",
    type: "raster",
    source: "satellite-source"
  });
};

App.vue

<template>
  <MglMap :accessToken="..." :mapStyle="..." @load="onMapLoaded" />
</template>


<script>
import { defineComponent } from "@vue/composition-api";
import { MglMap } from "vue-mapbox";
import { initMap } from "./index.js";

export default defineComponent({
  components: {
    MglMap
  },
  setup() {
    const onMapLoaded = (event) => {
      initMap(event);
    }

    return { onMapLoaded };
  }
});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants