Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

385
Visualizações
how to put a vue component on leaflet js map?

I'm creating a leaflet world map, and need to show a modal to user, according to what country the user clicks on. I'm creating the modal as a component, and using it in the index.vue. the codes in index.vue are:

<template>
  <div id="map-wrap" style="height: 100vh">

    <client-only>
      <l-map :zoom=13 :center="[55.9464418,8.1277591]" :options="options" ref="map">

        <l-tile-layer url="..."></l-tile-layer>
        <l-geo-json :geojson="geojson" :options="geoJSON_options"></l-geo-json>
        <Detail_modal />

      </l-map>
    </client-only>
</div>
</template>

<script>
import axios from "axios";
import Detail_modal from '~/components/detail_modal.vue';

export default {
  name: 'IndexPage',

  components:{
    Detail_modal
  },

  data: function(){
    return {
      options: {
        noWrap: true,
        maxBounds: [
          [-90, -180],
          [90, 180]
        ],
        minZoom: 3,
        maxZoom: 5,
      },

      geojson: null
    }
  },

  methods:{
    get_data(){
      ... 
    },

  },

  computed:{
    geoJSON_options(){
      return {
        style(feature){
          ...
      },

        onEachFeature(feature, layer){
          ...
        }
      }
    }
  },

  mounted(){
    this.get_data();

    setTimeout(() => {
      let map = this.$refs.map.mapObject;
      map.createPane("detail-modal");
      map.getPane("detail-modal").style.zIndex = 1000;
    })
  }
}
</script>

<style lang="scss" scoped>

</style>

and the component codes are:

<template>
    <div id="detail-modal">
        
    </div>
</template>

<script>
export default {

}
</script>

<style lang="scss" scoped>
div#detail-modal{
    position: absolute;
    width: 300px;
    height: 400px;
    background-color: white;

    z-index: 99;
    left: 500px;
    top: 20px;
}
</style>

As we see, we can expect a white rectangle to be shown above the map.

The problem is that the component (white rectangle) is always under the map, even when we are using z-index.

I've searched a lot about it, some people say that we should use map panes and map.createPane() in these situations, which turns the element into a leaflet layer and controls the order between different parts of the map, but the problem gets worse when there is no guide about how we are supposed to turn custom elements such as html element with a ID into this such layers.

Well, as always, any help is appreciated! :)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda