Skip to content

Commit b7f4f1f

Browse files
committed
Listen for basemap load.
1 parent 1618bba commit b7f4f1f

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/components/widgets/LivelihoodZonesMap.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default {
3030
previousRegion: '',
3131
previousIsland: '',
3232
33-
disabled: false,
33+
disabled: true,
3434
3535
options: [
3636
{ value: null, text: 'Please select a region' }
@@ -168,6 +168,7 @@ export default {
168168
169169
mounted () {
170170
this.getRegionOptions()
171+
const that = this
171172
172173
// Initialize the mapbox basemap
173174
window.MBL.initMap({
@@ -178,6 +179,16 @@ export default {
178179
})
179180
180181
this.$refs.map.getElementsByClassName('mapboxgl-canvas')[0].style.position = 'relative'
182+
183+
// Wait for basemap to load
184+
// TO-DO: Listen for mapbox events
185+
const time = setInterval(() => {
186+
if (!window.MBL.isLoading) {
187+
console.log('--BASEMAP')
188+
that.disabled = false
189+
clearInterval(time)
190+
}
191+
}, 200)
181192
},
182193
183194
methods: {

static/map.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function MapboxMap (publicAccessToken) {
1818

1919
// Flag if a vector data source is loading
2020
// TO-DO: Listen for mapbox events
21-
this.isLoading = false
21+
this.isLoading = true
2222
}
2323

2424
/**
@@ -61,6 +61,21 @@ MapboxMap.prototype.initMap = function ({ mapContainer = 'map', style, zoom = 5.
6161
this.mapContainer.style.height = (window.outerHeight + 70) + 'px'
6262
this.mapCanvas.style.width = '100%'
6363
this.map.resize()
64+
65+
// Listen for basemap loading events
66+
const that = this
67+
68+
this.map.on('load', function() {
69+
console.log('---basemap loaded')
70+
that.isLoading = false
71+
})
72+
73+
this.map.on('sourcedata', function(e) {
74+
if (e.isSourceLoaded) {
75+
console.log('---vector loaded')
76+
that.isLoading = false
77+
}
78+
})
6479
}
6580

6681
/**
@@ -210,10 +225,9 @@ MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUr
210225
const time = setInterval(function() {
211226
const features = that.map.queryRenderedFeatures({layers: [layerID] })
212227
if (features) {
213-
that.isLoading = false
228+
// that.isLoading = false
214229

215230
window.MBL.map.on('click', layerID, function(e) {
216-
console.log(e)
217231
// print all data
218232
var content = ""
219233
for(key in e.features[0].properties){

0 commit comments

Comments
 (0)