Skip to content

Commit bff2ddf

Browse files
committed
Fix all Tilesets loading detection error.
1 parent 64425b7 commit bff2ddf

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/components/widgets/LivelihoodZonesMap.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export default {
7676
messages: {
7777
DEFAULT: '',
7878
LOADING: 'Please wait while loading...',
79-
NAVIGATE_TO: 'Please navigate to the selected region to view legends.'
79+
NAVIGATE_TO: 'Please navigate to the selected region to view legends.',
80+
LOAD_ERROR: 'An error has occurred while fetching data. Please check your internet connection and reload the web page.'
8081
},
8182
8283
filters: {
@@ -187,14 +188,16 @@ export default {
187188
// Enable UI after basemap and (all) Tilesets have finished loading
188189
window.MBL.map.on(window.MBL.events.DATA_LOADED, function (e) {
189190
console.log('---ALL DATA HAS LOADED')
190-
that.statusMessage = that.messages.DEFAULT
191-
that.disabled = false
191+
if (that.statusMessage === that.messages.LOADING) {
192+
that.statusMessage = that.messages.DEFAULT
193+
that.disabled = false
194+
}
192195
})
193196
194197
// Display an error message if initial Tilesets pre-load has failed
195198
window.MBL.map.on(window.MBL.events.DATA_LOAD_FAILURE, function (e) {
196199
console.log('---DATA FAILED TO DOWNLOAD')
197-
that.statusMessage = 'Map data has failed to download.\nPlease check your internet connection and reload the web page.'
200+
that.statusMessage = that.messages.LOAD_ERROR
198201
})
199202
},
200203

static/map.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ MapboxMap.prototype.initMap = function ({ mapContainer = 'map', style, zoom, cen
130130
if (e.sourceId !== 'composite') {
131131
if (!that.eventsInitialized) {
132132
that.eventsInitialized = true
133+
let hasLoadError = false
134+
133135
const attributeNames = { // Attribute name mapping
134136
'ADM2_EN': 'Province',
135137
'ADM3_EN': 'Municipality',
@@ -143,6 +145,7 @@ MapboxMap.prototype.initMap = function ({ mapContainer = 'map', style, zoom, cen
143145

144146
if (features.length === 0) {
145147
console.log(`---failed to fetch ${that.layerNames[i]}`)
148+
hasLoadError = true
146149
this.fire(that.events.DATA_LOAD_FAILURE)
147150
break
148151
}
@@ -169,10 +172,12 @@ MapboxMap.prototype.initMap = function ({ mapContainer = 'map', style, zoom, cen
169172
}
170173
}
171174

172-
console.log(`---${that.events.DATA_LOADED}`)
173-
that.isLoading = false
174-
that.toggleHandlers(true)
175-
this.fire(that.events.DATA_LOADED)
175+
if (!hasLoadError) {
176+
console.log(`---${that.events.DATA_LOADED}`)
177+
that.isLoading = false
178+
that.toggleHandlers(true)
179+
this.fire(that.events.DATA_LOADED)
180+
}
176181
}
177182
}
178183
}

0 commit comments

Comments
 (0)