forked from fabiomb/TravelMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_map_cache.html
More file actions
287 lines (257 loc) · 10.6 KB
/
clear_map_cache.html
File metadata and controls
287 lines (257 loc) · 10.6 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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Limpiar Caché del Mapa - TravelMap</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-top: 0;
}
.info {
background: #e3f2fd;
border-left: 4px solid #2196f3;
padding: 15px;
margin: 20px 0;
border-radius: 4px;
}
.warning {
background: #fff3e0;
border-left: 4px solid #ff9800;
padding: 15px;
margin: 20px 0;
border-radius: 4px;
}
.success {
background: #e8f5e9;
border-left: 4px solid #4caf50;
padding: 15px;
margin: 20px 0;
border-radius: 4px;
display: none;
}
.error {
background: #ffebee;
border-left: 4px solid #f44336;
padding: 15px;
margin: 20px 0;
border-radius: 4px;
display: none;
}
button {
background: #2196f3;
color: white;
border: none;
padding: 12px 24px;
font-size: 16px;
border-radius: 4px;
cursor: pointer;
width: 100%;
margin: 10px 0;
}
button:hover {
background: #1976d2;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.btn-secondary {
background: #757575;
}
.btn-secondary:hover {
background: #616161;
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
font-family: monospace;
font-size: 14px;
}
a {
color: #2196f3;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>🗺️ Limpiar Caché del Mapa</h1>
<div class="info">
<strong>¿Para qué sirve esto?</strong><br>
Esta herramienta limpia la caché de los tiles (imágenes) del mapa almacenados por el Service Worker.
Esto es útil cuando:
<ul>
<li>Los mapas no se actualizan</li>
<li>Ves tiles viejos o corruptos</li>
<li>Has cambiado configuración del mapa y no se aplica</li>
<li>Quieres forzar la descarga de tiles frescos</li>
</ul>
</div>
<div class="warning">
<strong>⚠️ Nota importante sobre tiles raster (Leaflet):</strong><br>
Los tiles raster son imágenes pre-renderizadas que no pueden cambiar el idioma dinámicamente.
Si usas Leaflet, los nombres seguirán en el idioma predefinido del servidor de tiles.
<br><br>
<strong>Para soporte real de multilenguaje, usa MapLibre GL</strong> en Configuración > Mapa.
</div>
<div class="success" id="successMsg">
✅ Caché limpiada correctamente. Los tiles se descargarán de nuevo al cargar el mapa.
</div>
<div class="error" id="errorMsg">
❌ Error al limpiar la caché. Puede que tu navegador no soporte Service Workers.
</div>
<div id="status"></div>
<button onclick="clearCache()" id="clearBtn">
🧹 Limpiar Caché del Mapa
</button>
<button onclick="clearAllSiteCache()" class="btn-secondary" id="clearAllBtn">
🗑️ Limpiar Toda la Caché del Sitio
</button>
<button onclick="unregisterServiceWorker()" class="btn-secondary" id="unregisterBtn">
⚠️ Desregistrar Service Worker
</button>
<div style="margin-top: 30px; text-align: center;">
<a href="index.php">← Volver al mapa</a>
</div>
</div>
<script>
function updateStatus(message, type = 'info') {
const status = document.getElementById('status');
status.className = 'status';
status.textContent = message;
status.style.background = type === 'success' ? '#e8f5e9' :
type === 'error' ? '#ffebee' : '#e3f2fd';
}
async function clearCache() {
const btn = document.getElementById('clearBtn');
btn.disabled = true;
btn.textContent = 'Limpiando...';
try {
if (!('serviceWorker' in navigator)) {
throw new Error('Service Workers no soportados en este navegador');
}
// Send message to service worker to clear cache
const registration = await navigator.serviceWorker.ready;
if (registration.active) {
registration.active.postMessage('clearCache');
// Also clear browser cache
const cacheNames = await caches.keys();
const travelMapCaches = cacheNames.filter(name => name.startsWith('travelmap-'));
updateStatus(`Limpiando ${travelMapCaches.length} caché(s)...`);
await Promise.all(
travelMapCaches.map(name => caches.delete(name))
);
document.getElementById('successMsg').style.display = 'block';
document.getElementById('errorMsg').style.display = 'none';
updateStatus(`✅ ${travelMapCaches.length} caché(s) eliminada(s)`, 'success');
} else {
throw new Error('No hay Service Worker activo');
}
} catch (error) {
console.error('Error clearing cache:', error);
document.getElementById('successMsg').style.display = 'none';
document.getElementById('errorMsg').style.display = 'block';
updateStatus('❌ Error: ' + error.message, 'error');
} finally {
btn.disabled = false;
btn.textContent = '🧹 Limpiar Caché del Mapa';
}
}
async function clearAllSiteCache() {
const btn = document.getElementById('clearAllBtn');
if (!confirm('¿Estás seguro? Esto eliminará TODA la caché del sitio.')) {
return;
}
btn.disabled = true;
btn.textContent = 'Limpiando todo...';
try {
const cacheNames = await caches.keys();
updateStatus(`Limpiando ${cacheNames.length} caché(s) del sitio...`);
await Promise.all(
cacheNames.map(name => caches.delete(name))
);
document.getElementById('successMsg').style.display = 'block';
updateStatus(`✅ ${cacheNames.length} caché(s) eliminada(s)`, 'success');
} catch (error) {
console.error('Error:', error);
document.getElementById('errorMsg').style.display = 'block';
updateStatus('❌ Error: ' + error.message, 'error');
} finally {
btn.disabled = false;
btn.textContent = '🗑️ Limpiar Toda la Caché del Sitio';
}
}
async function unregisterServiceWorker() {
const btn = document.getElementById('unregisterBtn');
if (!confirm('¿Estás seguro? Esto desregistrará el Service Worker. Tendrás que recargar la página para volver a registrarlo.')) {
return;
}
btn.disabled = true;
btn.textContent = 'Desregistrando...';
try {
if (!('serviceWorker' in navigator)) {
throw new Error('Service Workers no soportados');
}
const registrations = await navigator.serviceWorker.getRegistrations();
updateStatus(`Desregistrando ${registrations.length} Service Worker(s)...`);
await Promise.all(
registrations.map(reg => reg.unregister())
);
// Also clear all caches
const cacheNames = await caches.keys();
await Promise.all(
cacheNames.map(name => caches.delete(name))
);
document.getElementById('successMsg').style.display = 'block';
updateStatus('✅ Service Worker desregistrado y caché limpiada. Recarga la página.', 'success');
} catch (error) {
console.error('Error:', error);
document.getElementById('errorMsg').style.display = 'block';
updateStatus('❌ Error: ' + error.message, 'error');
} finally {
btn.disabled = false;
btn.textContent = '⚠️ Desregistrar Service Worker';
}
}
// Check service worker status on load
window.addEventListener('load', async () => {
if ('serviceWorker' in navigator) {
try {
const registration = await navigator.serviceWorker.getRegistration();
if (registration) {
updateStatus('✓ Service Worker detectado y activo');
} else {
updateStatus('ℹ️ No hay Service Worker registrado', 'info');
}
} catch (error) {
updateStatus('⚠️ Error al verificar Service Worker', 'error');
}
} else {
updateStatus('⚠️ Service Workers no soportados en este navegador', 'error');
document.getElementById('clearBtn').disabled = true;
document.getElementById('clearAllBtn').disabled = true;
document.getElementById('unregisterBtn').disabled = true;
}
});
</script>
</body>
</html>