commit 21e7828d956383c6206f9c9a505f632c2cdc2929
parent 30f02cddf1b5cdb3ecf4ac1523a290c7295e34bb
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Fri, 7 Feb 2020 09:27:38 +0100
logging: improve logging for pdf print
Diffstat:
2 files changed, 86 insertions(+), 14 deletions(-)
diff --git a/src/App.js b/src/App.js
@@ -198,24 +198,79 @@ function setUp() {
});
azimuthControl.on('elevation-shown', () => tracklist.hideElevationProfile());
+ /* setup events logging */
+
+ function getLayerLoggingInfo(layer) {
+ if (layer.meta) {
+ return {title: layer.meta.title};
+ } else if (layer.__customLayer) {
+ return {custom: true, title: layer.__customLayer.title, url: layer._url};
+ }
+ return null;
+ }
+
+ function getLatLngBoundsLoggingInfo(latLngBounds) {
+ return {
+ west: latLngBounds.getWest(),
+ south: latLngBounds.getSouth(),
+ east: latLngBounds.getEast(),
+ north: latLngBounds.getNorth(),
+ };
+ }
+
function logUsedMaps() {
const layers = [];
map.eachLayer((layer) => {
- if (layer.meta) {
- layers.push({title: layer.meta.title});
- } else if (layer.__customLayer) {
- layers.push({custom: true, title: layer.__customLayer.title, url: layer._url});
+ const layerInfo = getLayerLoggingInfo(layer);
+ if (layerInfo) {
+ layers.push(layerInfo);
}
});
const bounds = map.getBounds();
logging.logEvent('activeLayers', {
layers,
- view: {west: bounds.getWest(), south: bounds.getSouth(), east: bounds.getEast(), north: bounds.getNorth()},
+ view: getLatLngBoundsLoggingInfo(bounds),
});
}
L.DomEvent.on(document, 'mousemove click touchend', L.Util.throttle(logUsedMaps, 10000));
+ printControl.on('mapRenderEnd', function(e) {
+ logging.logEvent('mapRenderEnd', {
+ eventId: e.eventId,
+ success: e.success,
+ error: e.error
+ ? {
+ name: e.error.name,
+ message: e.error.message,
+ stack: e.error.stack,
+ }
+ : null,
+ });
+ });
+
+ printControl.on('mapRenderStart', function(e) {
+ const layers = [];
+ map.eachLayer((layer) => {
+ const layerInfo = getLayerLoggingInfo(layer);
+ if (layer.options?.print && layerInfo) {
+ layers.push({
+ ...getLayerLoggingInfo(layer),
+ scaleDependent: layer.options.scaleDependent
+ });
+ }
+ });
+ logging.logEvent('mapRenderStart', {
+ eventId: e.eventId,
+ action: e.action,
+ scale: e.scale,
+ resolution: e.resolution,
+ pages: e.pages.map((page) => getLatLngBoundsLoggingInfo(page.latLngBounds)),
+ zooms: e.zooms,
+ layers
+ });
+ });
+
logging.logEvent('start', startInfo);
logUsedMaps();
}
diff --git a/src/lib/leaflet.control.printPages/control.js b/src/lib/leaflet.control.printPages/control.js
@@ -217,11 +217,19 @@ L.Control.PrintPages = L.Control.extend({
const width = this.pageWidth();
const height = this.pageHeight();
const eventId = logging.randId();
- logging.logEvent('print pdf start', {eventId});
+ const zooms = this.zoomForPrint();
+ this.fire('mapRenderStart', {
+ action: 'pdf',
+ eventId,
+ scale,
+ resolution,
+ pages,
+ zooms
+ });
renderPages({
map: this._map,
pages,
- zooms: this.zoomForPrint(),
+ zooms,
resolution,
scale,
decorationLayers,
@@ -237,12 +245,12 @@ L.Control.PrintPages = L.Control.extend({
extension: 'pdf'
});
savePagesPdf(images, resolution, fileName);
- logging.logEvent('print pdf end', {eventId, success: true});
+ this.fire('mapRenderEnd', {eventId, success: true});
}
}
).catch((e) => {
logging.captureException(e, 'raster creation failed');
- logging.logEvent('print pdf end', {eventId, success: false, error: e.stack});
+ this.fire('mapRenderEnd', {eventId, success: false, error: e});
notify(`Failed to create PDF: ${e.message}`);
}
).then(() => this.makingPdf(false));
@@ -266,16 +274,25 @@ L.Control.PrintPages = L.Control.extend({
this.downloadProgressRange(1000);
this.downloadProgressDone(undefined);
this.makingPdf(true);
+ const resolution = this.resolution();
const scale = this.scale();
const width = this.pageWidth();
const height = this.pageHeight();
const eventId = logging.randId();
- logging.logEvent('print jpg start', {eventId});
+ const zooms = this.zoomForPrint();
+ this.fire('mapRenderStart', {
+ action: 'jpg',
+ eventId,
+ scale,
+ resolution,
+ pages,
+ zooms
+ });
renderPages({
map: this._map,
pages,
- zooms: this.zoomForPrint(),
- resolution: this.resolution(),
+ zooms,
+ resolution,
scale,
decorationLayers,
progressCallback: this.incrementProgress.bind(this)
@@ -290,11 +307,11 @@ L.Control.PrintPages = L.Control.extend({
extension: 'jpg'
});
savePageJpg(images[0], fileName);
- logging.logEvent('print jpg end', {eventId, success: true});
+ this.fire('mapRenderEnd', {eventId, success: true});
})
.catch((e) => {
logging.captureException(e, 'raster creation failed');
- logging.logEvent('print jpg end', {eventId, success: false, error: e.stack});
+ this.fire('mapRenderEnd', {eventId, success: false, error: e});
notify(`Failed to create JPEG from page: ${e.message}`);
}
).then(() => this.makingPdf(false));