Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
proyecto-covid-threejs-igev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jonschi
proyecto-covid-threejs-igev
Commits
f2540dc7
Commit
f2540dc7
authored
Mar 31, 2022
by
jonschi
Browse files
Options
Downloads
Patches
Plain Diff
unify file loading and wait for all files to load before showing globe
parent
df3e4abb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
frontend/src/App.vue
+10
-14
10 additions, 14 deletions
frontend/src/App.vue
frontend/src/helpers/fileLoader.js
+0
-22
0 additions, 22 deletions
frontend/src/helpers/fileLoader.js
frontend/src/helpers/loader.js
+60
-0
60 additions, 0 deletions
frontend/src/helpers/loader.js
with
70 additions
and
36 deletions
frontend/src/App.vue
+
10
−
14
View file @
f2540dc7
<
script
setup
>
import
{
loadJsonFile
}
from
"
./helpers/fileLoader
"
;
import
Globe
from
"
./components/Globe.vue
"
;
import
Sidebar
from
"
./components/Sidebar.vue
"
;
import
VCenter
from
"
./components/VCenter.vue
"
;
import
Spinner
from
"
./components/Spinner.vue
"
;
import
load
from
"
./helpers/
textures
.js
"
;
import
load
from
"
./helpers/
loader
.js
"
;
import
{
ref
}
from
"
vue
"
;
import
{
computed
}
from
"
@vue/reactivity
"
;
import
moment
from
"
moment
"
;
...
...
@@ -17,33 +15,31 @@ moment.updateLocale("en", {
doy
:
4
,
// First week of year must contain 4 January (7 + 1 - 4)
},
});
const
globeTextureFile
=
"
../src/assets/8081_earthmap10k.jpeg
"
;
const
skyboxTextureFile
=
'
../src/assets/skybox/corona
'
;
const
geoDataFile
=
"
../src/assets/NUTS_RG_60M_2021_4326.geojson
"
;
const
covidDataFile
=
"
../src/assets/sample-covid-data-2022-13.json
"
;
const
initialDate
=
"
2022-03-14T00:00:00.000Z
"
;
// TODO: determine last date somehow?
const
artificialLoadingTime
=
0
;
const
loading
=
ref
(
true
);
const
geoData
=
ref
({});
const
covidData
=
ref
({});
const
textures
=
ref
({});
const
selectedNutsCode
=
ref
(
null
);
const
selectedDate
=
ref
(
null
);
// Wait until all data is loaded
Promise
.
all
([
load
J
sonFile
(
geoDataFile
),
load
J
sonFile
(
covidDataFile
),
load
.
globeTexture
(),
load
.
skyboxTexture
()
load
.
j
sonFile
(
geoDataFile
),
load
.
j
sonFile
(
covidDataFile
),
load
.
globeTexture
(
globeTextureFile
),
load
.
skyboxTexture
(
skyboxTextureFile
)
]).
then
(([
loadedGeoData
,
loadedCovidData
,
loadedGlobeTexture
,
loadedSkyboxTexture
])
=>
{
geoData
.
value
=
loadedGeoData
;
covidData
.
value
=
loadedCovidData
;
textures
.
value
.
globeTexture
=
loadedGlobeTexture
;
textures
.
value
.
skyboxTexture
=
loadedSkyboxTexture
;
selectedDate
.
value
=
new
Date
(
initialDate
);
// give three.js time to draw the globe
setTimeout
(()
=>
{
loading
.
value
=
false
;
},
artificialLoadingTime
);
});
const
search
=
function
()
{
...
...
@@ -108,7 +104,7 @@ const jumpCurrentWeek = function () {
/>
</div>
<transition
name=
"fade"
>
<div
v-if=
"
loading
"
class=
"loading-container"
>
<div
v-if=
"
!dataLoaded
"
class=
"loading-container"
>
<VCenter>
<Spinner
/>
<br
/>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/helpers/fileLoader.js
deleted
100644 → 0
+
0
−
22
View file @
df3e4abb
import
*
as
THREE
from
'
three
'
;
const
fileLoader
=
new
THREE
.
FileLoader
();
// Create awaitable version of file loader
function
loadJsonFile
(
location
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fileLoader
.
load
(
location
,
(
data
)
=>
{
resolve
(
JSON
.
parse
(
data
));
},
null
,
(
event
)
=>
{
reject
(
event
);
})
})
}
export
{
loadJsonFile
}
This diff is collapsed.
Click to expand it.
frontend/src/helpers/loader.js
0 → 100644
+
60
−
0
View file @
f2540dc7
import
{
FileLoader
,
TextureLoader
,
MeshBasicMaterial
,
BackSide
}
from
'
three
'
;
const
fileLoader
=
new
FileLoader
();
const
textureLoader
=
new
TextureLoader
();
function
jsonFile
(
location
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fileLoader
.
load
(
location
,
(
data
)
=>
{
resolve
(
JSON
.
parse
(
data
));
},
null
,
(
event
)
=>
{
reject
(
event
);
})
})
}
function
asyncLoadTexture
(
path
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
textureLoader
.
load
(
path
,
(
result
)
=>
{
resolve
(
result
)
})
});
}
const
globeTexture
=
async
function
(
location
)
{
return
await
asyncLoadTexture
(
location
);
}
function
createPathStrings
(
filename
)
{
const
fileType
=
"
.png
"
;
const
sides
=
[
"
ft
"
,
"
bk
"
,
"
up
"
,
"
dn
"
,
"
rt
"
,
"
lf
"
];
const
pathStings
=
sides
.
map
((
side
)
=>
{
return
filename
+
"
_
"
+
side
+
fileType
;
});
return
pathStings
;
}
const
skyboxTexture
=
async
function
(
location
)
{
const
loader
=
new
TextureLoader
();
const
skyboxImagepaths
=
createPathStrings
(
location
);
const
materialArray
=
Promise
.
all
(
skyboxImagepaths
.
map
(
async
(
image
)
=>
{
let
texture
=
await
asyncLoadTexture
(
image
);
return
new
MeshBasicMaterial
({
map
:
texture
,
side
:
BackSide
,
transparent
:
true
,
opacity
:
0.5
,
});
}));
return
materialArray
;
}
export
default
{
jsonFile
,
globeTexture
,
skyboxTexture
,
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment