Merge pull request #1254 from Hans5958/abort-abort1

Improve canvas loading (3)
This commit is contained in:
Stefano 2022-04-15 14:19:18 +02:00 committed by GitHub
commit 0aefab7540
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 15 deletions

View file

@ -125,7 +125,7 @@ header {
background-color: #555;
border-right: 1px #000 solid;
border-bottom: 1px #000 solid;
z-index: 2000;
z-index: 2100;
display: inline-block;
}
@ -250,7 +250,16 @@ #loading {
left: 0;
right: 0;
bottom: 0;
z-index: 2000;
}
[data-init-done][data-canvas-loading='false'] #loading {
display: none
}
[data-init-done] #loading {
z-index: 1000;
animation: fadeInOut 4s linear 0s 1;
}
#loading > div {
@ -274,10 +283,25 @@ #loading > div > div:first-child {
}
#loading > div > span {
font-family: "DejaVu Sans", Helvetica, sans-serif;
font-family: dejavu, Helvetica, sans-serif;
font-weight: 200;
}
@keyframes fadeInOut {
0% {
opacity: 0;
}
50% {
opacity: 0;
}
52.5% {
opacity: 1;
}
100% {
opacity: 1;
}
}
@keyframes spinner {
from {
transform: rotateZ(0deg);
@ -609,7 +633,7 @@ .overlay {
background-color: rgba(0, 0, 0, .8);
display: none;
justify-content: center;
z-index: 1000;
z-index: 2000;
}
#exportWindow {
@ -657,7 +681,7 @@ #coordsWrapper {
position: absolute;
display: flex;
gap: 10px;
z-index: 100;
z-index: 1100;
top: 5px;
left: 364px;
}
@ -764,6 +788,11 @@ #timeControls:hover #timeControlsTooltip {
display: flex;
}
#zoomControls,
#timeControls {
z-index: 1100;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
@ -786,7 +815,7 @@ #author {
border: 1px #000 solid;
padding: 3px;
font-size: 12px;
z-index: 1100;
z-index: 2100;
min-width: 320px;
text-align: center;
display: flex;
@ -1141,7 +1170,7 @@ #donateButton {
#donateWindow {
display: inline-block;
z-index: 2000;
z-index: 2100;
max-width: 400px;
background-color: #444;
border: 1px #000 solid;

View file

@ -1,2 +1,6 @@
/*
Access-Control-Allow-Origin: *
/_img/place/*.png
cache-control: public, max-age=604800

View file

@ -186,8 +186,6 @@ async function init(){
initView();
}
document.getElementById("loading").style.display = "none";
document.getElementById("zoomInButton").addEventListener("click", function(e){
/*if(zoomAnimationFrame){
@ -496,4 +494,6 @@ async function init(){
applyView();
});
document.body.dataset.initDone = ''
}

View file

@ -96,6 +96,9 @@ const timeConfig = [
let slider = document.getElementById("timeControlsSlider");
let tooltip = document.getElementById("timeControlsTooltip")
let image = document.getElementById("image");
let abortController = new AbortController()
let currentUpdateIndex = 0
let updateTimeout = setTimeout(null, 0)
let timeCallback = (a) => {};
let atlasBackup = [];
@ -106,14 +109,29 @@ slider.value = timeConfig.length;
updateTime(slider.value)
slider.addEventListener("input", (event) => {
updateTime(parseInt(event.target.value))
updateTooltip(parseInt(event.target.value))
clearTimeout(updateTimeout)
updateTimeout = setTimeout(() => {
updateTime(parseInt(event.target.value))
}, 100)
})
async function updateTime(index) {
document.body.dataset.canvasLoading = true
abortController.abort()
abortController = new AbortController()
currentUpdateIndex++
let myUpdateIndex = currentUpdateIndex
let configObject = timeConfig[index-1];
if (!configObject.image) {
console.log("fetching");
let fetchResult = await fetch(configObject.url);
let fetchResult = await fetch(configObject.url, {
signal: abortController.signal
});
if (currentUpdateIndex !== myUpdateIndex) {
hideLoading()
return
}
let imageBlob = await fetchResult.blob();
configObject.image = URL.createObjectURL(imageBlob);
}
@ -125,13 +143,16 @@ async function updateTime(index) {
atlas = []
}
timeCallback(atlas)
document.body.dataset.canvasLoading = false
}
function updateTooltip(index) {
var configObject = timeConfig[index-1]
if (typeof configObject.timestamp === "number") tooltip.querySelector('p').textContent = new Date(configObject.timestamp*1000).toUTCString()
else tooltip.querySelector('p').textContent = configObject.timestamp
tooltip.style.left = (((slider.offsetWidth)*(slider.value-1)/(slider.max-1)) - tooltip.offsetWidth/2) + "px"
}
tooltip.parentElement.addEventListener('mouseenter', () => tooltip.style.left = (((slider.offsetWidth)*(slider.value-1)/(slider.max-1)) - tooltip.offsetWidth/2) + "px"
)
tooltip.parentElement.addEventListener('mouseenter', () => updateTooltip(parseInt(slider.value)))
window.addEventListener('resize', () => tooltip.style.left = (((slider.offsetWidth)*(slider.value-1)/(slider.max-1)) - tooltip.offsetWidth/2) + "px"
)
window.addEventListener('resize', () => updateTooltip(parseInt(slider.value)))

View file

@ -140,7 +140,7 @@ objectsContainer.addEventListener("scroll", function(e){
updateLines();
});
window.addEventListener("resize", function(){
window.addEventListener("resize", function(e){
//console.log(document.documentElement.clientWidth, document.documentElement.clientHeight);
var viewportWidth = document.documentElement.clientWidth;