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

Skip to content

Commit 41ad02c

Browse files
committed
[fixup after rebase] add mapbox toSVG method
1 parent 2ba0f16 commit 41ad02c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/plots/mapbox/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var mapboxgl = require('mapbox-gl');
1313

1414
var Plots = require('../plots');
1515
var createMapbox = require('./mapbox');
16+
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
17+
1618
var CREDS = require('../../../../creds.json');
1719

1820

@@ -85,3 +87,30 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
8587
}
8688
}
8789
};
90+
91+
exports.toSVG = function(gd) {
92+
var fullLayout = gd._fullLayout,
93+
subplotIds = Plots.getSubplotIds(fullLayout, 'mapbox'),
94+
size = fullLayout._size;
95+
96+
for(var i = 0; i < subplotIds.length; i++) {
97+
var opts = fullLayout[subplotIds[i]],
98+
domain = opts.domain,
99+
mapbox = opts._mapbox;
100+
101+
var imageData = mapbox.toImage('png');
102+
var image = fullLayout._glimages.append('svg:image');
103+
104+
image.attr({
105+
xmlns: xmlnsNamespaces.svg,
106+
'xlink:href': imageData,
107+
x: size.l + size.w * domain.x[0],
108+
y: size.t + size.h * (1 - domain.y[1]),
109+
width: size.w * (domain.x[1] - domain.x[0]),
110+
height: size.h * (domain.y[1] - domain.y[0]),
111+
preserveAspectRatio: 'none'
112+
});
113+
114+
mapbox.destroy();
115+
}
116+
};

0 commit comments

Comments
 (0)