Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9ef0c1

Browse files
committed
got image export to work:
- pass staticPlot config opt to mapbox constructor - set preserveDrawingBuffer on export - add mapbox.toImage method - make sure that Plotly.plot promise is return after all layer are rendered. - add first image mock
1 parent 2748740 commit a9ef0c1

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

src/plots/mapbox/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ exports.plot = function plotMapbox(gd) {
6363
gd: gd,
6464
container: fullLayout._glcontainer.node(),
6565
id: id,
66-
fullLayout: fullLayout
66+
fullLayout: fullLayout,
67+
staticPlot: gd._context.staticPlot
6768
});
6869

6970
fullLayout[id]._mapbox = mapbox;

src/plots/mapbox/mapbox.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function Mapbox(opts) {
1919
this.id = opts.id;
2020
this.gd = opts.gd;
2121
this.container = opts.container;
22+
this.isStatic = opts.staticPlot;
2223

2324
var fullLayout = opts.fullLayout;
2425

@@ -78,16 +79,21 @@ proto.createMap = function(fullData, fullLayout, resolve) {
7879
container: self.div,
7980
style: convertStyleUrl(opts.style),
8081
center: convertCenter(opts.center),
81-
zoom: opts.zoom
82+
zoom: opts.zoom,
83+
preserveDrawingBuffer: self.isStatic
8284
});
8385

8486
map.once('load', function() {
8587
console.log('map on load')
8688
self.updateData(fullData);
8789
self.updateLayout(fullLayout);
88-
resolve();
89-
});
9090

91+
map.on('render', function() {
92+
if(map.loaded()) {
93+
map.off('render', this);
94+
resolve();
95+
}
96+
});
9197
map.on('mousemove', function(eventData) {
9298
// hover code goes here !!!
9399
});
@@ -219,6 +225,10 @@ proto.destroy = function() {
219225
this.container.removeChild(this.hoverLayer);
220226
};
221227

228+
proto.toImage = function(format) {
229+
return this.map.getCanvas().toDataURL();
230+
};
231+
222232
proto.getStyle = function() {
223233
var name = this.map.getStyle().name;
224234

test/image/baselines/mapbox.png

84.6 KB
Loading

test/image/mocks/mapbox.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scattermapbox",
5+
"mode": "markers+lines",
6+
"lon": [
7+
10,
8+
20,
9+
30
10+
],
11+
"lat": [
12+
10,
13+
20,
14+
30
15+
],
16+
"marker": {
17+
"size": 20
18+
},
19+
"uid": "d4580a"
20+
},
21+
{
22+
"type": "scattermapbox",
23+
"mode": "markers+lines",
24+
"lon": [
25+
-75,
26+
-120,
27+
170
28+
],
29+
"lat": [
30+
45,
31+
20,
32+
-40
33+
],
34+
"marker": {
35+
"size": 20
36+
},
37+
"uid": "f5a4c5"
38+
}
39+
],
40+
"layout": {
41+
"mapbox": {
42+
"style": "dark",
43+
"center": {
44+
"lon": -4.71092760419225,
45+
"lat": 19.475789009298566
46+
},
47+
"zoom": 1.2345714569517612
48+
},
49+
"height": 450,
50+
"width": 1100,
51+
"autosize": true
52+
}
53+
}

0 commit comments

Comments
 (0)