Skip to content

Commit

Permalink
fix(geo): delete map legend after the printing from the DOM (#1304)
Browse files Browse the repository at this point in the history
* package lock changes

* fix(geo): delete map legend after the printing from the DOM

* test git

* solve lint

* solve typo and set method Access to private
  • Loading branch information
aziz-access authored Sep 11, 2023
1 parent 860ea7e commit d84a9e6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/geo/src/lib/print/shared/print.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class PrintService {
const div = window.document.createElement('div');
div.style.position = 'absolute';
div.style.top = '0';

div.style.zIndex = '-1';
// Add html code to convert in the new window
window.document.body.appendChild(div);
div.innerHTML = html;
Expand All @@ -325,7 +325,7 @@ export class PrintService {
const canvas = await html2canvas(div, { useCORS: true }).catch((e) => {
console.log(e);
});

this.removeHtmlElement(div);
if (canvas) {
let status = SubjectStatus.Done;
try {
Expand All @@ -345,6 +345,10 @@ export class PrintService {
return status$;
}

private removeHtmlElement(element: HTMLElement) {
element.parentNode.removeChild(element);
}


getTextPdfObjectSizeAndMarg(text: string, margins, font:string, fontSizeInPt: number, fontStyle:string, doc: jsPDF)
: TextPdfSizeAndMargin {
Expand Down Expand Up @@ -481,6 +485,7 @@ export class PrintService {
const div = window.document.createElement('div');
div.style.position = 'absolute';
div.style.top = '0';
div.style.zIndex = '-1';

// Add html code to convert in the new window
window.document.body.appendChild(div);
Expand All @@ -490,7 +495,7 @@ export class PrintService {
const canvas = await html2canvas(div, { useCORS: true }).catch((e) => {
console.log(e);
});

this.removeHtmlElement(div);
if (canvas) {
const pourcentageReduction = 0.85;
const imageSize = [pourcentageReduction * (25.4 * canvas.width) / resolution, pourcentageReduction
Expand Down Expand Up @@ -534,13 +539,15 @@ export class PrintService {
const div = window.document.createElement('div');
div.style.position = 'absolute';
div.style.top = '0';
div.style.zIndex = '-1';
// Add html code to convert in the new window
window.document.body.appendChild(div);
div.innerHTML = html;
await this.timeout(1);
const canvas = await html2canvas(div, { useCORS: true }).catch((e) => {
console.log(e);
});
this.removeHtmlElement(div);
let marginsLegend;
if (canvas) {
const pourcentageReduction = 0.85;
Expand Down Expand Up @@ -1112,6 +1119,7 @@ export class PrintService {
const div = window.document.createElement('div');
div.style.position = 'absolute';
div.style.top = '0';
div.style.zIndex = '-1';
// Add html code to convert in the new window
window.document.body.appendChild(div);
div.innerHTML = html;
Expand Down Expand Up @@ -1146,7 +1154,7 @@ export class PrintService {

context.drawImage(canvasLegend, legendX, legendY, legendWidth, legendHeight);
context.strokeRect(legendX, legendY, legendWidth, legendHeight);
div.parentNode.removeChild(div); // remove temp div (IE style)
this.removeHtmlElement(div);
return true;
}
}
Expand Down

0 comments on commit d84a9e6

Please sign in to comment.