Skip to content

Commit 70fea0d

Browse files
committed
mark map as loaded with css class for puppeteer screenshots
1 parent c4aa5e7 commit 70fea0d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

vue/screenshot-service/screenshot-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ app.get('*', async (req, res) => {
7878
waitLoad: true,
7979
waitNetworkIdle: true
8080
});
81-
await page.waitForSelector('#mapinfo .v-list-item__title');
82-
// await page.waitFor(1000); // extra 1sec wait, for map tiles
81+
await page.waitForSelector('#map.loaded');
82+
await page.waitFor(500); // extra 500ms wait, for map tiles
8383
const screenshotBuffer = await page.screenshot({ encoding: 'binary' });
8484
// await browser.close();
8585
await browserPool.release(page);

vue/src/components/SnapshotMap.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</v-slide-x-reverse-transition>
1212

1313
<v-container fluid class="pa-0" ref="mapbox">
14-
<div id="map"></div>
14+
<div id="map" :class="{ loaded: isMapLoaded}"></div>
1515
</v-container>
1616

1717
<v-btn
@@ -115,7 +115,8 @@ export default {
115115
layers: [],
116116
geobounds: [],
117117
screenshotMode: this.$route.query.hasOwnProperty('screenshot'),
118-
screenshotIsThumbnail: this.$route.query.hasOwnProperty('thumbnail')
118+
screenshotIsThumbnail: this.$route.query.hasOwnProperty('thumbnail'),
119+
isMapLoaded: false
119120
};
120121
},
121122
@@ -205,7 +206,9 @@ export default {
205206
if (this.hash) { // full snapshot with hash
206207
this.layers.forEach((layer) => {
207208
if (layer.mediatype === 'application/vnd.mapbox-vector-tile') {
208-
this.layerContainer.addLayer(L.mapbox.styleLayer(layer.path));
209+
const tileLayer = L.mapbox.styleLayer(layer.path);
210+
tileLayer.on('load', () => { this.isMapLoaded = true; });
211+
this.layerContainer.addLayer(tileLayer);
209212
} else if (layer.mediatype === 'application/geo+json') {
210213
this.layerContainer.addLayer(L.mapbox.featureLayer(layer.data, {
211214
attribution: this.geojson.views[0].spec.attribution
@@ -267,6 +270,7 @@ export default {
267270
this.layers = [];
268271
this.geobounds = [];
269272
this.map = null;
273+
this.isMapLoaded = false;
270274
}
271275
}
272276
};

0 commit comments

Comments
 (0)