Skip to content
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

feat(geo): Print with resolution PDF and image #1264

Merged
merged 30 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c90d559
feat(geo): Added rotate option and north direction to the map when pr…
aziz-access May 16, 2023
1346b9a
solve lint and optimize map updateControls function
aziz-access May 16, 2023
083eeaa
integrate custom controle rotation-button component in the map
aziz-access May 17, 2023
6233434
adjust image in all template
aziz-access May 17, 2023
7d6c6aa
solve scale and rotate arrow color and position in pdf export
aziz-access May 18, 2023
bb4bc80
code improvement and write documentations
aziz-access May 19, 2023
c134874
sove lint
aziz-access May 19, 2023
9d8084a
Merge branch 'next' of github.com:infra-geo-ouverte/igo2-lib into pri…
aziz-access May 19, 2023
03be970
Merge branch 'next' of github.com:infra-geo-ouverte/igo2-lib into pri…
aziz-access May 19, 2023
193dc6e
feat(geo): add resolution options for print module
aziz-access May 24, 2023
b3367f4
add resolution to image export
aziz-access May 24, 2023
05d2c78
solve lint
aziz-access May 24, 2023
7af119d
code improvement
aziz-access May 24, 2023
32f8df9
code improvement eliminate repeated code
aziz-access May 29, 2023
2abec17
solve lint
aziz-access May 29, 2023
9ded749
code refactoring
aziz-access May 31, 2023
7741950
Merge branch 'next' of github.com:infra-geo-ouverte/igo2-lib into pri…
aziz-access May 31, 2023
279a35b
solve lint
aziz-access May 31, 2023
afdb476
delete mapOverlayHTML from dom
aziz-access May 31, 2023
973d2aa
solve comments
aziz-access Jun 1, 2023
93c94b3
add type to map canvas
aziz-access Jun 1, 2023
aa1f48f
delete console log
aziz-access Jun 1, 2023
b9f08e5
fix conflicts
aziz-access Jun 2, 2023
3839349
merge branches and adjust code
aziz-access Jun 2, 2023
4d0f0f2
delete scaleLine from print demo component
aziz-access Jun 2, 2023
aceb728
solve 1
aziz-access Jun 6, 2023
e2892ad
solve conflicts
aziz-access Jun 6, 2023
0c1b906
Merge branch 'next' of github.com:infra-geo-ouverte/igo2-lib into pri…
aziz-access Jun 27, 2023
4e2809b
code improvement add resetOriginalMapSize, setMapImageResolution and …
aziz-access Jun 27, 2023
2b69d7f
add access modifiers to function
aziz-access Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</mat-form-field>
</div>

<div class="igo-input-container" style="display: none;">
<div class="igo-input-container">
<mat-form-field>
<mat-select
formControlName="resolution"
Expand Down
4 changes: 1 addition & 3 deletions packages/geo/src/lib/print/print/print.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ export class PrintComponent {

this.printService.defineNbFileToProcess(nbFileToProcess);

const resolution = +data.resolution;

this.printService
.downloadMapImage(
this.map,
resolution,
data.resolution,
data.imageFormat,
data.showProjection,
data.showScale,
Expand Down
83 changes: 63 additions & 20 deletions packages/geo/src/lib/print/shared/print.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getLayersLegends } from '../../layer/utils/outputLegend';

import { PrintOptions, TextPdfSizeAndMargin } from './print.interface';
import GeoPdfPlugin from './geopdf';
import { PrintLegendPosition, PrintPaperFormat } from './print.type';
import { PrintLegendPosition, PrintPaperFormat, PrintResolution } from './print.type';

declare global {
interface Navigator {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class PrintService {
const margins = [10, 10, 10, 10];
const width = dimensions[0] - margins[3] - margins[1];
const height = dimensions[1] - margins[0] - margins[2];
const size = [width, height];
const size: [number, number] = [width, height];
let titleSizes: TextPdfSizeAndMargin;
let subtitleSizes: TextPdfSizeAndMargin;

Expand Down Expand Up @@ -610,30 +610,25 @@ export class PrintService {
doc: jsPDF,
map: IgoMap,
resolution: number,
size: Array<number>,
docSize: [number, number],
margins: Array<number>,
legendPostion: PrintLegendPosition
) {

const mapSize = map.ol.getSize();
const mapSize = map.ol.getSize() as [number, number];
const viewResolution = map.ol.getView().getResolution();
const extent = map.ol.getView().calculateExtent(mapSize);
const widthPixels = Math.round((size[0] * resolution) / 25.4);
const heightPixels = Math.round((size[1] * resolution) / 25.4);
const dimensionPixels = this.setMapResolution(map, docSize, resolution, viewResolution);
const status$ = new Subject();

let timeout;
map.ol.once('rendercomplete', async (event: any) => {
const mapCanvas = event.target.getViewport().getElementsByTagName('canvas') as HTMLCollectionOf<HTMLCanvasElement>;
const mapResultCanvas = await this.drawMap(
[widthPixels, heightPixels],
dimensionPixels,
mapCanvas
);

// Reset original map size
map.ol.setSize(mapSize);
map.ol.getView().setResolution(viewResolution);
this.renderMap(map, mapSize, extent);
this.resetOriginalMapSize(map, mapSize, viewResolution);

await this.drawMapControls(map, mapResultCanvas, legendPostion);

Expand Down Expand Up @@ -669,20 +664,43 @@ export class PrintService {
status = SubjectStatus.Error;
this.messageService.error('igo.geo.printForm.corsErrorMessageBody', 'igo.geo.printForm.corsErrorMessageHeader');
}
// Reset original map size
map.ol.setSize(mapSize);
map.ol.getView().setResolution(viewResolution);
this.renderMap(map, mapSize, extent);
this.resetOriginalMapSize(map, mapSize, viewResolution);
status$.next(status);
},200);
});

return status$;
}

private setMapResolution(
map: IgoMap,
initialSize: [number, number],
resolution: number,
viewResolution: number
): [number, number] {

const mapSize = map.ol.getSize();
const widthPixels = Math.round((initialSize[0] * resolution) / 25.4);
const heightPixels = Math.round((initialSize[1] * resolution) / 25.4);

// Set print size
const printSize = [widthPixels, heightPixels];
map.ol.setSize(printSize);
const scaling = Math.min(widthPixels / mapSize[0], heightPixels / mapSize[1]);
map.ol.getView().setResolution(viewResolution / scaling);
return status$;

return [widthPixels, heightPixels];
}

private resetOriginalMapSize(
map: IgoMap,
initialSize: [number, number],
viewResolution: number
) {
map.ol.setSize(initialSize);
map.ol.getView().setResolution(viewResolution);
map.ol.updateSize();
map.ol.renderSync();
}

private async drawMap(
Expand Down Expand Up @@ -832,7 +850,7 @@ export class PrintService {
*/
downloadMapImage(
map: IgoMap,
resolution: number,
printResolution: PrintResolution,
format = 'png',
projection = false,
scale = false,
Expand All @@ -843,15 +861,20 @@ export class PrintService {
legendPosition: PrintLegendPosition
) {
const status$ = new Subject();
// const resolution = map.ol.getView().getResolution();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dans les paramètres de la méthode, on pourrait ajouter le type pour la résolution: PrintResolution

this.activityId = this.activityService.register();
const translate = this.languageService.translate;
format = format.toLowerCase();
const resolution = +printResolution;
const initialMapSize = map.ol.getSize() as [number, number];
const viewResolution = map.ol.getView().getResolution();

map.ol.once('rendercomplete', async (event: any) => {
const size = map.ol.getSize();
const mapCanvas = event.target.getViewport().getElementsByTagName('canvas') as HTMLCollectionOf<HTMLCanvasElement>;
const mapResultCanvas = await this.drawMap(size, mapCanvas);

this.resetOriginalMapSize(map, initialMapSize, viewResolution);

await this.drawMapControls(map, mapResultCanvas, legendPosition);
// Check the legendPosition
if (legendPosition !== 'none') {
Expand Down Expand Up @@ -1032,10 +1055,30 @@ export class PrintService {
}
}
});
map.ol.renderSync();

this.setMapImageResolution(map, initialMapSize, resolution, viewResolution);

return status$;
}

private setMapImageResolution(
map: IgoMap,
initialMapSize: [number, number],
resolution: number,
viewResolution: number
): void {
const scaleFactor = resolution / 96;
const newMapSize = [
Math.round(initialMapSize[0] * scaleFactor), // width
Math.round(initialMapSize[1] * scaleFactor) // height
];
map.ol.setSize(newMapSize);
const scaling = Math.min(newMapSize[0] / initialMapSize[0], newMapSize[1] / initialMapSize[1]);
const view = map.ol.getView();
view.setResolution(viewResolution / scaling);
map.ol.renderSync();
}

/**
* Create and Add Legend to the map canvas
* @param canvas Canvas of the map
Expand Down