# HG changeset patch # User Markus Kottlaender # Date 1550220477 -3600 # Node ID a6cfa06c59833ed1d9c74c3176b050b495b04f7b # Parent ad9ede1a9e11e691bc7f7401d104338ca187f588 client: pdf-gen: added cancel button Prevents the rendercomplete event to fire. Should be enough since rendering the map takes most of time of the process. diff -r ad9ede1a9e11 -r a6cfa06c5983 client/src/components/Pdftool.vue --- a/client/src/components/Pdftool.vue Thu Feb 14 16:30:37 2019 +0100 +++ b/client/src/components/Pdftool.vue Fri Feb 15 09:47:57 2019 +0100 @@ -59,18 +59,23 @@ + @@ -155,7 +160,10 @@ height: null }, logoImageForPDF: null, // a HTMLImageElement instance - readyToGenerate: true // if the user is allowed to press the button + readyToGenerate: true, // if the user is allowed to press the button + rendercompleteListener: null, + mapSize: null, + mapExtent: null }; }, computed: { @@ -231,15 +239,15 @@ // Step 2 which starts rendering a map with the necessary image size var map = this.openLayersMap; - var mapSize = map.getSize(); // size in pixels of the map in the DOM + this.mapSize = map.getSize(); // size in pixels of the map in the DOM // Calculate the extent for the current view state and the passed size. // The size is the pixel dimensions of the box into which the calculated // extent should fit. - var mapExtent = map.getView().calculateExtent(mapSize); + this.mapExtent = map.getView().calculateExtent(this.mapSize); this.pdf.doc = new jsPDF(this.form.format, "mm", this.form.paperSize); // set a callback for after the next complete rendering of the map - map.once("rendercomplete", event => { + this.rendercompleteListener = map.once("rendercomplete", event => { let canvas = event.context.canvas; // because we are using Web Mercator, a pixel represents @@ -368,8 +376,8 @@ } // reset to original size - map.setSize(mapSize); - map.getView().fit(mapExtent, { size: mapSize }); + map.setSize(this.mapSize); + map.getView().fit(this.mapExtent, { size: this.mapSize }); // as we are done: re-enable button this.readyToGenerate = true; @@ -377,7 +385,16 @@ // trigger rendering map.setSize(mapSizeForPrint); - map.getView().fit(mapExtent, { size: mapSizeForPrint }); + map.getView().fit(this.mapExtent, { size: mapSizeForPrint }); + }, + cancel() { + this.openLayersMap.un( + this.rendercompleteListener.type, + this.rendercompleteListener.listener + ); + this.openLayersMap.setSize(this.mapSize); + this.openLayersMap.getView().fit(this.mapExtent, { size: this.mapSize }); + this.readyToGenerate = true; }, addRoundedBox(x, y, w, h, color, rounding) { // draws a rounded background box at (x,y) width x height