Skip to content

Commit

Permalink
...as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
StrawberryMaster committed Jan 16, 2025
1 parent ae7e1dd commit 84525e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 59 deletions.
48 changes: 23 additions & 25 deletions static/js/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class MapManager {
constructor() {
this.config = {
mapUrls: {
"xlarge": "/static/media/bg16383.webp",
"large-nxtgen": "/static/media/bg21600-nxtgen.jpg",
"large": "/static/media/bg12000.jpg",
"blkmar": "/static/media/bg13500-blkmar.jpg",
"normal": "/static/media/bg8192.png",
"xlarge": "static/media/bg16383.webp",
"large-nxtgen": "static/media/bg21600-nxtgen.jpg",
"large": "static/media/bg12000.jpg",
"blkmar": "static/media/bg13500-blkmar.jpg",
"normal": "static/media/bg8192.png",
},
selectors: {
mapIndicator: "#map-indicator",
Expand All @@ -50,14 +50,13 @@ class MapManager {
statusIcon: document.querySelector(this.config.selectors.statusIcon)
};

this.worker = new Worker('/static/js/worker.js');
this.worker.onmessage = this.handleWorkerMessage.bind(this);

this.blueMarble = null;
this.blueMarble = new Image();
this.blueMarble.crossOrigin = "anonymous";

this.handleMapChange = this.handleMapChange.bind(this);
this.handleButtonClick = this.handleButtonClick.bind(this);
this.handleWorkerMessage = this.handleWorkerMessage.bind(this);
this.handleMapLoad = this.handleMapLoad.bind(this);
this.handleMapError = this.handleMapError.bind(this);

this.init();
}
Expand Down Expand Up @@ -88,6 +87,9 @@ class MapManager {
this.handleButtonClick(button.dataset.size);
});
});

this.blueMarble.addEventListener('load', this.handleMapLoad);
this.blueMarble.addEventListener('error', this.handleMapError);
}

handleMapChange() {
Expand All @@ -100,27 +102,23 @@ class MapManager {
this.showLoader();
}

handleWorkerMessage(event) {
const { status, blueMarble, error } = event.data;

if (status === 'success') {
this.blueMarble = blueMarble;
this.state.loaded = true;
this.hideLoader();
this.updateStatus('success');
} else {
console.error('Yikes. Something went wrong.', error);
this.hideLoader();
this.updateStatus('error');
}
handleMapLoad() {
this.state.loaded = true;
this.hideLoader();
this.updateStatus('success');
}

handleMapError(error) {
console.error('Yikes. Something went wrong.', error);
this.hideLoader();
this.updateStatus('error');
}

loadMap(size) {
const mapUrl = this.getMapUrl(size);
if (mapUrl !== this.state.currentMap) {
this.state.currentMap = mapUrl;
this.state.loaded = false;
this.worker.postMessage({ url: mapUrl });
this.blueMarble.src = mapUrl;
}
}

Expand Down
34 changes: 0 additions & 34 deletions static/js/worker.js

This file was deleted.

0 comments on commit 84525e0

Please sign in to comment.