Skip to content

Commit

Permalink
Synchronize with sprite image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Apr 17, 2023
1 parent 0ebb923 commit 942b3c6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions js/japan-eq-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ Object.assign(panel, {
});
mapElement.appendChild(panel);

Promise.all([
new Promise(resolve => map.once('load', resolve)),
new Promise(resolve => map.on('data', e => {
if (e.dataType === 'style' &&
e.style.imageManager.listImages().length === Object.keys(INTENSITY_LOOKUP).length) {
resolve();
}
}))
]).then(() => {
loaded = true;
map.fire({type: 'allload'});
});

Promise.all([
fetch('https://www.jma.go.jp/bosai/quake/data/list.json').then(res => res.json()),
fetch('data/hypocenters.json').then(res => res.json()).then(data =>
Expand Down Expand Up @@ -315,12 +328,7 @@ Promise.all([
}).catch(err => {
initialParams.id = undefined;
}) : Promise.resolve(),
new Promise(resolve => {
map.once('styledata', resolve);
map.once('load', () => {
loaded = true;
});
})
new Promise(resolve => map.once('styledata', resolve))
]).then(([quakes, hypocenterLayer]) => {
map.addLayer(hypocenterLayer, 'waterway');

Expand Down Expand Up @@ -709,7 +717,7 @@ Promise.all([
if (!auto) {
hypocenterLayer.setProps({onHover});
} else {
map.once(loaded ? 'idle' : 'load', () => {
map.once(loaded ? 'idle' : 'allload', () => {
setHypocenter(initialParams);
updateIntensity().then(() => {
if (!interactive) {
Expand Down

0 comments on commit 942b3c6

Please sign in to comment.