Mudanças entre as edições de "Widget:MapaViewer"
Ir para navegação
Ir para pesquisar
| Linha 1: | Linha 1: | ||
<includeonly><div id="mapa-viewer-<!--{$id|escape:'quotes'|default:'mapa-default'}-->" style="width: <!--{$largura|escape:'quotes'|default:'100%'}-->; height: <!--{$altura|escape:'quotes'|default:'500px'}-->;"></div> | <includeonly> | ||
<div id="mapa-viewer-<!--{$id|escape:'quotes'|default:'mapa-default'}-->" style="width: <!--{$largura|escape:'quotes'|default:'100%'}-->; height: <!--{$altura|escape:'quotes'|default:'500px'}-->;"></div> | |||
<div style="margin-top: 10px; display: flex; gap: 10px; flex-wrap: wrap;"> | |||
<button onclick="window.mapaViewer_<!--{$id|escape:'quotes'|default:'mapa-default'}-->.zoomIn()" style="padding: 8px 16px; background: #3b82f6; color: white; border: none; border-radius: 6px; cursor: pointer;">🔍 Zoom +</button> | |||
<button onclick="window.mapaViewer_<!--{$id|escape:'quotes'|default:'mapa-default'}-->.zoomOut()" style="padding: 8px 16px; background: #3b82f6; color: white; border: none; border-radius: 6px; cursor: pointer;">🔍 Zoom -</button> | |||
<button onclick="window.mapaViewer_<!--{$id|escape:'quotes'|default:'mapa-default'}-->.resetView()" style="padding: 8px 16px; background: #6b7280; color: white; border: none; border-radius: 6px; cursor: pointer;">🔄 Resetar</button> | |||
<button onclick="window.mapaViewer_<!--{$id|escape:'quotes'|default:'mapa-default'}-->.prevFloor()" style="padding: 8px 16px; background: #8b5cf6; color: white; border: none; border-radius: 6px; cursor: pointer;">⬆️ Andar Anterior</button> | |||
<button onclick="window.mapaViewer_<!--{$id|escape:'quotes'|default:'mapa-default'}-->.nextFloor()" style="padding: 8px 16px; background: #8b5cf6; color: white; border: none; border-radius: 6px; cursor: pointer;">⬇️ Próximo Andar</button> | |||
</div> | |||
<script> | <script> | ||
class MapaViewer { | |||
constructor(containerId, configOrUrl) { | constructor(containerId, configOrUrl) { | ||
this.container = document.getElementById(containerId); | this.container = document.getElementById(containerId); | ||
| Linha 512: | Linha 518: | ||
} | } | ||
// | (function() { | ||
var containerId = 'mapa-viewer-<!--{$id|escape:'quotes'|default:'mapa-default'}-->'; | |||
var configJSON = <!--{$configJSON|default:'null'}-->; // Recebe o JSON | |||
var urlJSON = '<!--{$url|escape:'quotes'}-->'; // Recebe URL do JSON | |||
// Nome da variável global única para este mapa | |||
var globalVarName = 'mapaViewer_<!--{$id|escape:'quotes'|default:'mapa-default'}-->'; | |||
function iniciarMapa() { | |||
var container = document.getElementById(containerId); | |||
if (!container) return; | |||
if (container.hasAttribute('data-iniciado')) return; | |||
container.setAttribute('data-iniciado', 'true'); | |||
var viewer = null; | |||
if (configJSON && configJSON !== 'null') { | |||
// Configuração inline | |||
viewer = new MapaViewer(containerId, configJSON); | |||
} else if (urlJSON) { | |||
// Configuração via URL | |||
fetch(urlJSON) | |||
.then(response => response.json()) | |||
.then(config => { | |||
window[globalVarName] = new MapaViewer(containerId, config); | |||
}) | |||
.catch(error => { | |||
console.error('Erro ao carregar mapa:', error); | |||
container.innerHTML = '<div style="color:red;padding:20px;">❌ Erro ao carregar mapa: ' + error.message + '</div>'; | |||
}); | |||
return; // Sai porque o fetch é assíncrono | |||
} else { | |||
container.innerHTML = '<div style="color:red;padding:20px;">❌ Nenhuma configuração fornecida</div>'; | |||
return; | |||
} | } | ||
// Guarda a instância globalmente para acesso externo | |||
if (viewer) { | |||
window[globalVarName] = viewer; | |||
console.log('Mapa inicializado! Use window.' + globalVarName + ' para controlar'); | |||
console.log('Exemplo: window.' + globalVarName + '.nextFloor()'); | |||
} | } | ||
} | } | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', | document.addEventListener('DOMContentLoaded', iniciarMapa); | ||
} else { | } else { | ||
iniciarMapa(); | |||
} | } | ||
})(); | })(); | ||
</script></includeonly> | </script> | ||
</includeonly> | |||