Widget:Test3

Revisão de 22h22min de 3 de setembro de 2024 por Renee (discussão | contribs)

<!DOCTYPE html> <html lang="pt-BR">

<head>

   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Seleção e Exibição de Imagens</title>
   <style>
       /* Seus estilos aqui... */
   </style>

</head>

<body>

   <form id="mapForm">
           <select id="mapType" class="maps__select">
               <option value="">Selecione um mapa</option>
               <option value="1">Mapa Vermelho</option>
               <option value="2">Mapa Verde</option>
               <option value="3">Mapa Roxo</option>
           </select>
           <label class="maps__label" for="mapType">Tipo de Mapa</label>
           <select id="specificOption" class="maps__select">
               <option value="">Selecione uma opção</option>
               <option value="Areia">Areia</option>
               <option value="Gelo">Gelo</option>
               <option value="Grama">Grama</option>
               <option value="Pedra">Pedra</option>
               <option value="Subaquático">Subaquático</option>
               <option value="Terra">Terra</option>
               <option value="Pisos">Pisos</option>
           </select>
           <label class="maps__label" for="specificOption">Local do X</label>
           <input type="checkbox" id="enableFilter">
           <label for="enableFilter" class="filter-label">Ativar filtro</label>
           <label for="tagSelect">Selecione as Tags:</label>
   </form>
   <script>
       const specificOptions = {
           1: {
               'Areia': [ 
                   { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tags:['Areia','Água','Grama','Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/4/4c/Mapas_de_ADV_VERMELHO_-_3780%2C_3326%2C_7.webp' }, 
                   { id: '102', local: 'Wildwind Island', coordinates: '3969, 3300, 7', tags:['Areia','Terra','Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/5/58/Mapas_de_ADV_VERMELHO_-_3969%2C_3300%2C_7.webp' }, 
                   { id: '103', local: 'Wildwind Island', coordinates: '4002, 3320, 7', tags:['Areia','Árvore','Pedra'], imageUrl: 'https://wiki.pokexgames.com/images/0/07/Mapas_de_ADV_VERMELHO_-_4002%2C_3320%2C_7.webp' }, 
                   { id: '104', local: 'Saffron', coordinates: '4009, 3601, 7', tags:['Areia','Árvore','Terra','Água'], imageUrl: 'https://wiki.pokexgames.com/images/f/f5/Mapas_de_ADV_VERMELHO_-_4009%2C_3601%2C_7.webp' }, 
                   { id: '105', local: 'Hurricane Island', coordinates: '4166, 3302, 7', tags:['Areia','Árvore','Água'], imageUrl: 'https://wiki.pokexgames.com/images/0/0d/Mapas_de_ADV_VERMELHO_-_4166%2C_3302%2C_7.webp' },
               ]
           },
           2: {
               'Gelo': [
                   { id: '201', local: 'Frozen Tundra', coordinates: '5600, 5200, 7', tags: ['Gelo'], imageUrl: 'https://wiki.pokexgames.com/images/6/6f/Mapas_de_ADV_VERDE_-_5600%2C_5200%2C_7.webp' }
               ]
           },
           3: {
               'Grama': [
                   { id: '301', local: 'Grassland Fields', coordinates: '3300, 2200, 7', tags: ['Grama'], imageUrl: 'https://wiki.pokexgames.com/images/7/70/Mapas_de_ADV_ROXO_-_3300%2C_2200%2C_7.webp' }
               ]
           }
       };
       function displayMaps(maps) {
           const container = document.getElementById('imageContainer');
           container.innerHTML = ; // Clear previous results
           maps.forEach(map => {
               const imageItem = document.createElement('div');
               imageItem.className = 'image-item';
               const image = document.createElement('img');
               image.src = map.imageUrl;
               image.alt = map.local;
               image.className = 'map-image';
               const info = document.createElement('div');
               info.className = 'image-info';
               info.innerHTML = `
                   Número do Mapa: ${map.id} 
Local: ${map.local}
Coordenada: ${map.coordinates}
Tag(s): ${map.tags.join(', ') || 'Nenhuma'} `;
               imageItem.appendChild(image);
               imageItem.appendChild(info);
               container.appendChild(imageItem);
           });
           container.classList.remove('hidden');
       }
       function filterImages() {
           const mapType = document.getElementById('mapType').value;
           const specificOption = document.getElementById('specificOption').value;
           const selectedTags = Array.from(document.querySelectorAll('.tag-button.selected')).map(button => button.getAttribute('data-value'));
           if (mapType) {
               let filteredMaps = [];
               if (specificOption) {
                   filteredMaps = specificOptions[mapType][specificOption] || [];
               }
               if (selectedTags.length) {
                   filteredMaps = filteredMaps.filter(map => selectedTags.some(tag => map.tags.map(t => t.toLowerCase()).includes(tag.toLowerCase())));
               }
               displayMaps(filteredMaps);
           }
       }
        function toggleTagButton(e) {
           if (e.target.classList.contains('tag-button')) {
               e.target.classList.toggle('selected');
               filterImages();
           }
       }
       // Adiciona o listener de eventos para os botões de tag
       document.getElementById('tagButtons').addEventListener('click', toggleTagButton);
       // Adiciona o listener de eventos para o botão de filtro
       document.getElementById('filterButton').addEventListener('click', filterImages);
       // Adiciona o listener de eventos para a checkbox de ativação de filtro
       document.getElementById('enableFilter').addEventListener('change', function () {
           const filterSection = document.getElementById('filterSection');
           if (this.checked) {
               filterSection.classList.remove('hidden');
           } else {
               filterSection.classList.add('hidden');
           }
       });
       // Adiciona os listeners para exibir as tags somente quando os selects estiverem preenchidos
       document.getElementById('mapType').addEventListener('change', function () {
           const tagButtons = document.getElementById('tagButtons');
           const specificOption = document.getElementById('specificOption').value;
           if (this.value && specificOption) {
               tagButtons.classList.remove('hidden');
           } else {
               tagButtons.classList.add('hidden');
               // Limpa as seleções de tags
               document.querySelectorAll('.tag-button').forEach(button => button.classList.remove('selected'));
           }
       });
       document.getElementById('specificOption').addEventListener('change', function () {
           const tagButtons = document.getElementById('tagButtons');
           if (this.value && document.getElementById('mapType').value) {
               tagButtons.classList.remove('hidden');
           } else {
               tagButtons.classList.add('hidden');
               // Limpa as seleções de tags
               document.querySelectorAll('.tag-button').forEach(button => button.classList.remove('selected'));
           }
       });
   </script>

</body>

</html>