Skip to content

Commit

Permalink
use map data event instead of interval when waiting for map to be ready
Browse files Browse the repository at this point in the history
  • Loading branch information
kochis committed Aug 14, 2024
1 parent 52bd214 commit aba7820
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
15 changes: 4 additions & 11 deletions src/ui/RadarLineFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,10 @@ class RadarLineFeature extends RadarMapFeature {
// ensure map is ready before modifying source and layers
if (map.loaded()) {
addFeatureToMap();
} else { // wait for map to load up to 3 seconds, or abort
let count = 0;
let interval = setInterval(() => {
if (map.loaded()) {
clearInterval(interval);
addFeatureToMap();
} else if (++count >= 30 /* 3 seconds */) {
clearInterval(interval);
Logger.warn(`could not add line feature ${feature.id}`);
}
}, 100);
} else {
map.once('data',() => { // wait for map to be ready
addFeatureToMap();
});
}

return this;
Expand Down
15 changes: 4 additions & 11 deletions src/ui/RadarPolygonFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,10 @@ class RadarPolygonFeature extends RadarMapFeature {
// ensure map is ready before modifying source and layers
if (map.loaded()) {
addFeatureToMap();
} else { // wait for map to load up to 3 seconds, or abort
let count = 0;
let interval = setInterval(() => {
if (map.loaded()) {
clearInterval(interval);
addFeatureToMap();
} else if (++count >= 30 /* 3 seconds */) {
clearInterval(interval);
Logger.warn(`could not add polygon feature ${feature.id}`);
}
}, 100);
} else {
map.once('data',() => { // wait for map to be ready
addFeatureToMap();
});
}

return this;
Expand Down

0 comments on commit aba7820

Please sign in to comment.