Skip to content

Commit

Permalink
update service-worker & offline
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcrb3 committed Jul 4, 2024
1 parent 03b331f commit a896f26
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 34 deletions.
2 changes: 2 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ <h4 style="margin-bottom: 10px">Serveis a mostrar:</h4>
<input type="color" id="layerColor" name="layerColor" value="#f9f91d">
<label for="markerColor">Color del marcador:</label>
<input type="color" id="markerColor" name="markerColor" value="#FF6E42">
<!-- <label for="toponimia">Toponimia:</label>
<input type="checkbox" id="toponimia" name="toponimia" checked> -->
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ <h4 style="margin-bottom: 10px">Serveis a mostrar:</h4>
<input type="color" id="layerColor" name="layerColor" value="#f9f91d">
<label for="markerColor">Color del marcador:</label>
<input type="color" id="markerColor" name="markerColor" value="#FF6E42">
<!-- <label for="toponimia">Toponimia:</label>
<input type="checkbox" id="toponimia" name="toponimia" checked> -->
</div>
</div>

Expand Down
58 changes: 58 additions & 0 deletions offline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="ca">

<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="
https://www.googletagmanager.com/gtag/js?id=G-GR9JCZYNFH"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-46332195-11');
</script>
<meta charset='utf-8'>
<meta name='viewport' content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<!--
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/svelte-material-ui@4.2.0/bare.min.css" />
-->
<meta name="author" content="Institut Cartogràfic i Geològic de Catalunya" />
<link rel="manifest" href="manifest.json">
<meta property="fb:app_id" content="620717167980164" />
<meta property="og:title" content="API Territorial" />
<meta property="og:type" content="website" />
<meta property="og:image" content="icgc_icon_512.png" />
<meta property="og:image:type" content="image/png" />
<meta property="og:url" content="API Territorial" />
<meta property="og:description" content="API Territorial" />
<meta name="description" content="ContexMaps" />
<meta name="robots" content="index,follow" />
<meta name="keywords" content="Catalunya, visor">
<meta name="geo.region" content="ES-CT" />
<meta name="geo.placename" content="Barcelona" />
<meta name="geo.position" content="41.363892,2.186279" />
<meta name="language" content="ca" />
<title>API Territorial</title>
<!--
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
-->
<link href="https://fonts.googleapis.com/css?family=Material+Icons+Outlined|Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet">

<link rel='icon' type='image/png' href='favicon.png'>
<!---->

<!--
<script src='https://api.mapbox.com/mapbox-gl-js/v1.13.1/mapbox-gl.js'></script>
-->

</head>

<body>
</body>

</html>
68 changes: 45 additions & 23 deletions serviceworker.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,71 @@
'use strict';

// Update cache names any time any of the cached files change.
const CACHE_NAME = 'static-cache-v1';

// Add list of files to cache here.
const FILES_TO_CACHE = [
'offline.html',
];

self.addEventListener('install', (evt) => {
// console.log('[ServiceWorker] Install');
// console.log('[ServiceWorker] Install');
evt.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
// console.log('[ServiceWorker] Pre-caching offline page');
return cache.addAll(FILES_TO_CACHE);
})
caches.open(CACHE_NAME).then((cache) => {
// console.log('[ServiceWorker] Pre-caching offline page');
return cache.addAll(FILES_TO_CACHE);
})
);
self.skipWaiting();
});

self.addEventListener('activate', (evt) => {
// console.log('[ServiceWorker] Activate');
// console.log('[ServiceWorker] Activate');
// Remove previous cached data from disk.
evt.waitUntil(
caches.keys().then((keyList) => {
return Promise.all(keyList.map((key) => {
if (key !== CACHE_NAME) {
// console.log('[ServiceWorker] Removing old cache', key);
return caches.delete(key);
}
}));
})
caches.keys().then((keyList) => {
return Promise.all(keyList.map((key) => {
if (key !== CACHE_NAME) {
// console.log('[ServiceWorker] Removing old cache', key);
return caches.delete(key);
}
}));
})
);
self.clients.claim();
});

self.addEventListener('fetch', (evt) => {
// console.log('[ServiceWorker] Fetch', evt.request.url);
// console.log('[ServiceWorker] Fetch', evt.request.url);
// Add fetch event handler here.
if (evt.request.url.startsWith('https://geoserveis.icgc.cat/servei/catalunya')) {
evt.respondWith(
caches.open(CACHE_NAME).then((cache) => {
return cache.match(evt.request).then((response) => {
if (response) {
return response;
}
return fetch(evt.request).then((networkResponse) => {
cache.put(evt.request, networkResponse.clone());
return networkResponse;
});
});
})
);
return;
}

if (evt.request.mode !== 'navigate') {
// Not a page navigation, bail.
return;
}

evt.respondWith(
fetch(evt.request)
.catch(() => {
return caches.open(CACHE_NAME)
.then((cache) => {
return cache.match('offline.html');
});
})
fetch(evt.request).catch(() => {
return caches.open(CACHE_NAME)
.then((cache) => {
return cache.match('offline.html');
});
})
);
});
});
90 changes: 79 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function onBaseChange() {
}

}
//Topogràfic
if (base === 'topo') {
map.setSky({
'sky-color': '#a5f0f0',
Expand All @@ -75,6 +76,7 @@ export async function onBaseChange() {
'fog-color': '#c5d6d6'
});
}
//Ortofoto
else if (base === 'orto') {
map.setSky({
'sky-color': '#37709e',
Expand All @@ -85,6 +87,7 @@ export async function onBaseChange() {
'fog-color': '#c5d6d6'
});
}
//Mapa fosc
else if (base === 'fosc') {
map.setSky({
'sky-color': '#232423',
Expand Down Expand Up @@ -400,17 +403,6 @@ function initMap() {
'horizon-fog-blend': 0.9,
'fog-ground-blend': 0.85,
'fog-color': '#c5d6d6'
/* "atmosphere-blend": [
"interpolate",
["linear"],
["zoom"],
0,
1,
10,
1,
12,
0
] */
});

//test
Expand Down Expand Up @@ -615,7 +607,81 @@ function hideMapLoader() {
document.getElementById('mapLoader').style.display = 'none';
}

//toponimia
/* const arrayCapes = [
"water-name-ocean",
"water-name-mars",
"water-name-lakeline-z12",
"water-name-lakeline-MM",
"highway-name-pedestrian",
"highway-name-minor",
"highway-name-major",
"highway-shield-tertiary",
"highway-shield-primary",
"highway-shield-motorway_B_10_B-20",
"highway-shield-motorway",
"highway-shield-motorway_z8",
"airport-label-1",
"airport-label-2",
"poi-orography-altimetria",
"poi-level-3_icgc",
"place-other-xarxa_viaria",
"place-other-4",
"place-other-orography",
"place-isolated",
"highway-minor-square-1",
"highway-minor-square-2",
"place-other-serveis",
"place-other-neighbourhood",
"place-village",
"place-village_icgc",
"place-nommuni",
"place-city-z10_icgc",
"place-city-z8_icgc",
"place-city-z7_icgc",
"place-city",
"place-city-bcn_icgc",
"place-town",
"place-continent",
"place-country-other",
"place-country-adm1_2",
"place-country-3",
"place-country-2",
"place-country-1",
];
function setVisibility(isVisible) {
try {
const vis = isVisible ? "visible" : "none";
arrayCapes.forEach((capa) => {
if (map && map.getLayer(capa)) {
map.setLayoutProperty(capa, "visibility", vis);
}
});
} catch (err) {
console.log(err);
}
} */

/* var toponimiaCheckbox = document.getElementById('toponimia');
// Afegeix un event listener per capturar canvis a l'estat del checkbox
toponimiaCheckbox.addEventListener('change', function () {
const isChecked = toponimiaCheckbox.checked;
// Aquí pots fer el que calgui quan el checkbox canvia d'estat (marcat o no marcat)
if (isChecked) {
// Codi per activar la toponímia
console.log('Toponimia activada');
setVisibility(true)
// Aquí podríes cridar funcions o fer altres accions segons calgui
} else {
// Codi per desactivar la toponímia
console.log('Toponimia desactivada');
setVisibility(false)
// Aquí podríes cridar funcions o fer altres accions segons calgui
}
});
*/
// Crear una classe per al control de pitch
class PitchControl {
onAdd(map) {
Expand All @@ -641,6 +707,8 @@ class PitchControl {
}
}



function mapSettings() {
var notification = document.getElementById("notification");
if (notification) {
Expand Down

0 comments on commit a896f26

Please sign in to comment.