-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #189 Print options fix #238
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ import { | |
MatInputModule, | ||
MatFormFieldModule, | ||
MatRadioModule, | ||
MatCheckboxModule | ||
MatCheckboxModule, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the MatCheckboxModule and MatRadioModule modules are no longer useful |
||
MatSlideToggleModule | ||
} from '@angular/material'; | ||
|
||
import { IgoLanguageModule } from '@igo2/core'; | ||
|
@@ -33,6 +34,7 @@ import { PrintService } from './shared/print.service'; | |
MatFormFieldModule, | ||
MatRadioModule, | ||
MatCheckboxModule, | ||
MatSlideToggleModule, | ||
IgoLanguageModule, | ||
IgoKeyValueModule | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ export class PrintService { | |
(status: SubjectStatus) => { | ||
if (status === SubjectStatus.Done) { | ||
if (options.showLegend === true) { | ||
this.addLegend(doc, map); | ||
this.addLegend(doc, map, margins); | ||
} else { | ||
this.saveDoc(doc); | ||
} | ||
|
@@ -236,8 +236,10 @@ export class PrintService { | |
/** | ||
Add the legend to the document | ||
@param doc - Pdf document where legend will be added | ||
@param map - Map of the app | ||
@param margins - Page margins | ||
*/ | ||
private addLegend(doc: jsPDF, map: IgoMap) { | ||
private addLegend(doc: jsPDF, map: IgoMap, margins) { | ||
mbarbeau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const that = this; | ||
// Get html code for the legend | ||
const width = doc.internal.pageSize.width; | ||
|
@@ -256,7 +258,7 @@ export class PrintService { | |
|
||
imgData = canvas.toDataURL('image/png'); | ||
doc.addPage(); | ||
const imageSize = this.getImageSizeToFitPdf(doc, canvas); | ||
const imageSize = this.getImageSizeToFitPdf(doc, canvas, margins); | ||
doc.addImage(imgData, 'PNG', 10, position, imageSize[0], imageSize[1]); | ||
that.saveDoc(doc); | ||
div.parentNode.removeChild(div); // remove temp div (IE style) | ||
|
@@ -280,7 +282,7 @@ export class PrintService { | |
|
||
|
||
if (image !== undefined) { | ||
const imageSize = this.getImageSizeToFitPdf(doc, canvas); | ||
const imageSize = this.getImageSizeToFitPdf(doc, canvas, margins); | ||
doc.addImage(image, 'JPEG', margins[3], margins[0], imageSize[0], imageSize[1]); | ||
doc.rect(margins[3], margins[0], imageSize[0], imageSize[1]); | ||
} | ||
|
@@ -340,6 +342,8 @@ export class PrintService { | |
try { | ||
this.addCanvas(doc, canvas, size, margins); | ||
} catch (err) { | ||
alert('2' + err.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intended or you forgot to remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot, just removed it |
||
console.log(err); | ||
status = SubjectStatus.Error; | ||
this.messageService.error( | ||
this.languageService.translate.instant('igo.geo.printForm.corsErrorMessageBody'), | ||
|
@@ -558,11 +562,12 @@ export class PrintService { | |
Calculate the best Image size to fit in pdf | ||
@param doc - Pdf Document | ||
@param canvas - Canvas of image | ||
@param margins - Page margins | ||
*/ | ||
private getImageSizeToFitPdf(doc, canvas) { | ||
private getImageSizeToFitPdf(doc, canvas, margins) { | ||
// Define variable to calculate best size to fit in one page | ||
const pageHeight = doc.internal.pageSize.getHeight() - 20; // -20 to let margin work great | ||
const pageWidth = doc.internal.pageSize.getWidth() - 20; // -20 to let margin work great | ||
const pageHeight = doc.internal.pageSize.getHeight() - (margins[0] + margins[2]); | ||
const pageWidth = doc.internal.pageSize.getWidth() - (margins[1] + margins[3]); | ||
const canHeight = canvas.height; | ||
const canWidth = canvas.width; | ||
const heightRatio = canHeight / pageHeight; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to avoid using the 'important' keyword