From a8af3474814b02247ad272065d5bd0cc0cad62e2 Mon Sep 17 00:00:00 2001 From: Armand Bahi <armand.bahi@veremes.com> Date: Mon, 29 Oct 2018 15:04:05 +0100 Subject: [PATCH] Active the resolution parameter --- module/javascript/app/vmap/tools/print.js | 190 ++++++++++++---------- module/template/tools/print.html | 4 +- web_service/ws/PrintMapServices.class.inc | 12 +- 3 files changed, 108 insertions(+), 98 deletions(-) diff --git a/module/javascript/app/vmap/tools/print.js b/module/javascript/app/vmap/tools/print.js index 342c526f..8c779787 100644 --- a/module/javascript/app/vmap/tools/print.js +++ b/module/javascript/app/vmap/tools/print.js @@ -558,7 +558,6 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.print = function today = dd + '/' + mm + '/' + yyyy; // Valeurs par défaut - var resolutionCoeff = goog.isDefAndNotNull(opt_options.resolutionCoeff) ? opt_options.resolutionCoeff : 1; var templateId = opt_options.templateId; var printStyleId = opt_options.printStyleId; @@ -573,51 +572,6 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.print = function oPrintScope['date'] = goog.isDefAndNotNull(oPrintScope['date']) ? oPrintScope['date'] : today; var sScope = JSON.stringify(oPrintScope); - // Set mapId/mapJson - var sMapId; - var sMapJSON; - if (goog.isDefAndNotNull(opt_options.mapId)) { - sMapId = opt_options.mapId; - } else { - sMapJSON = oVmap.getMapManager().getJSONLayersTree(); - } - - // set EWKTFeatures - var aFeatures = goog.isDefAndNotNull(opt_options.features) ? opt_options.features : []; - var sEWKTFeatures = ''; - for (var i = 0; i < aFeatures.length; i++) { - if (i > 0) - sEWKTFeatures += '|'; - sEWKTFeatures += oVmap.getEWKTFromGeom(aFeatures[i].getGeometry()); - } - - // set extent - var aExtent = goog.isDefAndNotNull(opt_options.extent) ? opt_options.extent : []; - var sExtent = ''; - var aOverviewExtent = [ - aExtent[0] - (aExtent[2] - aExtent[0]), - aExtent[1] - (aExtent[3] - aExtent[1]), - aExtent[2] + (aExtent[2] - aExtent[0]), - aExtent[3] + (aExtent[3] - aExtent[1]) - ]; - var sOverviewExtent = ''; - for (var i = 0; i < aExtent.length; i++) { - if (i > 0) { - sExtent += '|'; - sOverviewExtent += '|'; - } - sExtent += aExtent[i]; - sOverviewExtent += aOverviewExtent[i]; - } - - // Features zoom - var sFeaturesZoom = 100; - if (goog.isDefAndNotNull(opt_options.featuresZoom)) { - sFeaturesZoom = opt_options.featuresZoom; - } else if (goog.isDefAndNotNull(oVmap['properties']['print']['features_zoom'])) { - sFeaturesZoom = oVmap['properties']['print']['features_zoom']; - } - // Ouvre la fenêtre d'impression var printWindow = window.open("", '_blank', 'height=400,width=600'); @@ -664,46 +618,17 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.print = function template.innerHTML = response['data']['data'][0]['definition']; var mapImageSize = this_.getTemplateTargetSize(template, '#map_image'); - var overviezSize = this_.getTemplateTargetSize(template, '#map_overview'); - - if (goog.isDefAndNotNull(mapImageSize)) { - var oMapDef = { - 'map_id': sMapId, - 'map_json': sMapJSON, - 'image_size': (mapImageSize[0] * resolutionCoeff) + '|' + (mapImageSize[1] * resolutionCoeff), - 'resolution_coeff': resolutionCoeff, - 'extent': sExtent, - 'features': sEWKTFeatures, - 'features_zoom': sFeaturesZoom - }; - } - - if (goog.isDefAndNotNull(overviezSize)) { - var oOverviewDef = { - 'map_id': sMapId, - 'map_json': sMapJSON, - 'image_size': (overviezSize[0] * resolutionCoeff) + '|' + (overviezSize[1] * resolutionCoeff), - 'resolution_coeff': resolutionCoeff, - 'extent': sOverviewExtent, - 'features': sEWKTFeatures, - 'features_zoom': 400 - }; - } - - var oMapsJson = []; - if (goog.isDefAndNotNull(oMapDef)) { - oMapsJson.push({ - 'target': '#map_image', - 'map_definition': oMapDef - }); - } - if (goog.isDefAndNotNull(oOverviewDef)) { - oMapsJson.push({ - 'target': '#map_overview', - 'map_definition': oOverviewDef - }); - } - var mapsJson = JSON.stringify(oMapsJson); + var overviewSize = this_.getTemplateTargetSize(template, '#map_overview'); + + var mapsJson = this_.getMapsJsonDef({ + mapId: opt_options.mapId, + resolutionCoeff: opt_options.resolutionCoeff, + extent: opt_options.extent, + features: opt_options.features, + featuresZoom: opt_options.featuresZoom, + mapImageSize: mapImageSize, + overviewSize: overviewSize + }) // Récupère les infos de l'utilisateur this_.getUserInfos_().then(function (oUserInfos) { @@ -773,6 +698,99 @@ nsVmap.nsToolsManager.Print.prototype.printController.prototype.print = function return 1; }; +nsVmap.nsToolsManager.Print.prototype.printController.prototype.getMapsJsonDef = function (opt_options) { + oVmap.log('nsVmap.nsToolsManager.Print.prototype.printController.prototype.getMapsJsonDef'); + + // Resolution + var resolutionCoeff = goog.isDefAndNotNull(opt_options.resolutionCoeff) ? opt_options.resolutionCoeff : 1; + + // mapId/mapJson + var sMapId; + var sMapJSON; + if (goog.isDefAndNotNull(opt_options.mapId)) { + sMapId = opt_options.mapId; + } else { + sMapJSON = oVmap.getMapManager().getJSONLayersTree(); + } + + // Extent + var aExtent = goog.isDefAndNotNull(opt_options.extent) ? opt_options.extent : []; + var sExtent = ''; + var aOverviewExtent = [ + aExtent[0] - (aExtent[2] - aExtent[0]), + aExtent[1] - (aExtent[3] - aExtent[1]), + aExtent[2] + (aExtent[2] - aExtent[0]), + aExtent[3] + (aExtent[3] - aExtent[1]) + ]; + var sOverviewExtent = ''; + for (var i = 0; i < aExtent.length; i++) { + if (i > 0) { + sExtent += '|'; + sOverviewExtent += '|'; + } + sExtent += aExtent[i]; + sOverviewExtent += aOverviewExtent[i]; + } + + // Features + var aFeatures = goog.isDefAndNotNull(opt_options.features) ? opt_options.features : []; + var sEWKTFeatures = ''; + for (var i = 0; i < aFeatures.length; i++) { + if (i > 0) + sEWKTFeatures += '|'; + sEWKTFeatures += oVmap.getEWKTFromGeom(aFeatures[i].getGeometry()); + } + + var sFeaturesZoom = 100; + if (goog.isDefAndNotNull(opt_options.featuresZoom)) { + sFeaturesZoom = opt_options.featuresZoom; + } else if (goog.isDefAndNotNull(oVmap['properties']['print']['features_zoom'])) { + sFeaturesZoom = oVmap['properties']['print']['features_zoom']; + } + + if (goog.isDefAndNotNull(opt_options.mapImageSize)) { + var oMapDef = { + 'map_id': sMapId, + 'map_json': sMapJSON, + 'image_size': (opt_options.mapImageSize[0] * resolutionCoeff) + '|' + (opt_options.mapImageSize[1] * resolutionCoeff), + 'resolution_coeff': resolutionCoeff, + 'extent': sExtent, + 'features': sEWKTFeatures, + 'features_zoom': sFeaturesZoom + }; + } + + if (goog.isDefAndNotNull(opt_options.overviewSize)) { + var oOverviewDef = { + 'map_id': sMapId, + 'map_json': sMapJSON, + 'image_size': (opt_options.overviewSize[0] * resolutionCoeff) + '|' + (opt_options.overviewSize[1] * resolutionCoeff), + 'resolution_coeff': resolutionCoeff, + 'extent': sOverviewExtent, + 'features': sEWKTFeatures, + 'features_zoom': 400 + }; + } + + var oMapsJson = []; + if (goog.isDefAndNotNull(oMapDef)) { + oMapsJson.push({ + 'target': '#map_image', + 'map_definition': oMapDef + }); + } + if (goog.isDefAndNotNull(oOverviewDef)) { + oMapsJson.push({ + 'target': '#map_overview', + 'map_definition': oOverviewDef + }); + } + + var mapsJson = JSON.stringify(oMapsJson); + + return mapsJson; +} + /** * Get the size of a target in a template * @param {string} template diff --git a/module/template/tools/print.html b/module/template/tools/print.html index 92421e58..0a1fd62b 100644 --- a/module/template/tools/print.html +++ b/module/template/tools/print.html @@ -45,8 +45,8 @@ <option value="100">1:100</option> </select> - <div class="hidden print-form-label">Résolution</div> - <select id="select-print-resolution" class="hidden form-control minus" ng-model="ctrl.dpi"> + <div class="print-form-label">Résolution</div> + <select id="select-print-resolution" class="form-control minus" ng-model="ctrl.dpi"> <option value="1">72 dpi</option> <option value="2" ng-show="ctrl.resolution <= 4">144 dpi</option> <option value="4" ng-show="ctrl.resolution <= 2">288 dpi</option> diff --git a/web_service/ws/PrintMapServices.class.inc b/web_service/ws/PrintMapServices.class.inc index 34623aa9..8c656d82 100755 --- a/web_service/ws/PrintMapServices.class.inc +++ b/web_service/ws/PrintMapServices.class.inc @@ -15,7 +15,7 @@ require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/BdDataAccess.i * \brief This file contains the PrintMapServices php class * * This class defines the rest api for printmapservices - * + * */ class PrintMapServices extends PrintServices { /** @@ -241,14 +241,6 @@ class PrintMapServices extends PrintServices { } } - // Change la taille de l'image en fonction de la résolution - if (isset($this->aValues['resolution_coeff'])) { - $aImageSize = explode('|', $sImageSize); - $aImageSize[0] = $aImageSize[0] * $this->aValues['resolution_coeff']; - $aImageSize[1] = $aImageSize[1] * $this->aValues['resolution_coeff']; - $sImageSize = implode('|', $aImageSize); - } - // Écrit les paramètres gros dans des fichiers if (is_dir($this->aProperties['vas_home'])) { if (!is_dir($this->aProperties['vas_home'] . '/public')) { @@ -343,4 +335,4 @@ class PrintMapServices extends PrintServices { } -?> \ No newline at end of file +?> -- GitLab