Add guard to fix overlapping regional forecast icons after a period of time

This commit is contained in:
mrkmntal 2026-04-12 13:13:15 -04:00
commit a23eb483ea

View file

@ -21,6 +21,7 @@ class RegionalForecast extends WeatherDisplay {
this.locationMarker = null; this.locationMarker = null;
this.nearbyMarkers = []; this.nearbyMarkers = [];
this.nearbyMarkersKey = ''; this.nearbyMarkersKey = '';
this.refreshingMarkers = false;
} }
async getData(weatherParameters, refresh) { async getData(weatherParameters, refresh) {
@ -54,30 +55,36 @@ class RegionalForecast extends WeatherDisplay {
} }
async refreshNearbyMarkers() { async refreshNearbyMarkers() {
if (!this.map || !this.active) return; if (!this.map || !this.active || this.refreshingMarkers) return;
this.map.invalidateSize(false); this.refreshingMarkers = true;
this.map.setView([this.weatherParameters.latitude, this.weatherParameters.longitude], 6);
const bounds = this.map.getBounds(); try {
const markerKey = [ this.map.invalidateSize(false);
this.weatherParameters.latitude.toFixed(2), this.map.setView([this.weatherParameters.latitude, this.weatherParameters.longitude], 6);
this.weatherParameters.longitude.toFixed(2),
bounds.getSouth().toFixed(2),
bounds.getWest().toFixed(2),
bounds.getNorth().toFixed(2),
bounds.getEast().toFixed(2),
].join(':');
if (this.nearbyMarkers.length > 0 && this.nearbyMarkersKey === markerKey) return; const bounds = this.map.getBounds();
const markerKey = [
this.weatherParameters.latitude.toFixed(2),
this.weatherParameters.longitude.toFixed(2),
bounds.getSouth().toFixed(2),
bounds.getWest().toFixed(2),
bounds.getNorth().toFixed(2),
bounds.getEast().toFixed(2),
].join(':');
this.nearbyMarkers = clearMarkers(this.map, this.nearbyMarkers); if (this.nearbyMarkers.length > 0 && this.nearbyMarkersKey === markerKey) return;
this.nearbyMarkers = await loadNearbyObservationMarkers(this.map, {
latitude: this.weatherParameters.latitude, this.nearbyMarkers = clearMarkers(this.map, this.nearbyMarkers);
longitude: this.weatherParameters.longitude, this.nearbyMarkers = await loadNearbyObservationMarkers(this.map, {
}); latitude: this.weatherParameters.latitude,
this.nearbyMarkers.forEach((marker) => marker.addTo(this.map)); longitude: this.weatherParameters.longitude,
this.nearbyMarkersKey = markerKey; });
this.nearbyMarkers.forEach((marker) => marker.addTo(this.map));
this.nearbyMarkersKey = markerKey;
} finally {
this.refreshingMarkers = false;
}
} }
async ensureMap() { async ensureMap() {