Skip to content

Commit

Permalink
[#1168][#1165][#1159] Fit quick image to result window, increase allo…
Browse files Browse the repository at this point in the history
…wed map zoom lvl, add colors to report legend (#1186)

Closes: #1168,#1165,#1159
  • Loading branch information
danielkryska authored Apr 28, 2021
1 parent 02fd31b commit 5d16b06
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 33 deletions.
1 change: 1 addition & 0 deletions s4e-web/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 14.15.5
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
'background': result.image ? 'url(' + result.image + ')' : '',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'background-size': 'cover'
'background-size': 'contain'
}"
(click)="showDetails.emit(result)"
>
Expand Down
91 changes: 60 additions & 31 deletions s4e-web/src/app/views/map-view/zk/report-modal/report-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*
*/

import Canvg from 'canvg';
import {jsPDF} from 'jspdf';
import {forkJoin, fromEvent, Observable, of, ReplaySubject} from 'rxjs';
import {delay, filter, switchMap, take, tap} from 'rxjs/operators';
Expand Down Expand Up @@ -276,28 +274,57 @@ class LegendComposer {
}
}

insertLegend(legend: Legend, svgData: string) {
async insertLegend(legend: Legend, svg: string) {
const height = 50;
const width = 3;
const margin = 5;
const fontSize = 4;
const fontSize = 6;
const yStart = this.currentY + margin;

this.doc.addSvgAsImage(svgData, this.xStart, yStart, width, height);
this.doc.setFont(this.FONT_NAME, 'normal');
this.doc.setFontSize(fontSize);

Object.entries(legend.leftDescription).forEach(([position, value]) => {
const positionN = Number(position);
this.doc.text(
value,
this.xStart + width + 1,
yStart + height - height * positionN,
{maxWidth: this.width, align: 'left', baseline: 'top'}
);
await this._svgToImgBase64$(svg, width, height).then(imgBase64 => {
this.doc.addImage(imgBase64, this.xStart, yStart, width, height);
this.doc.setFont(this.FONT_NAME, 'normal');
this.doc.setFontSize(fontSize);

Object.entries(legend.leftDescription).forEach(([position, value]) => {
const positionN = Number(position);
this.doc.text(
value,
this.xStart + width + 1,
yStart + height - height * positionN,
{maxWidth: this.width, align: 'left', baseline: 'top'}
);
});

this.advanceY(height + margin);
});
}

this.advanceY(height + margin);
private _svgToImgBase64$(
svg: string,
width: number,
height: number
): Promise<string> {
return new Promise((resolve, reject) => {
let container = document.createElement('div');
container.style.display = 'none';
container.innerHTML = svg;

let canvas = document.createElement('canvas');
let context = canvas.getContext('2d');

const image = new Image();
image.onload = () => {
canvas.width = (image.width / image.height) * height;
canvas.height = (image.height / image.width) * width;
context.drawImage(image, 0, 0, canvas.width, canvas.height);
resolve(canvas.toDataURL('image/png', 0.92));
};

image.src =
'data:image/svg+xml;base64,' +
btoa(new XMLSerializer().serializeToString(container.firstElementChild));
});
}
}

Expand Down Expand Up @@ -336,18 +363,19 @@ export class ReportGenerator {
filter(w => !w),
tap(() => this.working$.next(true)),
delay(0),
tap(() =>
this.combineDocument(
imageData,
imageWidth,
imageHeight,
caption,
notes,
productName,
sceneDate,
pointResolution,
legend
)
tap(
async () =>
await this.combineDocument(
imageData,
imageWidth,
imageHeight,
caption,
notes,
productName,
sceneDate,
pointResolution,
legend
)
),
delay(0),
tap(() => this.working$.next(false))
Expand Down Expand Up @@ -418,7 +446,7 @@ export class ReportGenerator {
* @return height of the added text box
*/

private combineDocument(
private async combineDocument(
imageData: string,
imageWidth: number,
imageHeight: number,
Expand Down Expand Up @@ -498,7 +526,8 @@ export class ReportGenerator {
composer.insertScale(pxPerMM * pointResolution);

if (legend) {
composer.insertLegend(legend, this.svg.legend);
console.log(this.svg);
await composer.insertLegend(legend, this.svg.legend);
}

composer.insertTextBox('Szczegóły', {
Expand Down
2 changes: 1 addition & 1 deletion s4e-web/src/environments/environment.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const commonEnvironmentVariables = {
generalErrorKey: '__general__',
apiPrefixV1: 'api/v1',
projection: {toProjection: 'EPSG:3857', coordinates: [19, 52] as [number, number]},
maxZoom: 12,
maxZoom: 19,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,

/*
Expand Down

0 comments on commit 5d16b06

Please sign in to comment.