From f302b5883e121c323bb11e2ccd2327e042d5aa75 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 13 Feb 2020 18:06:02 +0000 Subject: [PATCH 1/2] Update jspdf version --- examples/export-pdf.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/export-pdf.html b/examples/export-pdf.html index c335d609a1..fa20f86069 100644 --- a/examples/export-pdf.html +++ b/examples/export-pdf.html @@ -6,7 +6,7 @@ docs: > Example of exporting a map as a PDF using the jsPDF library. tags: "export, pdf, openstreetmap" resources: - - https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js + - https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js ---
From 0b893f11d3622bd62089b7047ddd65a84360ee09 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 13 Feb 2020 18:13:07 +0000 Subject: [PATCH 2/2] Fix IE compatibility. Add opacity handling. querySelectorAll().forEach() isn't supported by IE. Add opacity to the vector layer and handle it in the output. --- examples/export-pdf.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/export-pdf.js b/examples/export-pdf.js index 125c95d05d..97dac9b59e 100644 --- a/examples/export-pdf.js +++ b/examples/export-pdf.js @@ -18,7 +18,8 @@ feature.getGeometry().transform('EPSG:4326', 'EPSG:3857'); const vector = new VectorLayer({ source: new VectorSource({ features: [feature] - }) + }), + opacity: 0.5 }); @@ -62,8 +63,10 @@ exportButton.addEventListener('click', function() { mapCanvas.width = width; mapCanvas.height = height; const mapContext = mapCanvas.getContext('2d'); - document.querySelectorAll('.ol-layer canvas').forEach(function(canvas) { + Array.prototype.forEach.call(document.querySelectorAll('.ol-layer canvas'), function(canvas) { if (canvas.width > 0) { + const opacity = canvas.parentNode.style.opacity; + mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity); const transform = canvas.style.transform; // Get the transform parameters from the style's transform matrix const matrix = transform.match(/^matrix\(([^\(]*)\)$/)[1].split(',').map(Number);