5 805
edições
Sem resumo de edição Etiqueta: Revertido |
Etiqueta: Desfazer |
||
Linha 275: | Linha 275: | ||
}; | }; | ||
const mapTypeSelect = document.getElementById('mapType'); | |||
const specificOptionSelect = document.getElementById('specificOption'); | |||
const filterOptions = document.getElementById('filterOptions'); | |||
const tagButtons = document.getElementById('tagButtons'); | |||
const imageContainer = document.getElementById('imageContainer'); | |||
const enableFilter = document.getElementById('enableFilter'); | |||
const filterTypeSelect = document.getElementById('filterType'); | |||
const searchIdsInput = document.getElementById('searchIds'); | |||
const filterButton = document.getElementById('filterButton'); | |||
function updateTags() { | |||
const selectedMapType = mapTypeSelect.value; | |||
const selectedOption = specificOptionSelect.value; | |||
let tags = []; | |||
if (selectedMapType && selectedOption) { | |||
const options = specificOptions[selectedMapType]; | |||
if (options && options[selectedOption]) { | |||
options[selectedOption].forEach(item => { | |||
tags = [...new Set([...tags, ...item.tags])]; | |||
}); | |||
} | } | ||
} | |||
tagButtons.innerHTML = ''; | |||
const disabledTags = { | |||
'Areia': 'Areia', | |||
'Gelo': 'Gelo', | |||
'Grama': 'Grama', | |||
'Pedra': 'Pedra', | |||
'Subaquático': 'Água', | |||
'Terra': 'Terra', | |||
'Pisos': 'Piso' | |||
}; | |||
tags.forEach(tag => { | |||
const button = document.createElement('button'); | |||
button.textContent = tag; | |||
button.classList.add('tag-button'); | |||
if (disabledTags[selectedOption] === tag) { | |||
button.disabled = true; // Desabilitar a tag correspondente ao Local do X | |||
button.classList.add('disabled'); | |||
} | |||
button.addEventListener('click', () => { | |||
if (!button.disabled) { | |||
button.classList.toggle('selected'); | |||
} | } | ||
}); | }); | ||
tagButtons.appendChild(button); | |||
}); | |||
tagButtons.classList.toggle('hidden', tags.length === 0); | |||
} | |||
function filterImages() { | |||
const selectedTags = Array.from(document.querySelectorAll('.tag-button.selected')).map(btn => btn.textContent); | |||
const selectedMapType = mapTypeSelect.value; | |||
const selectedOption = specificOptionSelect.value; | |||
const filterById = searchIdsInput.value.trim(); | |||
imageContainer.innerHTML = ''; | |||
let itemsToFilter = []; | |||
if (selectedMapType) { | |||
const options = specificOptions[selectedMapType]; | |||
if (options) { | |||
if (selectedOption && options[selectedOption]) { | |||
itemsToFilter = options[selectedOption]; | |||
} | } | ||
} else { | } | ||
} else { | |||
// Se nenhum tipo de mapa for selecionado, reunir itens de todos os tipos de mapa | |||
for (const mapType in specificOptions) { | |||
for (const local in specificOptions[mapType]) { | |||
itemsToFilter = itemsToFilter.concat(specificOptions[mapType][local]); | |||
} | } | ||
} | } | ||
} | |||
if (itemsToFilter.length > 0) { | |||
const filteredItems = itemsToFilter.filter(item => { | |||
const matchesTag = selectedTags.length === 0 || selectedTags.some(tag => item.tags.includes(tag)); | |||
const matchesId = filterById === '' || filterById.split(',').map(id => id.trim()).includes(item.id); | |||
const matchesLocal = selectedOption === '' || item.tags.includes(selectedOption); | |||
return matchesTag && matchesId && matchesLocal; | |||
}); | |||
filteredItems.forEach(item => { | |||
const itemDiv = document.createElement('div'); | |||
itemDiv.classList.add('image-item'); | |||
const img = document.createElement('img'); | |||
img.src = item.imageUrl; | |||
img.alt = `Mapa ${item.id}`; | |||
itemDiv.appendChild(img); | |||
const infoDiv = document.createElement('div'); | |||
infoDiv.classList.add('image-info'); | |||
infoDiv.innerHTML = ` | |||
<strong>Número do Mapa:</strong> ${item.id}<br> | |||
<strong>Local:</strong> ${item.local}<br> | |||
<strong>Coordenada:</strong> ${item.coordinates}<br> | |||
<strong>Tag(s):</strong> ${item.tags.join(', ')} | |||
`; | |||
itemDiv.appendChild(infoDiv); | |||
imageContainer.appendChild(itemDiv); | |||
}); | |||
if (filteredItems.length === 0) { | |||
imageContainer.innerHTML = '<p>Nenhuma imagem encontrada para os critérios selecionados.</p>'; | |||
} | } | ||
} | } | ||
} | |||
document.getElementById('enableFilter').addEventListener('change', function() { | |||
mapTypeSelect.addEventListener(' | const filterOptions = document.getElementById('filterOptions'); | ||
if (this.checked) { | |||
filterOptions.classList.remove('hidden'); | |||
} else { | |||
filterOptions.classList.add('hidden'); | |||
} | |||
}); | |||
function handleFilterChange() { | |||
const isFilterEnabled = enableFilter.checked; | |||
if (isFilterEnabled) { | |||
mapTypeSelect.disabled = true; | |||
specificOptionSelect.disabled = true; | |||
filterOptions.classList.remove('hidden'); | |||
tagButtons.classList.add('hidden'); | |||
filterTypeSelect.value = 'number'; | |||
filterButton.addEventListener('click', () => { | |||
// Desmarcar todas as tags ao ativar o filtro | |||
document.querySelectorAll('.tag-button.selected').forEach(btn => btn.classList.remove('selected')); | |||
filterImages(); | |||
}); | |||
mapTypeSelect.value = ''; | |||
specificOptionSelect.value = ''; | |||
searchIdsInput.value = ''; | |||
imageContainer.innerHTML = ''; | |||
} else { | |||
mapTypeSelect.disabled = false; | |||
specificOptionSelect.disabled = false; | |||
filterOptions.classList.add('hidden'); | |||
tagButtons.classList.remove('hidden'); | |||
searchIdsInput.value = ''; | |||
imageContainer.innerHTML = ''; | |||
updateTags(); | updateTags(); | ||
} | } | ||
} | |||
specificOptionSelect.addEventListener('change', () => { | enableFilter.addEventListener('change', handleFilterChange); | ||
mapTypeSelect.addEventListener('change', () => { | |||
}); | updateTags(); | ||
filterImages(); | |||
}); | |||
specificOptionSelect.addEventListener('change', () => { | |||
updateTags(); | |||
filterImages(); | |||
}); | |||
// Inicializa a exibição das tags e imagens | |||
updateTags(); | |||
</script> | |||
</body> | </body> | ||
</html> | </html> |