Allow including extra html elements in a screenshot.
MODIFY
src/map.js
src/map.js
@@ -1727,6 +1727,9 @@ var map = function (arg) {
* @param {boolean|null} [opts.attribution=null] If `null` or unspecified,
* include the attribution only if all layers are used. If false, never
* include the attribution. If `true`, always include it.
+ * @param {HTMLObject[]|string[]} [opts.html] A list of additional HTML
+ * elements, selectors, or jQuery elements to render on top of the map.
+ * These are rendered in order, with the last one topmost.
* @returns {deferred} A jQuery Deferred object. The done function receives
* either a data URL or an `HTMLCanvasElement` with the result.
* @fires geo.event.screenshot.ready
@@ -1838,6 +1841,16 @@ var map = function (arg) {
});
});
}
+ if (opts.html) {
+ $(opts.html).each(function () {
+ var attrElem = $(this);
+ defer = defer.then(function () {
+ return util.htmlToImage(attrElem, 1).done(function (img) {
+ drawLayerImageToContext(context, 1, $([]), img);
+ });
+ });
+ });
+ }
defer = defer.then(function () {
var canvas = result;
if (type !== 'canvas') {

MODIFY
tests/cases/map.js
tests/cases/map.js
@@ -887,6 +887,13 @@ describe('geo.core.map', function () {
done();
});
}, 10000);
+ /* Extra html */
+ it('screenshot with extra html', function (done) {
+ m.screenshot(null, undefined, undefined, {html: ['body']}).then(function (result) {
+ expect(result.substr(0, 22)).toBe('data:image/png;base64,');
+ done();
+ });
+ });
}
// end of non-PhantomJS tests
if (isPhantomJS()) {

Allow including extra html elements in a screenshot.