Skip to content

Commit

Permalink
fix: online issues (empty cache)
Browse files Browse the repository at this point in the history
  • Loading branch information
azarz committed Feb 20, 2025
1 parent aefba65 commit 7ec767b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/js/event-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function addListeners() {
if (Capacitor.isNativePlatform()) {
Globals.map.setGlyphs("https://data.geopf.fr/annexes/ressources/vectorTiles/fonts/{fontstack}/{range}.pbf");
}
Globals.offlineMaps.setOnlinePlanIgnSource();
} else {
PopupUtils.showOnlinePopup(`
<div id="onlinePopup">
Expand All @@ -227,6 +228,7 @@ function addListeners() {
// Active Plan IGN
if (!planIgnLayerBtn.classList.contains("selectedLayer")) {
planIgnLayerBtn.click();
setTimeout(() => Globals.offlineMaps.setOfflinePlanIgnSource(), 150);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/js/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if (!online) {
}
}
if (!hasPlanIGN) {
layersDisplayed.unshift(
layersDisplayed.push(
{
id: "PLAN.IGN.INTERACTIF$TMS",
opacity: 100,
Expand Down
2 changes: 1 addition & 1 deletion src/js/layer-manager/layer-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class LayerSwitcher extends EventTarget {
this.layers[id].style = data_2.layers; // sauvegarde !
} catch (e) {
if (fallback) {
fetchStyle(fallback, null);
return fetchStyle(fallback, null);
} else {
this.layers[id].error = true;
throw new Error(e);
Expand Down
17 changes: 2 additions & 15 deletions src/js/offline-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import maplibregl from "maplibre-gl";
import { Capacitor } from "@capacitor/core";
import { Filesystem, Directory, Encoding } from "@capacitor/filesystem";
import { Network } from "@capacitor/network";
import { KeepAwake } from "@capacitor-community/keep-awake";
import { openDB } from "idb";
import pLimit from "p-limit";
Expand Down Expand Up @@ -92,9 +91,6 @@ class OfflineMaps {
}
);

if (!Globals.online) {
this.#setOfflineSource();
}
const container = this.options.container || document.getElementById("offlineMapsWindow");
this.dom = {
selectOnMapScreen: container.querySelector("#offlineMapsWindowSelectOnMap"),
Expand Down Expand Up @@ -223,15 +219,6 @@ class OfflineMaps {
* Listeners...
*/
#listeners() {
Network.addListener("networkStatusChange", (status) => {
let newStatus = status.connected;
if (newStatus) {
this.#setOnlineSource();
} else {
this.#setOfflineSource();
}
});

this.map.on("move", () => {
if (this.map.getZoom() < 8) {
this.dom.locationSelectBtn.classList.add("disabled");
Expand Down Expand Up @@ -457,7 +444,7 @@ class OfflineMaps {
/**
* Sets plan_ign layers to have the offline source
*/
#setOfflineSource() {
setOfflinePlanIgnSource() {
this.map.getStyle().layers.forEach((layer) => {
if (layer.source === "plan_ign") {
this.#setLayerSource(this.map, layer.id, "offline-plan-ign");
Expand All @@ -468,7 +455,7 @@ class OfflineMaps {
/**
* Sets plan_ign layers to have the online source
*/
#setOnlineSource() {
setOnlinePlanIgnSource() {
this.map.getStyle().layers.forEach((layer) => {
if (layer.source === "offline-plan-ign") {
this.#setLayerSource(this.map, layer.id, "plan_ign");
Expand Down

0 comments on commit 7ec767b

Please sign in to comment.