Skip to content

Commit

Permalink
save last movement on the map
Browse files Browse the repository at this point in the history
  • Loading branch information
FallBackITA27 committed May 14, 2024
1 parent 6a6df7c commit b9fdc92
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions gtav-interactive-map/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ let insertMarkersMode = false;
let saveData = {
profile0: {
selectedTileLayer: "game",
lastZoom: 0,
lastCoords: [-90, 64.69999694824219],
}
}

var map = L.map('map', {
center: [-90, 64.69999694824219],
zoom: 0,
let temporarySaveData = localStorage.getItem("saveData");
if (temporarySaveData != null) saveData = JSON.parse(temporarySaveData);
saveDataSave();

let map = L.map('map', {
center: saveData.profile0.lastCoords,
zoom: saveData.profile0.lastZoom,
inertia: true,
worldCopyJump: false,
attributionControl: false
Expand All @@ -28,15 +34,25 @@ const constantData = {
},
}

map.on("zoomend", function (e) {
let x = map.getCenter();
saveData.profile0.lastCoords = [x.lat.toFixed(6), x.lng.toFixed(6)];
saveData.profile0.lastZoom = map.getZoom();
saveDataSave();
});

map.on("moveend", function(e) {
let x = map.getCenter();
saveData.profile0.lastCoords = [x.lat.toFixed(6), x.lng.toFixed(6)];
saveDataSave();
});

function saveDataSave() {
console.log(saveData);
localStorage.setItem("saveData", JSON.stringify(saveData));
}

async function loadDynamicData() {
let temporarySaveData = localStorage.getItem("saveData");
if (temporarySaveData != null) saveData = JSON.parse(temporarySaveData);
saveDataSave();

let x = [];
x.push(
fetch("./assets/figurines.json").then(r=>r.json()).then(r=>genericCollectibleInsert(document.getElementById("actionFiguresDiv"), r, constantData.icons.figurine))
Expand Down

0 comments on commit b9fdc92

Please sign in to comment.