ebta-workflow-prod 4.0.7 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/activitypack.json +1 -1
- package/build/main.js +2 -2
- package/package.json +1 -1
- package/src/activities/PDFMapGenerator.ts +353 -274
- package/src/elements/Viewer360.tsx +0 -6
- package/src/index.ts +0 -3
- package/src/elements/Viewer360V2.tsx +0 -116
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
4
4
|
/* eslint-disable prefer-const */
|
|
5
5
|
import type { IActivityHandler } from "@vertigis/workflow";
|
|
6
|
-
import { PDFDocument, degrees, rgb, PDFName, PDFString, TextAlignment, PDFArray, StandardFonts,PDFRef } from 'pdf-lib';
|
|
6
|
+
import { PDFDocument, degrees, rgb, PDFName, PDFString, TextAlignment, PDFArray, StandardFonts, PDFRef } from 'pdf-lib';
|
|
7
7
|
import axios from 'axios';
|
|
8
8
|
|
|
9
9
|
|
|
@@ -24,13 +24,11 @@ interface PDFMapGeneratorInputs {
|
|
|
24
24
|
/**
|
|
25
25
|
* @displayName Legend img Base64
|
|
26
26
|
* @description Legend img Base64 created by Legend creator
|
|
27
|
-
* @required
|
|
28
27
|
*/
|
|
29
28
|
LegendImgBase64: string;
|
|
30
29
|
/**
|
|
31
30
|
* @displayName Scale Array
|
|
32
31
|
* @description Array contains the scale numbers catched from each extent
|
|
33
|
-
* @required
|
|
34
32
|
*/
|
|
35
33
|
scaleArray: number[];
|
|
36
34
|
/**
|
|
@@ -90,6 +88,16 @@ interface PDFMapGeneratorInputs {
|
|
|
90
88
|
* @description Array of geocoded addresses
|
|
91
89
|
*/
|
|
92
90
|
addressList: string[];
|
|
91
|
+
/**
|
|
92
|
+
* @displayName specific type name of print template
|
|
93
|
+
* @description specific type name of print template, e.g.'VMP'
|
|
94
|
+
*/
|
|
95
|
+
template: string;
|
|
96
|
+
/**
|
|
97
|
+
* @displayName Object to provide extra field detail, by key-value(string)
|
|
98
|
+
* @description Object to provide extra field detail, by key-value(string)
|
|
99
|
+
*/
|
|
100
|
+
extraField: object;
|
|
93
101
|
}
|
|
94
102
|
/** An interface that defines the outputs of the activity. */
|
|
95
103
|
interface PDFMapGeneratorOutputs {
|
|
@@ -109,7 +117,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
109
117
|
console.log('EBTA PDFMapGenerator version 1.1')
|
|
110
118
|
if (typeof fetch !== 'undefined') {
|
|
111
119
|
const response = await fetch(url, {
|
|
112
|
-
mode:
|
|
120
|
+
mode: 'cors',
|
|
113
121
|
credentials: 'omit'
|
|
114
122
|
});
|
|
115
123
|
if (!response.ok) {
|
|
@@ -129,42 +137,42 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
129
137
|
}
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
|
|
140
|
+
private async reencodeImageToArrayBuffer(arrayBuffer: ArrayBuffer): Promise<ArrayBuffer> {
|
|
133
141
|
const blob = new Blob([arrayBuffer], { type: 'image/jpeg' });
|
|
134
142
|
const img = new Image();
|
|
135
|
-
|
|
143
|
+
|
|
136
144
|
// Convert the array buffer to a blob URL
|
|
137
145
|
img.src = URL.createObjectURL(blob);
|
|
138
|
-
|
|
146
|
+
|
|
139
147
|
return new Promise<ArrayBuffer>((resolve, reject) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
img.onload = () => {
|
|
149
|
+
const canvas = document.createElement('canvas');
|
|
150
|
+
canvas.width = img.width;
|
|
151
|
+
canvas.height = img.height;
|
|
152
|
+
|
|
153
|
+
const ctx = canvas.getContext('2d');
|
|
154
|
+
if (!ctx) return reject(new Error('Canvas context could not be created'));
|
|
155
|
+
|
|
156
|
+
ctx.drawImage(img, 0, 0);
|
|
157
|
+
|
|
158
|
+
canvas.toBlob((blob) => {
|
|
159
|
+
if (!blob) return reject(new Error('Failed to convert canvas to Blob'));
|
|
160
|
+
|
|
161
|
+
const reader = new FileReader();
|
|
162
|
+
reader.onloadend = () => {
|
|
163
|
+
if (reader.result instanceof ArrayBuffer) {
|
|
164
|
+
resolve(reader.result);
|
|
165
|
+
} else {
|
|
166
|
+
reject(new Error('Failed to read Blob as ArrayBuffer'));
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
reader.readAsArrayBuffer(blob);
|
|
170
|
+
}, 'image/jpeg');
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
img.onerror = (err) => reject(new Error('Image load error: '));
|
|
166
174
|
});
|
|
167
|
-
|
|
175
|
+
}
|
|
168
176
|
|
|
169
177
|
|
|
170
178
|
private arrayBufferToBase64(buffer: ArrayBuffer): string {
|
|
@@ -206,7 +214,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
206
214
|
return num;
|
|
207
215
|
}
|
|
208
216
|
|
|
209
|
-
|
|
217
|
+
|
|
210
218
|
|
|
211
219
|
/** Perform the execution logic of the activity. */
|
|
212
220
|
async execute(inputs: PDFMapGeneratorInputs): Promise<PDFMapGeneratorOutputs> {
|
|
@@ -234,17 +242,29 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
234
242
|
const image3url = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/dbyd.png'
|
|
235
243
|
const imageBarurl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/Scalebar.png'
|
|
236
244
|
const imageNorthUrl = 'https://cdn-icons-png.flaticon.com/512/3236/3236586.png'
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
let image10Buffer, image1Buffer, image2Buffer, image3Buffer
|
|
246
|
+
|
|
247
|
+
if (inputs.template == 'VMP') {
|
|
248
|
+
const image10kmurl = 'https://ebta.maps.arcgis.com/sharing/rest/content/items/c15211b9826549f69a13c3f3d32a841b/resources/vmp_symbols/speedlimit10.svg'
|
|
249
|
+
image10Buffer = await this.fetchData(image10kmurl);
|
|
250
|
+
console.log('Image10 fetched successfully');
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
image1Buffer = await this.fetchData(image1url);
|
|
254
|
+
console.log('Image1 fetched successfully');
|
|
255
|
+
image2Buffer = await this.fetchData(image2url);
|
|
256
|
+
console.log('Image2 fetched successfully');
|
|
257
|
+
image3Buffer = await this.fetchData(image3url);
|
|
258
|
+
console.log('Image3 fetched successfully');
|
|
259
|
+
}
|
|
243
260
|
const imageBarBuffer = await this.fetchData(imageBarurl);
|
|
244
261
|
console.log('Image scale bar fetched successfully');
|
|
245
262
|
const imageNorthBuffer = await this.fetchData(imageNorthUrl);
|
|
246
263
|
console.log('Image North Arrow fetched successfully');
|
|
247
|
-
|
|
264
|
+
let legendBuffer
|
|
265
|
+
if (inputs.LegendImgBase64) {
|
|
266
|
+
legendBuffer = this.base64ToArrayBuffer(inputs.LegendImgBase64);
|
|
267
|
+
}
|
|
248
268
|
const filledPDFs: Uint8Array[] = [];
|
|
249
269
|
for (let i = 0; i < imgBase64Array.length; i++) {
|
|
250
270
|
let doc = await PDFDocument.load(pdfBuffer);
|
|
@@ -259,16 +279,27 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
259
279
|
} else if (imgBase64.startsWith('data:image/jpeg;base64,') || imgBase64.startsWith('data:image/jpg;base64,')) {
|
|
260
280
|
image = await doc.embedJpg(imageBuffer);
|
|
261
281
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
282
|
+
let image1, image2, image3, image10
|
|
283
|
+
if (inputs.template == 'VMP') {
|
|
284
|
+
image10 = await doc.embedPng(image10Buffer);
|
|
285
|
+
console.log('image10 embed successfully')
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
image1 = await doc.embedPng(image1Buffer);
|
|
289
|
+
image2 = await doc.embedPng(image2Buffer);
|
|
290
|
+
image3 = await doc.embedPng(image3Buffer);
|
|
291
|
+
console.log('image1,2,3 embed successfully')
|
|
292
|
+
}
|
|
265
293
|
const imageBar = await doc.embedPng(imageBarBuffer);
|
|
266
294
|
const imageNorth = await doc.embedPng(imageNorthBuffer);
|
|
267
295
|
let legendImage
|
|
268
|
-
if (inputs.LegendImgBase64
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
296
|
+
if (inputs.LegendImgBase64) {
|
|
297
|
+
if (inputs.LegendImgBase64.startsWith('data:image/png;base64,')) {
|
|
298
|
+
legendImage = await doc.embedPng(legendBuffer);
|
|
299
|
+
} else if (inputs.LegendImgBase64.startsWith('data:image/jpeg;base64,') || inputs.LegendImgBase64.startsWith('data:image/jpg;base64,')) {
|
|
300
|
+
legendImage = await doc.embedJpg(legendBuffer);
|
|
301
|
+
}
|
|
302
|
+
console.log('legend image embed successfully')
|
|
272
303
|
}
|
|
273
304
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
274
305
|
newPage.drawImage(image, {
|
|
@@ -277,76 +308,117 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
277
308
|
width: width * 0.8113,
|
|
278
309
|
height: height * 0.8029,
|
|
279
310
|
});
|
|
280
|
-
|
|
281
|
-
if (
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
311
|
+
console.log('map image drawn successfully')
|
|
312
|
+
if (inputs.LegendImgBase64) {
|
|
313
|
+
//Define position & size of legend screeshot, depent on width/height ratio
|
|
314
|
+
if (legendImage.width / legendImage.height > 0.259) {
|
|
315
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
316
|
+
newPage.drawImage(legendImage, {
|
|
317
|
+
x: width * 0.83796,
|
|
318
|
+
y: height * (0.94611) - width * 0.14 * (legendImage.height / legendImage.width),
|
|
319
|
+
width: width * 0.14,
|
|
320
|
+
height: width * 0.14 * (legendImage.height / legendImage.width),
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
if (legendImage.width / legendImage.height < 0.259 / 1.6) {
|
|
325
|
+
if (legendImage.width / legendImage.height < 0.259 / 3.95) {
|
|
326
|
+
if (legendImage.width / legendImage.height < 0.259 / 5.5) {
|
|
327
|
+
console.log("split legend into 3 columns");
|
|
328
|
+
const fullLegendimg = new Image();
|
|
329
|
+
fullLegendimg.src = inputs.LegendImgBase64;
|
|
330
|
+
fullLegendimg.onload = async () => {
|
|
331
|
+
const neckHeight = Math.floor(legendImage.height * 0.33); // Approximate neck position
|
|
332
|
+
const waistHeight = Math.floor(legendImage.height * 0.66); // Approximate waist position
|
|
333
|
+
// Neck to Top
|
|
334
|
+
const neckUpCanvas = document.createElement('canvas');
|
|
335
|
+
neckUpCanvas.width = legendImage.width;
|
|
336
|
+
neckUpCanvas.height = neckHeight;
|
|
337
|
+
const neckUpCtx = neckUpCanvas.getContext('2d');
|
|
338
|
+
neckUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, neckHeight, 0, 0, legendImage.width, neckHeight);
|
|
339
|
+
// Waist to Neck
|
|
340
|
+
const waistUpCanvas = document.createElement('canvas');
|
|
341
|
+
waistUpCanvas.width = legendImage.width;
|
|
342
|
+
waistUpCanvas.height = waistHeight - neckHeight;
|
|
343
|
+
const waistUpCtx = waistUpCanvas.getContext('2d');
|
|
344
|
+
waistUpCtx!.drawImage(fullLegendimg, 0, neckHeight, legendImage.width, waistHeight - neckHeight, 0, 0, legendImage.width, waistHeight - neckHeight);
|
|
345
|
+
// Bottom to Waist
|
|
346
|
+
const waistDownCanvas = document.createElement('canvas');
|
|
347
|
+
waistDownCanvas.width = legendImage.width;
|
|
348
|
+
waistDownCanvas.height = legendImage.height - waistHeight;
|
|
349
|
+
const waistDownCtx = waistDownCanvas.getContext('2d');
|
|
350
|
+
waistDownCtx!.drawImage(fullLegendimg, 0, waistHeight, legendImage.width, legendImage.height - waistHeight, 0, 0, legendImage.width, legendImage.height - waistHeight);
|
|
351
|
+
const neckUpBase64 = neckUpCanvas.toDataURL('image/jpeg');
|
|
352
|
+
const upBuffer1 = this.base64ToArrayBuffer(neckUpBase64);
|
|
353
|
+
const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
|
|
354
|
+
const upBuffer2 = this.base64ToArrayBuffer(waistUpBase64);
|
|
355
|
+
const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
|
|
356
|
+
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
357
|
+
const LegendNeckUp = await doc.embedJpg(upBuffer1);
|
|
358
|
+
const LegendWaistUp = await doc.embedJpg(upBuffer2);
|
|
359
|
+
const LegendWaistDown = await doc.embedJpg(downBuffer);
|
|
360
|
+
newPage.drawImage(LegendNeckUp, {
|
|
361
|
+
x: width * 0.83796,
|
|
362
|
+
y: height * 0.94611 - width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
|
|
363
|
+
width: width * 0.14 * 0.33,
|
|
364
|
+
height: width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
|
|
365
|
+
});
|
|
366
|
+
newPage.drawImage(LegendWaistUp, {
|
|
367
|
+
x: width * 0.83796 + width * 0.14 * 0.33,
|
|
368
|
+
y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
|
|
369
|
+
width: width * 0.14 * 0.33,
|
|
370
|
+
height: width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
|
|
371
|
+
});
|
|
372
|
+
newPage.drawImage(LegendWaistDown, {
|
|
373
|
+
x: width * 0.83796 + width * 0.14 * .66,
|
|
374
|
+
y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width),
|
|
375
|
+
width: width * 0.14 * 0.33,
|
|
376
|
+
height: width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width)
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
//split into 2 columns & strectch
|
|
382
|
+
console.log("split legend into 2 columns & stretch ")
|
|
383
|
+
const fullLegendimg = new Image();
|
|
384
|
+
fullLegendimg.src = inputs.LegendImgBase64
|
|
385
|
+
fullLegendimg.onload = async () => {
|
|
386
|
+
const halfHeight = Math.floor(legendImage.height / 2)
|
|
387
|
+
const waistUpCanvas = document.createElement('canvas');
|
|
388
|
+
waistUpCanvas.width = legendImage.width;
|
|
389
|
+
waistUpCanvas.height = halfHeight;
|
|
390
|
+
const waistUpCtx = waistUpCanvas.getContext('2d');
|
|
391
|
+
waistUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
|
|
392
|
+
const waistDownCanvas = document.createElement('canvas');
|
|
393
|
+
waistDownCanvas.width = legendImage.width;
|
|
394
|
+
waistDownCanvas.height = halfHeight;
|
|
395
|
+
const waistDownCtx = waistDownCanvas.getContext('2d');
|
|
396
|
+
waistDownCtx!.drawImage(fullLegendimg, 0, halfHeight, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
|
|
397
|
+
const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
|
|
398
|
+
const upBuffer = this.base64ToArrayBuffer(waistUpBase64);
|
|
399
|
+
const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
|
|
400
|
+
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
401
|
+
const LegendUp = await doc.embedJpg(upBuffer);
|
|
402
|
+
const LegendDown = await doc.embedJpg(downBuffer);
|
|
403
|
+
|
|
404
|
+
newPage.drawImage(LegendUp, {
|
|
405
|
+
x: width * 0.83796,
|
|
406
|
+
y: height * (0.94611 - 0.77),
|
|
407
|
+
width: height * 0.77 * (LegendUp.width / LegendUp.height),
|
|
408
|
+
height: height * 0.77,
|
|
409
|
+
});
|
|
410
|
+
newPage.drawImage(LegendDown, {
|
|
411
|
+
x: width * 0.83796 + height * 0.77 * (LegendDown.width / LegendDown.height),
|
|
412
|
+
y: height * (0.94611 - 0.77),
|
|
413
|
+
width: height * 0.77 * (LegendDown.width / LegendDown.height),
|
|
414
|
+
height: height * 0.77,
|
|
415
|
+
})
|
|
416
|
+
}
|
|
345
417
|
}
|
|
346
418
|
}
|
|
347
419
|
else {
|
|
348
|
-
//split into 2 columns & strectch
|
|
349
|
-
console.log("split legend into 2 columns
|
|
420
|
+
//split into 2 columns & no strectch
|
|
421
|
+
console.log("split legend into 2 columns & no strectch")
|
|
350
422
|
const fullLegendimg = new Image();
|
|
351
423
|
fullLegendimg.src = inputs.LegendImgBase64
|
|
352
424
|
fullLegendimg.onload = async () => {
|
|
@@ -367,89 +439,64 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
367
439
|
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
368
440
|
const LegendUp = await doc.embedJpg(upBuffer);
|
|
369
441
|
const LegendDown = await doc.embedJpg(downBuffer);
|
|
370
|
-
|
|
371
442
|
newPage.drawImage(LegendUp, {
|
|
372
443
|
x: width * 0.83796,
|
|
373
|
-
y: height * (0.94611 - 0.
|
|
374
|
-
width:
|
|
375
|
-
height:
|
|
444
|
+
y: height * (0.94611) - width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
|
|
445
|
+
width: width * 0.14 * 0.5,
|
|
446
|
+
height: width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
|
|
376
447
|
});
|
|
377
448
|
newPage.drawImage(LegendDown, {
|
|
378
|
-
x: width * 0.83796 +
|
|
379
|
-
y: height * (0.94611 - 0.
|
|
380
|
-
width:
|
|
381
|
-
height:
|
|
449
|
+
x: width * 0.83796 + width * 0.14 * 0.505,
|
|
450
|
+
y: height * (0.94611) - width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width),
|
|
451
|
+
width: width * 0.14 * 0.5,
|
|
452
|
+
height: width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width)
|
|
382
453
|
})
|
|
383
454
|
}
|
|
384
455
|
}
|
|
385
456
|
}
|
|
386
457
|
else {
|
|
387
|
-
//
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
waistUpCanvas.width = legendImage.width;
|
|
395
|
-
waistUpCanvas.height = halfHeight;
|
|
396
|
-
const waistUpCtx = waistUpCanvas.getContext('2d');
|
|
397
|
-
waistUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
|
|
398
|
-
const waistDownCanvas = document.createElement('canvas');
|
|
399
|
-
waistDownCanvas.width = legendImage.width;
|
|
400
|
-
waistDownCanvas.height = halfHeight;
|
|
401
|
-
const waistDownCtx = waistDownCanvas.getContext('2d');
|
|
402
|
-
waistDownCtx!.drawImage(fullLegendimg, 0, halfHeight, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
|
|
403
|
-
const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
|
|
404
|
-
const upBuffer = this.base64ToArrayBuffer(waistUpBase64);
|
|
405
|
-
const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
|
|
406
|
-
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
407
|
-
const LegendUp = await doc.embedJpg(upBuffer);
|
|
408
|
-
const LegendDown = await doc.embedJpg(downBuffer);
|
|
409
|
-
newPage.drawImage(LegendUp, {
|
|
410
|
-
x: width * 0.83796,
|
|
411
|
-
y: height * (0.94611) - width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
|
|
412
|
-
width: width * 0.14 * 0.5,
|
|
413
|
-
height: width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
|
|
414
|
-
});
|
|
415
|
-
newPage.drawImage(LegendDown, {
|
|
416
|
-
x: width * 0.83796 + width * 0.14 * 0.505,
|
|
417
|
-
y: height * (0.94611) - width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width),
|
|
418
|
-
width: width * 0.14 * 0.5,
|
|
419
|
-
height: width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width)
|
|
420
|
-
})
|
|
421
|
-
}
|
|
458
|
+
// A little bit slim, just stretch
|
|
459
|
+
newPage.drawImage(legendImage, {
|
|
460
|
+
x: width * 0.83796,
|
|
461
|
+
y: height * (0.94611 - 0.77),
|
|
462
|
+
width: height * 0.77 * (legendImage.width / legendImage.height),
|
|
463
|
+
height: height * 0.77,
|
|
464
|
+
});
|
|
422
465
|
}
|
|
423
466
|
}
|
|
424
|
-
|
|
425
|
-
// A little bit slim, just stretch
|
|
426
|
-
newPage.drawImage(legendImage, {
|
|
427
|
-
x: width * 0.83796,
|
|
428
|
-
y: height * (0.94611 - 0.77),
|
|
429
|
-
width: height * 0.77 * (legendImage.width / legendImage.height),
|
|
430
|
-
height: height * 0.77,
|
|
431
|
-
});
|
|
432
|
-
}
|
|
467
|
+
console.log('legend image drawn successfully')
|
|
433
468
|
}
|
|
434
469
|
const lableSize = 100
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
470
|
+
if (inputs.template == 'VMP') {
|
|
471
|
+
newPage.drawImage(image10, {
|
|
472
|
+
x: 28 + 200,
|
|
473
|
+
y: 145,
|
|
474
|
+
width: lableSize,
|
|
475
|
+
height: lableSize * (image10.height / image10.width),
|
|
476
|
+
});
|
|
477
|
+
console.log('image10 drawn successfully')
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
newPage.drawImage(image1, {
|
|
481
|
+
x: 28,
|
|
482
|
+
y: 145,
|
|
483
|
+
width: lableSize,
|
|
484
|
+
height: lableSize * (image1.height / image1.width),
|
|
485
|
+
});
|
|
486
|
+
newPage.drawImage(image2, {
|
|
487
|
+
x: 28 + lableSize + 6,
|
|
488
|
+
y: 145,
|
|
489
|
+
width: lableSize,
|
|
490
|
+
height: lableSize * (image2.height / image2.width),
|
|
491
|
+
});
|
|
492
|
+
newPage.drawImage(image3, {
|
|
493
|
+
x: 28 + 2 * lableSize + 6 * 2,
|
|
494
|
+
y: 145,
|
|
495
|
+
width: lableSize * .8,
|
|
496
|
+
height: lableSize * .8 * (image3.height / image3.width),
|
|
497
|
+
});
|
|
498
|
+
console.log('image1,2,3 drawn successfully')
|
|
499
|
+
}
|
|
453
500
|
console.log(`success in page. ${i} `)
|
|
454
501
|
// north arrow
|
|
455
502
|
const centerX = 40;
|
|
@@ -524,6 +571,18 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
524
571
|
const revField = form.getTextField('Rev.' + i)
|
|
525
572
|
revField.setText(inputs.Rev)
|
|
526
573
|
revField.updateAppearances(font)
|
|
574
|
+
if (inputs.template=='VMP'){
|
|
575
|
+
//supervisor
|
|
576
|
+
const supervisorField = form.getTextField('Supervisor')
|
|
577
|
+
supervisorField.setText(inputs.extraField['supervisor'])
|
|
578
|
+
supervisorField.setAlignment(TextAlignment.Center)
|
|
579
|
+
supervisorField.updateAppearances(font)
|
|
580
|
+
//UHF
|
|
581
|
+
const uhfField = form.getTextField('UHF')
|
|
582
|
+
uhfField.setText(inputs.extraField['UHF'])
|
|
583
|
+
uhfField.setAlignment(TextAlignment.Center)
|
|
584
|
+
uhfField.updateAppearances(font)
|
|
585
|
+
}
|
|
527
586
|
//date
|
|
528
587
|
const today = new Date();
|
|
529
588
|
const formattedDate = today.toLocaleDateString('en-AU');
|
|
@@ -553,90 +612,109 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
553
612
|
}
|
|
554
613
|
console.log('Text Fields removal successful')
|
|
555
614
|
//draw a QR Code image only when Qr URL is given && QR image not given
|
|
615
|
+
const boldFont = await doc.embedFont(StandardFonts.HelveticaBold);
|
|
556
616
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
x: buttonX+5,
|
|
574
|
-
y: buttonY+22,
|
|
575
|
-
size: 10,
|
|
576
|
-
color: rgb(1, 1, 1), // White color
|
|
577
|
-
font: boldFont,
|
|
578
|
-
});
|
|
617
|
+
if (inputs.template == 'VMP') {
|
|
618
|
+
newPage.drawText('Maximum Speed 10KM/h within Work Area', {
|
|
619
|
+
x: 28,
|
|
620
|
+
y: 145,
|
|
621
|
+
size: 10.5,
|
|
622
|
+
color: rgb(255, 255, 255), // White color
|
|
623
|
+
font: boldFont,
|
|
624
|
+
});
|
|
625
|
+
newPage.drawText('Maximum Speed 10KM/h within Work Area', {
|
|
626
|
+
x: 28,
|
|
627
|
+
y: 145,
|
|
628
|
+
size: 10,
|
|
629
|
+
color: rgb(255, 0, 0), // red color
|
|
630
|
+
font: boldFont,
|
|
631
|
+
});
|
|
632
|
+
}
|
|
579
633
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
},
|
|
595
|
-
})
|
|
596
|
-
);
|
|
597
|
-
// Append the new annotation to the existing ones
|
|
598
|
-
annotationsArray.push(linkAnnotation);
|
|
599
|
-
// Set the updated annotations array back to the page
|
|
600
|
-
newPage.node.set(PDFName.of('Annots'), annotationsArray);
|
|
601
|
-
}
|
|
634
|
+
if (inputs.buttonLink && inputs.buttonLink.length > 0) {
|
|
635
|
+
const buttonX = width * 0.74
|
|
636
|
+
const buttonY = 130
|
|
637
|
+
const buttonW = 90
|
|
638
|
+
const buttonH = 50
|
|
639
|
+
const buttonBackgroundUrl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/gis-button.png'
|
|
640
|
+
const buttonBackgroundBuffer = await this.fetchData(buttonBackgroundUrl);
|
|
641
|
+
const buttonEmbed = await doc.embedPng(buttonBackgroundBuffer);
|
|
642
|
+
newPage.drawImage(buttonEmbed, {
|
|
643
|
+
x: buttonX,
|
|
644
|
+
y: buttonY,
|
|
645
|
+
width: buttonW,
|
|
646
|
+
height: buttonH,
|
|
647
|
+
});
|
|
602
648
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
649
|
+
newPage.drawText('Go to EBTA GIS', {
|
|
650
|
+
x: buttonX + 5,
|
|
651
|
+
y: buttonY + 22,
|
|
652
|
+
size: 10,
|
|
653
|
+
color: rgb(1, 1, 1), // White color
|
|
654
|
+
font: boldFont,
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
|
|
659
|
+
let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
const linkAnnotation = doc.context.register(
|
|
663
|
+
doc.context.obj({
|
|
664
|
+
Type: 'Annot',
|
|
665
|
+
Subtype: 'Link',
|
|
666
|
+
Rect: [buttonX, buttonY, buttonX + buttonW, buttonY + buttonH],
|
|
667
|
+
Border: [0, 0, 0],
|
|
668
|
+
A: {
|
|
669
|
+
Type: 'Action',
|
|
670
|
+
S: 'URI',
|
|
671
|
+
URI: PDFString.of((i <= (inputs.buttonLink.length - 1)) ? inputs.buttonLink[i] : inputs.buttonLink[inputs.buttonLink.length - 1]),
|
|
672
|
+
},
|
|
673
|
+
})
|
|
674
|
+
);
|
|
675
|
+
// Append the new annotation to the existing ones
|
|
676
|
+
annotationsArray.push(linkAnnotation);
|
|
677
|
+
// Set the updated annotations array back to the page
|
|
678
|
+
newPage.node.set(PDFName.of('Annots'), annotationsArray);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (inputs.QrUrl && inputs.QrUrl.length > 0 && (inputs.QrCodeImage == undefined)) {
|
|
682
|
+
//QR Code
|
|
683
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
684
|
+
const QRCode = require('qrcode');
|
|
685
|
+
const qrDataUrl = (i <= (inputs.QrUrl.length - 1)) ? await QRCode.toDataURL(inputs.QrUrl[i]) : await QRCode.toDataURL(inputs.QrUrl[inputs.QrUrl.length - 1]);
|
|
686
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
687
|
+
const qrImageBytes = await fetch(qrDataUrl).then(res => res.arrayBuffer());
|
|
688
|
+
const qrImage = await doc.embedPng(qrImageBytes);
|
|
689
|
+
newPage.drawImage(qrImage, {
|
|
690
|
+
x: 210,
|
|
691
|
+
y: 93,
|
|
692
|
+
width: 40,
|
|
693
|
+
height: 40,
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
|
|
697
|
+
let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
|
|
698
|
+
const linkAnnotation = doc.context.register(
|
|
699
|
+
doc.context.obj({
|
|
700
|
+
Type: 'Annot',
|
|
701
|
+
Subtype: 'Link',
|
|
702
|
+
Rect: [210, 93, 250, 93 + 40],
|
|
703
|
+
Border: [0, 0, 0],
|
|
704
|
+
A: {
|
|
705
|
+
Type: 'Action',
|
|
706
|
+
S: 'URI',
|
|
707
|
+
URI: PDFString.of((i <= (inputs.QrUrl.length - 1)) ? inputs.QrUrl[i] : inputs.QrUrl[inputs.QrUrl.length - 1]),
|
|
708
|
+
},
|
|
709
|
+
})
|
|
710
|
+
);
|
|
711
|
+
// Append the new annotation to the existing ones
|
|
712
|
+
annotationsArray.push(linkAnnotation);
|
|
713
|
+
// Set the updated annotations array back to the page
|
|
714
|
+
newPage.node.set(PDFName.of('Annots'), annotationsArray);
|
|
715
|
+
}
|
|
617
716
|
|
|
618
|
-
const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
|
|
619
|
-
let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
|
|
620
|
-
const linkAnnotation = doc.context.register(
|
|
621
|
-
doc.context.obj({
|
|
622
|
-
Type: 'Annot',
|
|
623
|
-
Subtype: 'Link',
|
|
624
|
-
Rect: [210, 93, 250, 93+40],
|
|
625
|
-
Border: [0, 0, 0],
|
|
626
|
-
A: {
|
|
627
|
-
Type: 'Action',
|
|
628
|
-
S: 'URI',
|
|
629
|
-
URI: PDFString.of((i <= (inputs.QrUrl.length - 1)) ? inputs.QrUrl[i] : inputs.QrUrl[inputs.QrUrl.length - 1]),
|
|
630
|
-
},
|
|
631
|
-
})
|
|
632
|
-
);
|
|
633
|
-
// Append the new annotation to the existing ones
|
|
634
|
-
annotationsArray.push(linkAnnotation);
|
|
635
|
-
// Set the updated annotations array back to the page
|
|
636
|
-
newPage.node.set(PDFName.of('Annots'), annotationsArray);
|
|
637
|
-
}
|
|
638
717
|
|
|
639
|
-
|
|
640
718
|
if (inputs.QrCodeImage && inputs.QrCodeImage.length > 0) {
|
|
641
719
|
const inputQrImageUrl = (i <= (inputs.QrCodeImage.length - 1)) ? inputs.QrCodeImage[i] : inputs.QrCodeImage[inputs.QrCodeImage.length - 1]
|
|
642
720
|
const inputQrBuffer = await this.fetchData(inputQrImageUrl);
|
|
@@ -644,13 +722,13 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
644
722
|
let inputQRembed
|
|
645
723
|
console.log(inputQrImageUrl);
|
|
646
724
|
console.log(inputQrImageUrl.toLowerCase().includes(".png"));
|
|
647
|
-
console.log(inputQrImageUrl.toLowerCase().includes(".jpg")||inputQrImageUrl.toLowerCase().includes(".jpeg"));
|
|
648
|
-
if (inputQrImageUrl.toLowerCase().includes(".png")){
|
|
649
|
-
|
|
650
|
-
|
|
725
|
+
console.log(inputQrImageUrl.toLowerCase().includes(".jpg") || inputQrImageUrl.toLowerCase().includes(".jpeg"));
|
|
726
|
+
if (inputQrImageUrl.toLowerCase().includes(".png")) {
|
|
727
|
+
inputQRembed = await doc.embedPng(inputQrBuffer);
|
|
728
|
+
console.log('embed QR Code image as png');
|
|
651
729
|
}
|
|
652
|
-
|
|
653
|
-
else if (inputQrImageUrl.toLowerCase().includes(".jpg")||inputQrImageUrl.toLowerCase().includes(".jpeg")){
|
|
730
|
+
|
|
731
|
+
else if (inputQrImageUrl.toLowerCase().includes(".jpg") || inputQrImageUrl.toLowerCase().includes(".jpeg")) {
|
|
654
732
|
console.log(inputQrBuffer)
|
|
655
733
|
const dataView = new DataView(inputQrBuffer);
|
|
656
734
|
console.log(dataView)
|
|
@@ -665,11 +743,11 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
665
743
|
console.log('SOI marker not found but forcing to be correct.');
|
|
666
744
|
let fixedArrayBuffer = await this.reencodeImageToArrayBuffer(inputQrBuffer)
|
|
667
745
|
inputQRembed = await doc.embedJpg(fixedArrayBuffer);
|
|
668
|
-
}
|
|
746
|
+
}
|
|
669
747
|
console.log('embed QR Code image as jpg successful');
|
|
670
748
|
}
|
|
671
749
|
|
|
672
|
-
|
|
750
|
+
|
|
673
751
|
newPage.drawImage(inputQRembed, {
|
|
674
752
|
x: 210,
|
|
675
753
|
y: 93,
|
|
@@ -699,7 +777,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
699
777
|
filledPDFs.push(await doc.save());
|
|
700
778
|
|
|
701
779
|
}
|
|
702
|
-
|
|
780
|
+
|
|
703
781
|
const finalPDF = await PDFDocument.create();
|
|
704
782
|
|
|
705
783
|
// Copy pages from all filled PDFs into the final document
|
|
@@ -711,6 +789,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
711
789
|
|
|
712
790
|
const pdfBytes = await finalPDF.save();
|
|
713
791
|
const base64String = this.arrayBufferToBase64(pdfBytes);
|
|
792
|
+
//was and still working fine, ignore the bug report
|
|
714
793
|
const downloadUrl = this.createDownloadUrl(base64String);
|
|
715
794
|
console.log('pdf file created and ready to download');
|
|
716
795
|
return {
|