Skip to content

Commit 1618bba

Browse files
committed
Disabled selection ui on map load.
1 parent dd04774 commit 1618bba

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/components/widgets/LivelihoodZonesMap.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
b-form-select(
99
v-model="selectedRegion"
10+
:disabled="disabled"
1011
:options="options"
1112
)
1213

1314
b-form-select(
1415
v-model="selectedProvince"
16+
:disabled="disabled"
1517
:options="optionsProvince"
1618
)
1719
</template>
@@ -28,6 +30,8 @@ export default {
2830
previousRegion: '',
2931
previousIsland: '',
3032
33+
disabled: false,
34+
3135
options: [
3236
{ value: null, text: 'Please select a region' }
3337
],
@@ -133,6 +137,17 @@ export default {
133137
134138
// this.previousIsland = this.selectedIsland
135139
this.previousRegion = this.selectedIsland
140+
141+
// Disable the UI
142+
this.disabled = true
143+
const that = this
144+
const time = setInterval(() => {
145+
if (!window.MBL.isLoading) {
146+
console.log('map loaded!')
147+
that.disabled = false
148+
clearInterval(time)
149+
}
150+
}, 200)
136151
},
137152
138153
selectedProvince () {
@@ -153,7 +168,8 @@ export default {
153168
154169
mounted () {
155170
this.getRegionOptions()
156-
console.log('---INITIALIZING LIVELIHOOD ZONES')
171+
172+
// Initialize the mapbox basemap
157173
window.MBL.initMap({
158174
mapContainer: 'map',
159175
style: 'mapbox://styles/mapbox/streets-v11',
@@ -170,7 +186,6 @@ export default {
170186
return
171187
}
172188
173-
console.log(`--PROCESSING ${str}`)
174189
let string = str
175190
if (string.includes('-')) {
176191
string = Array.from(string.split('-'), (x) => `${x[0].toUpperCase()}${x.substr(1, x.length)}`).join('-')
@@ -214,8 +229,6 @@ export default {
214229
this.optionsProvince.push({ value: item, text: provinceValue })
215230
})
216231
}
217-
218-
console.log(this.optionsProvince)
219232
}
220233
}
221234
}

static/map.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ function MapboxMap (publicAccessToken) {
1515

1616
// Set the mapbox public access token
1717
this.accessToken = mapboxgl.accessToken = publicAccessToken
18+
19+
// Flag if a vector data source is loading
20+
// TO-DO: Listen for mapbox events
21+
this.isLoading = false
1822
}
1923

2024
/**
@@ -81,6 +85,9 @@ MapboxMap.prototype.toggleLayer = function (layerName) {
8185
}
8286
}
8387

88+
/**
89+
* Livelihood zones map fill styles
90+
*/
8491
MapboxMap.prototype.getLegendColorCodes = function () {
8592
const styles = {
8693
'1 Aquaculture/Freshwater fisheries': '#08306b',
@@ -195,12 +202,16 @@ MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUr
195202
})
196203

197204
console.log(layer)
205+
this.isLoading = true
198206
this.map.addLayer(layer)
199207

200208
// Enable click events (display a pop-up message) after the layer and source has loaded
209+
const that = this
201210
const time = setInterval(function() {
202211
const features = that.map.queryRenderedFeatures({layers: [layerID] })
203212
if (features) {
213+
that.isLoading = false
214+
204215
window.MBL.map.on('click', layerID, function(e) {
205216
console.log(e)
206217
// print all data
@@ -219,11 +230,11 @@ MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUr
219230
clearInterval(time)
220231
}
221232
}, 200)
222-
233+
/*
223234
this.map.on('load', function(e) {
224235
console.log('---DONE!!!')
225-
226236
})
237+
*/
227238
} else {
228239
// Display the layer if its source already exists
229240
this.toggleLayer(layerID)

0 commit comments

Comments
 (0)