-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrasil2.html
More file actions
243 lines (206 loc) · 9.97 KB
/
brasil2.html
File metadata and controls
243 lines (206 loc) · 9.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mapa Interativo do Brasil - GeoJSON</title>
<!-- Tailwind CSS para estilização -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
#map {
height: calc(100vh - 80px);
width: 100%;
z-index: 1;
background-color: #f8fafc; /* Cor de fundo neutra para o vazio */
}
.leaflet-container {
background: #f1f5f9 !important; /* Remove o fundo padrão do Leaflet */
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 10px;
}
</style>
</head>
<body class="bg-slate-50 font-sans text-slate-900">
<!-- Header -->
<header class="h-20 bg-white border-b border-slate-200 flex items-center justify-between px-6 sticky top-0 z-10">
<div class="flex items-center gap-3">
<div class="bg-emerald-600 p-2 rounded-lg">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 20l-5.447-2.724A2 2 0 013 15.488V5.512a2 2 0 011.553-1.954L9 1l6 3 6-3 1.447.724A2 2 0 0121 8.512v9.976a2 2 0 01-1.553 1.954L15 23l-6-3z" />
</svg>
</div>
<div>
<h1 class="text-xl font-bold tracking-tight">Mapa Vetorial do Brasil</h1>
<p class="text-xs text-slate-500">Visualização exclusiva de dados GeoJSON</p>
</div>
</div>
</header>
<main class="flex flex-col md:flex-row h-[calc(100vh-80px)]">
<!-- Sidebar -->
<aside class="w-full md:w-80 lg:w-96 bg-white border-r border-slate-200 p-6 overflow-y-auto z-20 order-2 md:order-1">
<div id="welcome-msg">
<h2 class="text-lg font-semibold mb-4 text-emerald-800">Selecione um Estado</h2>
<p class="text-slate-600 leading-relaxed mb-6">
Clique em qualquer região do mapa para visualizar as informações extraídas e um valor gerado aleatoriamente.
</p>
<div class="bg-emerald-50 p-4 rounded-xl border border-emerald-100">
<p class="text-xs uppercase font-bold text-emerald-600 mb-2">Modo Vetorial</p>
<p class="text-sm text-emerald-800">O mapa de fundo foi removido para destacar as fronteiras geométricas do arquivo.</p>
</div>
</div>
<!-- Painel Dinâmico -->
<div id="details-panel" class="hidden">
<button onclick="resetSelection()" class="mb-6 text-xs font-semibold text-emerald-600 hover:text-emerald-800 flex items-center gap-1">
← Limpar seleção
</button>
<div id="state-content">
<!-- Preenchido via JS -->
</div>
</div>
</aside>
<!-- Container do Mapa -->
<section class="flex-1 relative order-1 md:order-2">
<div id="map"></div>
<!-- Loader -->
<div id="loader" class="absolute inset-0 z-[1000] bg-white flex flex-col items-center justify-center transition-opacity duration-500">
<div class="w-12 h-12 border-4 border-emerald-600 border-t-transparent rounded-full animate-spin"></div>
<p class="mt-4 font-medium text-emerald-800">Desenhando vetores...</p>
</div>
</section>
</main>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
let map;
let geojsonLayer;
let selectedFeature = null;
function initMap() {
// Inicializa o mapa sem o fundo de tiles
map = L.map('map', {
zoomControl: false,
attributionControl: true,
minZoom: 4
}).setView([-15.78, -47.93], 4);
L.control.zoom({ position: 'topright' }).addTo(map);
// Não adicionamos L.tileLayer aqui para manter apenas o GeoJSON
loadGeoData();
}
async function loadGeoData() {
try {
const response = await fetch('brasil_geojson_hd.json');
if (!response.ok) throw new Error('Falha ao ler brasil_geojson_hd.json');
const data = await response.json();
function style(feature) {
return {
fillColor: '#10b981', // Verde esmeralda
weight: 2,
opacity: 1,
color: '#064e3b', // Borda verde escuro
fillOpacity: 0.4
};
}
function highlightFeature(e) {
const layer = e.target;
if (selectedFeature !== layer) {
layer.setStyle({
fillOpacity: 0.7,
fillColor: '#34d399',
weight: 3
});
layer.bringToFront();
}
}
function resetHighlight(e) {
if (selectedFeature !== e.target) {
geojsonLayer.resetStyle(e.target);
}
}
function onFeatureClick(e) {
const layer = e.target;
const props = layer.feature.properties;
if (selectedFeature) {
geojsonLayer.resetStyle(selectedFeature);
}
selectedFeature = layer;
layer.setStyle({
weight: 4,
color: '#064e3b',
fillOpacity: 0.9,
fillColor: '#059669'
});
// Gera número aleatório
const randomValue = Math.floor(Math.random() * 10000);
showDetails(props, randomValue);
map.fitBounds(layer.getBounds(), { padding: [40, 40] });
}
geojsonLayer = L.geoJSON(data, {
style: style,
onEachFeature: function(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: onFeatureClick
});
const name = feature.properties.name || feature.properties.NM_ESTADO || feature.properties.NM_UF || "Região";
layer.bindTooltip(name, { sticky: true });
}
}).addTo(map);
map.fitBounds(geojsonLayer.getBounds());
document.getElementById('loader').classList.add('opacity-0');
setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
} catch (error) {
console.error(error);
document.getElementById('loader').innerHTML = `<p class="text-red-500 font-bold">${error.message}</p>`;
}
}
function showDetails(props, randomValue) {
const welcome = document.getElementById('welcome-msg');
const panel = document.getElementById('details-panel');
const content = document.getElementById('state-content');
welcome.classList.add('hidden');
panel.classList.remove('hidden');
const nome = props.name || props.NM_ESTADO || props.NM_UF || "Desconhecido";
const sigla = props.sigla || props.SIGLA || props.UF_05 || "";
content.innerHTML = `
<div class="mb-8">
<h2 class="text-xs font-bold text-emerald-600 uppercase tracking-widest mb-1">Estado Selecionado</h2>
<h3 class="text-4xl font-black text-slate-900">${nome} ${sigla ? `<span class="text-emerald-500">${sigla}</span>` : ''}</h3>
</div>
<div class="bg-emerald-600 p-6 rounded-2xl text-white shadow-lg shadow-emerald-200 mb-8">
<p class="text-emerald-100 text-xs font-bold uppercase tracking-tighter">Valor Gerado Aleatório</p>
<div class="text-5xl font-mono font-bold mt-1">${randomValue}</div>
</div>
<div class="space-y-4">
<h4 class="text-xs font-bold text-slate-400 uppercase tracking-widest">Metadados do GeoJSON</h4>
<div class="divide-y divide-slate-100 border-t border-slate-100">
${Object.entries(props).map(([key, value]) => `
<div class="flex justify-between py-2 text-sm">
<span class="text-slate-400 font-medium">${key}</span>
<span class="text-slate-700 font-bold text-right">${value}</span>
</div>
`).join('')}
</div>
</div>
`;
}
function resetSelection() {
if (selectedFeature) {
geojsonLayer.resetStyle(selectedFeature);
selectedFeature = null;
}
document.getElementById('welcome-msg').classList.remove('hidden');
document.getElementById('details-panel').classList.add('hidden');
map.fitBounds(geojsonLayer.getBounds());
}
window.onload = initMap;
</script>
</body>
</html>