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

126
Visualizações
How to load a map inside a div container on button click

I have this javascript that can place a map on an html page as following:

simple.html:

<body onload="loadMap({{% coordinates %}})">
    <div id="map"></div>
  </body>

js:

function setupMap(coordinates){
      var map = new L.Map('map', {
        zoomControl: false,
        center: [40, 0],
        zoom: 3
      });
      var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: 'OSM'
      }).addTo(map);

      map.addLayer(layer)
}
function loadMap(coordinates) {
        window.onload = setupMap(coordinates);
}

My question is whether I can use this function to set the map on a div, instead of the body. If it's not possible, what should I change in order to target a div, not the window?

In my case I want to open the map when a button is clicked and the modal where I want to place the map is poped up.

desired.html:

<button id="modal-map-open" class='modal-toggle' onclick="loadMap({{coordinates}})"><i class="fa fa-map"></i></button>

              <div id="open-map-class" class='modal' style="width: 1000px;">
                   <div id="map"></div>
                  <button id="modal-map" onclick="closeMap()" class='modal-toggle modal-button'>&times;</button>
              </div>
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