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

121
Visualizações
HTML: create a interactive table with several radio buttons, which can show different maps created by MapBox

I tried to use HTML to build an interactive table of maps, which can show several different maps from MapBox. I created a table with some radio buttons, like:

<table>
                <tr>
                    <td>
                        <input type="radio" name="layers" id="layer1" value="2000" checked><label>2000 &nbsp;
                            &nbsp;</label>
                        <input type="radio" name="layers" id="layer2" value="2008"><label>2008 </label>
                    </td>
                </tr>
            </table>

And then, I imported maps from MapBox by:

mapboxgl.accessToken = 'mytoken';  //Put your mapbox access token here

        var map1 = new mapboxgl.Map({
                //container: 'map', // container id
                style: 'mapbox_stylelink', // map background layer location
                center: [0, 51.5], // starting position [lng, lat]
                zoom: 10, // starting zoom
                pitch: 50 // tilt of the viewpoint in degrees
            });
        
        var map2 = mapboxgl.Map({
                //container: 'map', // container id
                style: 'mapbox_stylelink', // map background layer location
                center: [0, 51.5], // starting position [lng, lat]
                zoom: 8, // starting zoom
                pitch: 50 // tilt of the viewpoint in degrees
            });

And try to callback listener by:

document.getElementById("layer1").addEventListener("click", function(){
            document.getElementById("map")  = 'map1'
        });

        document.getElementById("layer2").addEventListener("click", function () {
                document.getElementById("map") = 'map2'
            });

When I start to go live with the code, it just can not change the map by clicking the 'radio' button in the table. I know there is something wrong with the callback, but I don't know how to correct it. And it also seems that the container should be empty when defining a new map. Can someone please give me some guidance?Thank you very much!

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