-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrasil.html
More file actions
292 lines (254 loc) · 11.8 KB
/
Brasil.html
File metadata and controls
292 lines (254 loc) · 11.8 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!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</title>
<!-- Tailwind CSS para estilização -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Leaflet CSS para o mapa -->
<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;
}
.info-panel {
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 8px;
}
.legend {
line-height: 18px;
color: #555;
background: white;
padding: 10px;
border-radius: 5px;
box-shadow: 0 0 15px rgba(0,0,0,0.2);
}
/* Custom scrollbar para o painel lateral */
::-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-blue-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>
<h1 class="text-xl font-bold tracking-tight">Geografia do Brasil</h1>
</div>
<div class="hidden md:block text-sm text-slate-500 italic">
Visualizador de Dados GeoJSON HD
</div>
</header>
<main class="flex flex-col md:flex-row h-[calc(100vh-80px)]">
<!-- Sidebar de Informações -->
<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-blue-800">Explore o Mapa</h2>
<p class="text-slate-600 leading-relaxed mb-6">
Passe o mouse sobre os estados para ver detalhes rápidos ou clique para selecionar uma região específica.
</p>
<div class="bg-slate-100 p-4 rounded-xl border border-slate-200">
<p class="text-xs uppercase font-bold text-slate-400 mb-2">Dica</p>
<p class="text-sm text-slate-700">O arquivo carregado possui alta definição (HD), permitindo ver contornos detalhados das fronteiras.</p>
</div>
</div>
<!-- Painel Dinâmico de Detalhes -->
<div id="details-panel" class="hidden">
<button onclick="resetSelection()" class="mb-4 text-xs font-semibold text-blue-600 hover:text-blue-800 flex items-center gap-1">
← Voltar para visão geral
</button>
<div id="state-content">
<!-- Conteúdo inserido via JS -->
</div>
</div>
<!-- Stats Footer (Sidebar) -->
<div class="mt-8 pt-8 border-t border-slate-100">
<h3 class="text-xs font-bold text-slate-400 uppercase tracking-widest mb-4">Resumo da Camada</h3>
<div id="layer-stats" class="space-y-3">
<div class="flex justify-between text-sm">
<span class="text-slate-500">Elementos mapeados:</span>
<span id="feature-count" class="font-mono font-bold">--</span>
</div>
</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/80 flex flex-col items-center justify-center transition-opacity duration-500">
<div class="w-12 h-12 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"></div>
<p class="mt-4 font-medium text-blue-800">Processando GeoJSON HD...</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;
// Inicializa o mapa
function initMap() {
map = L.map('map', {
zoomControl: false,
attributionControl: true
}).setView([-15.78, -47.93], 4); // Brasília
// Adiciona controle de zoom no canto superior direito
L.control.zoom({ position: 'topright' }).addTo(map);
// Camada de base (TileLayer) - CartoDB Positron (claro e limpo)
L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
attribution: '© OpenStreetMap contributors © CARTO'
}).addTo(map);
loadGeoData();
}
// Carrega o arquivo GeoJSON anexado
async function loadGeoData() {
try {
const response = await fetch('brasil_geojson_hd.json');
if (!response.ok) throw new Error('Não foi possível carregar o arquivo GeoJSON.');
const data = await response.json();
// Configura estilo padrão
function style(feature) {
return {
fillColor: '#3b82f6',
weight: 1.5,
opacity: 1,
color: 'white',
fillOpacity: 0.6
};
}
// Efeito ao passar o mouse
function highlightFeature(e) {
const layer = e.target;
if (selectedFeature !== layer) {
layer.setStyle({
weight: 3,
color: '#1e3a8a',
fillOpacity: 0.8,
fillColor: '#60a5fa'
});
layer.bringToFront();
}
}
// Resetar estilo ao tirar o mouse
function resetHighlight(e) {
if (selectedFeature !== e.target) {
geojsonLayer.resetStyle(e.target);
}
}
// Evento de clique
function onFeatureClick(e) {
const layer = e.target;
const props = layer.feature.properties;
// Resetar anterior
if (selectedFeature) {
geojsonLayer.resetStyle(selectedFeature);
}
// Selecionar novo
selectedFeature = layer;
layer.setStyle({
weight: 4,
color: '#1e3a8a',
fillOpacity: 0.9,
fillColor: '#2563eb'
});
showDetails(props);
map.fitBounds(layer.getBounds(), { padding: [20, 20] });
}
// Renderiza a camada
geojsonLayer = L.geoJSON(data, {
style: style,
onEachFeature: function(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: onFeatureClick
});
// Tooltip flutuante rápido
const name = feature.properties.name || feature.properties.NM_ESTADO || feature.properties.NM_UF || "Região";
layer.bindTooltip(name, {
sticky: true,
className: 'px-2 py-1 rounded shadow-lg border-none text-sm font-semibold'
});
}
}).addTo(map);
// Ajusta o mapa aos dados
map.fitBounds(geojsonLayer.getBounds());
// Stats
document.getElementById('feature-count').innerText = data.features.length;
document.getElementById('loader').classList.add('opacity-0');
setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
} catch (error) {
console.error(error);
document.getElementById('loader').innerHTML = `
<div class="text-center p-6 bg-red-50 text-red-700 rounded-lg">
<p class="font-bold">Erro ao carregar mapa</p>
<p class="text-sm">${error.message}</p>
</div>
`;
}
}
// Mostra detalhes no painel lateral
function showDetails(props) {
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');
// Mapeamento de propriedades comuns em GeoJSONs do IBGE/Brasil
const nome = props.name || props.NM_ESTADO || props.NM_UF || "Desconhecido";
const sigla = props.sigla || props.SIGLA || props.UF_05 || "";
const regiao = props.regiao || props.NM_REGIAO || "N/A";
let tableRows = "";
for (const [key, value] of Object.entries(props)) {
if (typeof value !== 'object') {
tableRows += `
<div class="flex flex-col py-2 border-b border-slate-50">
<span class="text-[10px] uppercase font-bold text-slate-400">${key}</span>
<span class="text-sm text-slate-700 font-medium">${value}</span>
</div>
`;
}
}
content.innerHTML = `
<div class="mb-6">
<h2 class="text-3xl font-black text-blue-900">${nome} ${sigla ? `<span class="text-blue-400">/ ${sigla}</span>` : ''}</h2>
<span class="inline-block bg-blue-100 text-blue-700 text-xs px-2 py-1 rounded-full font-bold mt-2">
Região ${regiao}
</span>
</div>
<div class="space-y-1">
<h3 class="text-xs font-bold text-slate-400 uppercase tracking-widest mb-2">Atributos do Objeto</h3>
<div class="bg-slate-50 p-3 rounded-lg border border-slate-100 max-h-96 overflow-y-auto">
${tableRows}
</div>
</div>
`;
}
// Reseta seleção
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>