Skip to content

Commit

Permalink
fix(geo): Print set the same horizontal margin for the map
Browse files Browse the repository at this point in the history
code review

code improvment

feat(geo): print get attribution and get Proj Scale

change variable name

fix(geo): print - map position, comment and projection position and georeference

code review

feat(geo): hide attrebition from map image

change variable names

add comments and change variable name

calcule position and size

feat(geo): print show image with attribut

merge and update solve comments

feat(geo): print - add map attribution under the map

feat(geo): add attribution in direction service

change function name

code improvement
  • Loading branch information
aziz-access committed Apr 25, 2024
1 parent 2de5c63 commit 6312942
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 161 deletions.
47 changes: 36 additions & 11 deletions packages/geo/src/lib/directions/shared/directions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ export class DirectionsService {
format: 'Letter',
unit: 'mm' // default
});
const dimensions = [
doc.internal.pageSize.width,
doc.internal.pageSize.height
];
const margins = [10, 10, 10, 10];
const width = dimensions[0];
const height = dimensions[1] - margins[0] - margins[2];
const size: [number, number] = [width, height];

const { width: pageWidth, height: pageHeight } = doc.internal.pageSize;

/** top | right | bottom | left */
const margins: [number, number, number, number] = [20, 10, 20, 10];
this.addAttribution(map, doc, margins);
const width = pageWidth - margins[3] - margins[1];
const height = pageHeight - margins[0] - margins[2];
const imageDimensions: [number, number] = [width, height];
const title = `${direction.title} (${formatDistance(
direction.distance
)}, ${formatDuration(direction.duration)})`;
Expand All @@ -91,10 +91,16 @@ export class DirectionsService {
align: 'center'
});

margins[0] += 20;
const resolution = 96; // Default is 96
this.printService
.addMap(doc, map, resolution, size, margins, PrintLegendPosition.none)
.addMap(
doc,
map,
resolution,
imageDimensions,
margins,
PrintLegendPosition.none
)
.subscribe(async (status: SubjectStatus) => {
if (status === SubjectStatus.Done) {
await this.addInstructions(doc, direction, title);
Expand All @@ -109,6 +115,25 @@ export class DirectionsService {
return status$;
}

private addAttribution(
map: IgoMap,
doc: jsPDF,
margins: [number, number, number, number]
) {
const verticalSpacing: number = 5;
const attributionText: string = this.printService.getAttributionText(map);
if (attributionText) {
margins[2] += verticalSpacing;
const xPosition = margins[3];
const marginBottom = margins[2];
// calculate text position Y
const yPosition =
doc.internal.pageSize.height - marginBottom + verticalSpacing;
doc.setFontSize(10);
doc.text(attributionText, xPosition, yPosition);
}
}

private async setHTMLTableContent(
direction: Direction
): Promise<HTMLTableElement> {
Expand Down Expand Up @@ -155,7 +180,7 @@ export class DirectionsService {
for (let index = 0; index < matListItem.length; index++) {
const element = matListItem[index];
const icon = element.getElementsByTagName('mat-icon')[0] as HTMLElement;
const iconName = icon.getAttribute('data-mat-icon-name') as string;
const iconName = icon.innerText;
const found = iconsArray.some((el) => el.name === iconName);
if (!found) {
const iconCanvas = await html2canvas(icon, { scale: 3 });
Expand Down
Loading

0 comments on commit 6312942

Please sign in to comment.