mapas_repatriado.html
14.7 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SISTEMA GIS | Dashboard Institucional</title>
<!-- Google Font: Source Sans Pro -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<!-- AdminLTE 3.2 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
<!-- MapLibre GL JS -->
<link href="https://unpkg.com/maplibre-gl@3.6.2/dist/maplibre-gl.css" rel="stylesheet" />
<style>
.content-wrapper { position: relative; height: calc(100vh - 57px); overflow: hidden; background: #fff; }
#map { width: 100%; height: 100%; }
.map-overlay {
position: absolute;
bottom: 20px;
left: 20px;
z-index: 1000;
background: rgba(255, 255, 255, 0.9);
border-radius: 4px;
padding: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
display: none;
}
.maplibre-popup { z-index: 2000; }
.popup-header { background: #007bff; color: #fff; padding: 5px 10px; font-weight: bold; font-size: 11px; }
.popup-body { padding: 10px; font-family: 'Source Sans Pro', sans-serif; font-size: 13px; }
.rotating { animation: rotation 2s infinite linear; }
@keyframes rotation { from { transform: rotate(0deg); } to { transform: rotate(359deg); } }
.main-sidebar { border-right: 1px solid #4b545c !important; }
.brand-link { border-bottom: 1px solid #4b545c !important; }
</style>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
<!-- Navbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<span class="nav-link font-weight-bold text-primary" id="muni-title">MUNICIPALIDAD - VISOR GIS</span>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link text-danger" href="/gis-geoserver/login.html" role="button">
<i class="fas fa-sign-out-alt"></i> Cerrar Sesión
</a>
</li>
</ul>
</nav>
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<a href="#" class="brand-link">
<img src="https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
<span class="brand-text font-weight-light">SIGEM <b>GIS</b></span>
</a>
<div class="sidebar">
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<i class="fas fa-user-circle text-light fa-2x"></i>
</div>
<div class="info">
<a href="#" class="d-block" id="user-display">Operador Municipal</a>
</div>
</div>
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu">
<li class="nav-header">RESUMEN MUNICIPAL</li>
<li class="nav-item">
<div class="info-box bg-info m-2">
<span class="info-box-icon"><i class="fas fa-map-marked-alt"></i></span>
<div class="info-box-content">
<span class="info-box-text">Lotes Totales</span>
<span class="info-box-number" id="total-lotes">0</span>
</div>
</div>
</li>
<li class="nav-item">
<div class="info-box bg-danger m-2">
<span class="info-box-icon"><i class="fas fa-exclamation-triangle"></i></span>
<div class="info-box-content">
<span class="info-box-text">Lotes Morosos</span>
<span class="info-box-number" id="lotes-morosos">0</span>
</div>
</div>
</li>
<li class="nav-header">CONTROL DE MAPA</li>
<li class="nav-item">
<a href="javascript:void(0)" onclick="applyMorosidadTheme()" class="nav-link">
<i class="nav-icon fas fa-dollar-sign text-warning"></i>
<p>Mapa Tributario</p>
</a>
</li>
<li class="nav-item">
<a href="javascript:void(0)" onclick="resetMap()" class="nav-link">
<i class="nav-icon fas fa-undo-alt"></i>
<p>Reiniciar Vista</p>
</a>
</li>
<li class="nav-item">
<a href="javascript:void(0)" onclick="toggleWmsLayer()" class="nav-link">
<i class="nav-icon fas fa-layer-group text-success"></i>
<p>WMS Dinámico <span class="badge badge-info right" id="wms-status">OFF</span></p>
</a>
</li>
<li class="nav-header">ADMINISTRACIÓN</li>
<li class="nav-item">
<a href="javascript:void(0)" onclick="updateMunicipalData()" class="nav-link" id="btn-update">
<i class="nav-icon fas fa-sync-alt" id="update-icon"></i>
<p id="update-text">Sincronizar FDW</p>
</a>
</li>
</ul>
</nav>
</div>
</aside>
<!-- Content Wrapper -->
<div class="content-wrapper">
<div id="map"></div>
<div id="legend" class="map-overlay card card-outline card-primary p-2">
<h6 class="text-xs font-weight-bold text-uppercase mb-2">Escala de Morosidad (Gs)</h6>
<div id="legend-content"></div>
</div>
</div>
</div>
<!-- Scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/js/adminlte.min.js"></script>
<script src="https://unpkg.com/maplibre-gl@3.6.2/dist/maplibre-gl.js"></script>
<script>
// Configuración desde LocalStorage (ADN SIGEM-GIS)
const token = localStorage.getItem('jwt');
const entidad = localStorage.getItem('entidad') || '505';
const userName = localStorage.getItem('user_name') || 'Operador';
// Si no hay token, redirigir al login
if (!token) window.location.href = '/gis-geoserver/login.html';
document.getElementById('user-display').innerText = userName;
document.getElementById('muni-title').innerText = `MUNICIPALIDAD ENTIDAD ${entidad}`;
// Inicialización del Mapa LibRe 3D Elite
const map = new maplibregl.Map({
container: 'map',
style: {
'version': 8,
'sources': {
'osm': {
'type': 'raster',
'tiles': ['https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'],
'tileSize': 256,
'attribution': '© OpenStreetMap'
},
'lotes-png': {
'type': 'raster',
'tiles': [
`${window.location.origin}/geoserver/sigem/wms?service=WMS&version=1.1.1&request=GetMap&layers=sigem:vw_lotes_morosidad_${entidad}&bbox={bbox-epsg-3857}&width=256&height=256&srs=EPSG:3857&format=image/png&transparent=true`
],
'tileSize': 256
},
'lotes-mvt': {
'type': 'vector',
'tiles': [`${window.location.origin}/gis-geoserver/sigem/gwc/service/tms/1.0.0/sigem:vw_lotes_morosidad_${entidad}@EPSG:900913@pbf/{z}/{x}/{y}.pbf`],
'minzoom': 13,
'maxzoom': 22
}
},
'layers': [
{ 'id': 'background-osm', 'type': 'raster', 'source': 'osm', 'minzoom': 0, 'maxzoom': 22 },
{ 'id': 'lotes-raster', 'type': 'raster', 'source': 'lotes-png', 'minzoom': 13, 'maxzoom': 22, 'paint': { 'raster-opacity': 0.8 } },
{
'id': 'lotes-layer',
'type': 'line',
'source': 'lotes-mvt',
'source-layer': `vw_lotes_morosidad_${entidad}`,
'paint': {
'line-color': '#444444',
'line-width': 0.5
}
}
]
},
center: [
parseFloat(localStorage.getItem('map_lng') || -56.446949),
parseFloat(localStorage.getItem('map_lat') || -25.456443)
],
zoom: parseInt(localStorage.getItem('map_zoom') || 14),
pitch: 0,
bearing: 0,
antialias: true
});
map.addControl(new maplibregl.NavigationControl(), 'top-right');
map.on('load', () => {
console.log("Mapa AdminLTE 3 Cargado - Entidad " + entidad);
loadMunicipalStats();
// Carga automática del tema de morosidad (Funcionalidad de Ayer)
applyMorosidadTheme();
});
// --- Funciones de Negocio GIS ---
function applyMorosidadTheme() {
const legend = document.getElementById('legend');
const legendContent = document.getElementById('legend-content');
legend.style.display = 'block';
const scale = [
{ limit: 0, color: '#6b9070', label: 'Sin Deuda 🟢' },
{ limit: 351585, color: '#b5c47a', label: 'Baja 🟡' },
{ limit: 714969, color: '#ffd966', label: 'Media 🟠' },
{ limit: 1226946, color: '#f08060', label: 'Alta 🔴' },
{ limit: 2099322, color: '#a91d1d', label: 'Crítica 💀' }
];
legendContent.innerHTML = scale.map(i => `
<div class="d-flex align-items-center mb-1">
<div style="width: 15px; height: 15px; background: ${i.color}; margin-right: 8px; border-radius: 2px;"></div>
<span class="text-xs">${i.label}</span>
</div>
`).join('');
map.setPaintProperty('lotes-layer', 'fill-color', [
'step',
['get', 'trb_total_deuda'],
'#6b9070',
351585, '#b5c47a',
714969, '#ffd966',
1226946, '#f08060',
2099322, '#a91d1d'
]);
map.setPaintProperty('lotes-layer', 'fill-outline-color', 'rgba(255, 255, 255, 0.4)');
}
function resetMap() {
document.getElementById('legend').style.display = 'none';
map.setPaintProperty('lotes-layer', 'fill-color', 'rgba(255, 255, 255, 0.05)');
if(map.getLayer('lotes-wms-layer')) {
map.setLayoutProperty('lotes-wms-layer', 'visibility', 'none');
document.getElementById('wms-status').innerText = 'OFF';
}
}
function toggleWmsLayer() {
if (!map.getSource('lotes-wms')) {
map.addSource('lotes-wms', {
'type': 'raster',
'tiles': [`${window.location.origin}/gis-geoserver/sigem/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=sigem:vw_lotes_morosidad_${entidad}&STYLES=morosidad_style_wms&FORMAT=image/png&TRANSPARENT=TRUE&WIDTH=256&HEIGHT=256&SRS=EPSG:3857&BBOX={bbox-epsg-3857}`],
'tileSize': 256
});
map.addLayer({ 'id': 'lotes-wms-layer', 'type': 'raster', 'source': 'lotes-wms', 'layout': { 'visibility': 'none' }, 'paint': { 'raster-opacity': 0.8 } }, 'lotes-layer');
}
const isVisible = map.getLayoutProperty('lotes-wms-layer', 'visibility') === 'visible';
const next = isVisible ? 'none' : 'visible';
map.setLayoutProperty('lotes-wms-layer', next);
document.getElementById('wms-status').innerText = next === 'visible' ? 'ON' : 'OFF';
}
async function loadMunicipalStats() {
try {
const res = await fetch(`/gis-geoserver/api/gis/entidad/${entidad}/resumen`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await res.json();
document.getElementById('total-lotes').innerText = data.total_lotes.toLocaleString();
document.getElementById('lotes-morosos').innerText = data.lotes_con_deuda.toLocaleString();
} catch (err) { console.error("Error stats:", err); }
}
async function updateMunicipalData() {
const icon = document.getElementById('update-icon');
const text = document.getElementById('update-text');
icon.classList.add('rotating');
text.innerText = 'Sincronizando...';
try {
const res = await fetch(`/gis-geoserver/api/admin/fdw/update/${entidad}`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await res.json();
alert(data.success ? "✅ Sincronización Exitosa" : "❌ Error: " + data.message);
if (data.success) location.reload();
} catch (err) { alert("❌ Error de servidor"); }
finally {
icon.classList.remove('rotating');
text.innerText = 'Sincronizar FDW';
}
}
// Popups de Datos (MVT)
map.on('click', 'lotes-layer', (e) => {
const props = e.features[0].properties;
new maplibregl.Popup()
.setLngLat(e.lngLat)
.setHTML(`
<div class="popup-header">ESTADO DE CUENTA: ${props.ccc || 'N/A'}</div>
<div class="popup-body">
<b>Ficha:</b> ${props.inm_ficha || '0'}<br>
<b style="color:red">Adeudado:</b> Gs. ${props.trb_total_deuda ? parseFloat(props.trb_total_deuda).toLocaleString('es-PY') : '0'}<br>
<b>Pagado:</b> Gs. ${props.trb_total_pago ? parseFloat(props.trb_total_pago).toLocaleString('es-PY') : '0'}<br>
<b>Último Pago:</b> ${props.ultimo_pago || 'Nunca'}
</div>
`).addTo(map);
});
</script>
</body>
</html>