diff --git a/src/module_vmap/module/javascript/app/vmap/tools/printBox.js b/src/module_vmap/module/javascript/app/vmap/tools/printBox.js index b359736577fd4fc861e58c471cf2f0aad568d5ae..d25f47f7a8ca5d9588d23e08f23767f1ad9d6c16 100755 --- a/src/module_vmap/module/javascript/app/vmap/tools/printBox.js +++ b/src/module_vmap/module/javascript/app/vmap/tools/printBox.js @@ -18,11 +18,13 @@ goog.require('ol.interaction.Translate'); nsVmap.nsToolsManager.PrintBox = function (opt_options) { oVmap.log('nsVmap.nsToolsManager.PrintBox'); - this.map_ = oVmap.getMap().getOLMap(); - // Valeurs par défaut opt_options = goog.isDefAndNotNull(opt_options) ? opt_options : {}; + this.oMap_ = (goog.isDefAndNotNull(opt_options["map_object"])? opt_options["map_object"]: oVmap.getMap()); + + this.map_ = this.oMap_.getOLMap(); + /** * The print box feature * @private @@ -45,7 +47,7 @@ nsVmap.nsToolsManager.PrintBox = function (opt_options) { * @type {ol.layer.Vector} * @private */ - this.oOpenLayersOverlay_ = oVmap.getMap().addVectorLayer(); + this.oOpenLayersOverlay_ = this.oMap_.addVectorLayer(); /** * @type {ol.Collection} @@ -110,7 +112,7 @@ nsVmap.nsToolsManager.PrintBox.prototype.managePrintBox = function (sInteraction this.unlistenMapMovements(); // Ajoute l'interaction de déplacement de la printBox - oVmap.getMap().setInteraction(this.translateInteraction_, sInteractionName); + this.oMap_.setInteraction(this.translateInteraction_, sInteractionName); }; @@ -122,12 +124,23 @@ nsVmap.nsToolsManager.PrintBox.prototype.unmanagePrintBox = function () { oVmap.log('nsVmap.nsToolsManager.PrintBox.unmanagePrintBox'); // remove l'action de modification - oVmap.getMap().removeActionsAndTooltips(); + this.oMap_.removeActionsAndTooltips(); this.drawPrintBox(); this.listenMapMovements(); }; +/** + * Cancel the printZone manage interaction and adapt the view on it + * @export + */ +nsVmap.nsToolsManager.PrintBox.prototype.unmanagePrintBoxAndLock = function () { + oVmap.log('nsVmap.nsToolsManager.PrintBox.unmanagePrintBox'); + + // remove l'action de modification + this.oMap_.removeActionsAndTooltips(); +}; + /** * Get the print box scale * @returns {Number|String} @@ -149,7 +162,7 @@ nsVmap.nsToolsManager.PrintBox.prototype.getScale = function () { nearest: true }); - var scale = oVmap.getMap().getScale(); + var scale = this.oMap_.getScale(); setTimeout(function () { // Retrouve la position initiale @@ -166,13 +179,13 @@ nsVmap.nsToolsManager.PrintBox.prototype.getScale = function () { * @export */ nsVmap.nsToolsManager.PrintBox.prototype.setScale = function (newScale) { - + // Échelle courante var currentScale = this.getScale(); // Calcul du delta entre l'échelle courrante et l'échelle voulue var deltaScale = newScale / currentScale; - + // Mise sous forme de variables pour une meilleure compréhension var currentExtent = this.getExtent(); var xmin = currentExtent[0]; @@ -185,7 +198,7 @@ nsVmap.nsToolsManager.PrintBox.prototype.setScale = function (newScale) { // Calcul de la nouvelle hauteur/largeur de la printBox var newLength = length * deltaScale; var newHeight = height * deltaScale; - + // Calcul des nouvelles coordonnées en fonction du centre et des nouvelles hauteur/largeur var center = this.printBoxFeature_.getGeometry().getInteriorPoint().getCoordinates(); var newXmin = center[0] - newLength / 2; @@ -198,10 +211,10 @@ nsVmap.nsToolsManager.PrintBox.prototype.setScale = function (newScale) { this.printBoxFeature_ = new ol.Feature({ geometry: box }); - + // Supprime l'ancienne feature this.oOpenLayersOverlayFeatures_.clear(); - + // Ajoute la nouvelle feature this.oOpenLayersOverlay_.getSource().addFeature(this.printBoxFeature_); }; @@ -239,7 +252,7 @@ nsVmap.nsToolsManager.PrintBox.prototype.getExtent = function () { */ nsVmap.nsToolsManager.PrintBox.prototype.listenMapMovements = function () { - this.printBoxEvent_ = oVmap.getMap().setEventOnMap('precompose', this.drawPrintBox, this); + this.printBoxEvent_ = this.oMap_.setEventOnMap('precompose', this.drawPrintBox, this); }; /** @@ -286,10 +299,12 @@ nsVmap.nsToolsManager.PrintBox.prototype.createPrintBox = function (printBoxSize var boxWidth = printBoxSize[0]; var boxHeight = printBoxSize[1]; - var x1 = $('#map1').width() / 2 - boxWidth / 2; - var x2 = $('#map1').width() / 2 + boxWidth / 2; - var y1 = $('#map1').height() / 2 - boxHeight / 2; - var y2 = $('#map1').height() / 2 + boxHeight / 2; + var sMapComponentId = this.map_.getViewport().getAttribute('id'); + + var x1 = $('#' + sMapComponentId).width() / 2 - boxWidth / 2; + var x2 = $('#' + sMapComponentId).width() / 2 + boxWidth / 2; + var y1 = $('#' + sMapComponentId).height() / 2 - boxHeight / 2; + var y2 = $('#' + sMapComponentId).height() / 2 + boxHeight / 2; var point1 = [x1, y2]; var point3 = [x2, y1]; @@ -306,4 +321,4 @@ nsVmap.nsToolsManager.PrintBox.prototype.createPrintBox = function (printBoxSize boxFeature.set('pixelExtent', [x1, y1, x2, y2]); return boxFeature; -}; \ No newline at end of file +};