From 2f744082b9b79e85f930de922e6313194a46a189 Mon Sep 17 00:00:00 2001 From: Armand Bahi <armand.bahi@veremes.com> Date: Mon, 26 Nov 2018 15:13:01 +0100 Subject: [PATCH] =?UTF-8?q?Bug=20d=C3=A9formation=20carte=20imprim=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/javascript/app/vmap/tools/print.js | 72 +++++++++-------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/module/javascript/app/vmap/tools/print.js b/module/javascript/app/vmap/tools/print.js index f05db85a..f2d041ca 100644 --- a/module/javascript/app/vmap/tools/print.js +++ b/module/javascript/app/vmap/tools/print.js @@ -161,11 +161,23 @@ nsVmap.nsToolsManager.Print.prototype.printController = function ($timeout, $com this.template_; /** - * Size of the printZone + * Size of the map printZone * @private */ this.printedMapSize_; + /** + * Size of the compare map printZone + * @private + */ + this.printedCompareMapSize_; + + /** + * Size of the overview map printZone + * @private + */ + this.printedOverviewMapSize_; + /** * this.printedMapSize_ resize coeff * @private @@ -363,10 +375,10 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.loadModelParmas2 oVmap.log('nsVmap.nsToolsManager.Print.printController.loadModelParmas2'); // Récupère la taille de la carte this.printedMapSize_ ainsi que le coefficient this.resizeCoeff_ - oPrintMapSize = this.getPrintedMapSize(this.template_); + this.printedMapSize_ = this.getPrintedMapSize(this.template_, '#map1', '#map_image'); + this.printedOverviewMapSize_ = this.getPrintedMapSize(this.template_, '#map1', '#map_overview'); - this.printedMapSize_ = oPrintMapSize.printedMapSize; - this.resizeCoeff_ = oPrintMapSize.resizeCoeff; + this.resizeCoeff_ = this.printedMapSize_.resizeCoeff; // Pré-rempli le champ "Résolution" this['resolution'] = this.resizeCoeff_; @@ -375,20 +387,21 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.loadModelParmas2 this['currentScale'] = oVmap.getMap().getPrettyScale(oVmap.getMap().getScale() / this.resizeCoeff_); // Dessine un carré d'impression à chaque mouvement de la carte - this.printBox_.setSize(this.printedMapSize_); + this.printBox_.setSize(this.printedMapSize_.printedMapSize); this.printBox_.show(); if(this.$scope_["$root"]["compare_enabled"]){ - this.oComparePrintMapSize = this.getPrintedMapSize(this.template_, "#map1Compare", "#map_image_compare"); - if(this.oComparePrintMapSize !== 0){ + this.printedCompareMapSize_ = this.getPrintedMapSize(this.template_, "#map1Compare", "#map_image_compare"); + + if(this.printedCompareMapSize_ !== 0){ // Pré-rempli le champ "Résolution" - this['resolutionCompare'] = this.oComparePrintMapSize.resizeCoeff; + this['resolutionCompare'] = this.printedCompareMapSize_.resizeCoeff; // Ajuste l'échelle avec le niveau de détail - this['currentScaleCompare'] = oVmap.getMapCompare().getPrettyScale(oVmap.getMapCompare().getScale() / this.oComparePrintMapSize.resizeCoeff); + this['currentScaleCompare'] = oVmap.getMapCompare().getPrettyScale(oVmap.getMapCompare().getScale() / this.printedCompareMapSize_.resizeCoeff); // Dessine un carré d'impression à chaque mouvement de la carte - this.printBoxCompare_.setSize(this.oComparePrintMapSize.printedMapSize); + this.printBoxCompare_.setSize(this.printedCompareMapSize_.printedMapSize); this.printBoxCompare_.show(); } else { this.printBoxCompare_.hide(); @@ -480,6 +493,7 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.getPrintedMapSiz return { printedMapSize: [mapWidth, mapHeight], + realSize: [imageDiv.width(), imageDiv.height()], resizeCoeff: resizeCoeff } }; @@ -583,7 +597,7 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.prepareAndLaunch // récupération des infos pour la carte de comparaison si le mode comparaison est actif if(this.$scope_['$root']["compare_enabled"]){ - if(this.oComparePrintMapSize !== 0){ + if(this.printedCompareMapSize_ !== 0){ // Enregistre l'échelle actuelle this.currentScaleCompare_ = oVmap.getMapCompare().getScale({ 'pretty': true @@ -703,12 +717,9 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.print = function var sFormat = response['data']['data'][0]['rt_format_id']; var sOrientation = response['data']['data'][0]['rt_orientation_id']; - var template = document.createElement("div"); - template.innerHTML = response['data']['data'][0]['definition']; - - var mapImageSize = this_.getTemplateTargetSize(template, '#map_image'); - var mapImageSizeCompare = this_.getTemplateTargetSize(template, '#map_image_compare'); - var overviewSize = this_.getTemplateTargetSize(template, '#map_overview'); + var mapImageSize = this_.printedMapSize_.realSize; + var mapImageSizeCompare = this_.printedCompareMapSize_.realSize; + var overviewSize = this_.printedOverviewMapSize_.realSize; var oJsonDefOptions = { mapId: opt_options.mapId, @@ -919,33 +930,6 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.getMapsJsonDef = return mapsJson; } -/** - * Get the size of a target in a template - * @param {string} template - * @param {string} target - * @returns {Array<Number>|undefined} - */ -nsVmap.nsToolsManager.Print.prototype.printController.prototype.getTemplateTargetSize = function (template, target) { - - var targetDiv = $(template).find(target); - - // Vérifie la présence de '#map_image' - if (!goog.isDef(targetDiv.get(0))) { - oVmap.log('Aucune balise ' + target + ' trouvée dans le template'); - return undefined; - } - - $('body').append(template); - - var targetHeight = targetDiv.height(); - var targetWidth = targetDiv.width(); - - // Supprime le template du body de Vmap - $(template).remove(); - - return [targetWidth, targetHeight]; -}; - /** * Get the html definition of the template with base64 images * @param {string} sTarget -- GitLab