Skip to content

Commit d12de0a

Browse files
committed
add quality in map.toDataURL, fix #1244
1 parent 368d9e7 commit d12de0a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/map/Map.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,8 @@ class Map extends Handlerable(Eventable(Renderable(Class))) {
12101210
/**
12111211
* Exports image from the map's canvas.
12121212
* @param {Object} [options=undefined] - options
1213-
* @param {String} [options.mimeType=image/png] - mime type of the image
1213+
* @param {String} [options.mimeType=image/png] - mime type of the image: image/png, image/jpeg, image/webp
1214+
* @param {String} [options.quality=0.92] - A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp.
12141215
* @param {Boolean} [options.save=false] - whether pop a file save dialog to save the export image.
12151216
* @param {String} [options.fileName=export] - specify the file name, if options.save is true.
12161217
* @return {String} image of base64 format.
@@ -1230,11 +1231,11 @@ class Map extends Handlerable(Eventable(Renderable(Class))) {
12301231
if (!file) {
12311232
file = 'export';
12321233
}
1233-
const dataURL = renderer.toDataURL(mimeType);
1234+
const dataURL = renderer.toDataURL(mimeType, options.quality || 0.92);
12341235
if (save && dataURL) {
12351236
let imgURL;
12361237
if (typeof Blob !== 'undefined' && typeof atob !== 'undefined') {
1237-
const blob = b64toBlob(dataURL.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''), mimeType);
1238+
const blob = b64toBlob(dataURL.replace(/^data:image\/(png|jpeg|jpg|webp);base64,/, ''), mimeType);
12381239
imgURL = URL.createObjectURL(blob);
12391240
} else {
12401241
imgURL = dataURL;

src/renderer/map/MapCanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ class MapCanvasRenderer extends MapRenderer {
409409
return null;
410410
}
411411

412-
toDataURL(mimeType) {
412+
toDataURL(mimeType, quality) {
413413
if (!this.canvas) {
414414
return null;
415415
}
416-
return this.canvas.toDataURL(mimeType);
416+
return this.canvas.toDataURL(mimeType, quality);
417417
}
418418

419419
remove() {

0 commit comments

Comments
 (0)