1 /** 2 * @fileOverview 3 * Copyright (c) 2013 Regione Autonoma della Sardegna 4 * Published under the GPL license.<br> 5 * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a> 6 * for the full text of the license. 7 * @version 0.1 8 */ 9 10 /** 11 * @namespace framework.widgets.doublemap 12 */ 13 Ext.namespace('framework.widgets.doublemap'); 14 15 /** 16 * Command for displaying/hiding one of two columns in a BoxLayout. Used to 17 * display/hide second map in the main page 18 * 19 * @name_ ToggleColumnButton 20 * @class Command for displaying/hiding one of two columns in a BoxLayout 21 * @constructor 22 * @extends <a target="_blank" href="http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.Button">Ext.Button</a> 23 */ 24 framework.widgets.doublemap.ToggleColumnButton = Ext.extend(Ext.Button, 25 26 /** 27 * @lends framework.widgets.doublemap.ToggleColumnButton.prototype 28 */ 29 { 30 /** 31 * ID Button 32 * @public 33 * @type String 34 */ 35 id: 'hideSecondMapCtrl2', 36 37 /** 38 * Enable button 39 * @public 40 * @type Boolean 41 */ 42 enableToggle: true, 43 44 /** 45 * If border (true/false) 46 * @public 47 * @type Boolean 48 */ 49 border:false, 50 51 /** 52 * If pressed button 53 * @public 54 * @type Boolean 55 */ 56 pressed:false, 57 58 /** 59 * ID Secondary panel 60 * @public 61 * @type String 62 */ 63 secondaryPanel: "comp2", 64 65 /** 66 * ID Main panel 67 * @public 68 * @type String 69 */ 70 mainPanel: "comp1", 71 72 /** 73 * ID Panels containers 74 * @public 75 * @type String 76 */ 77 panelsContainer: null, 78 79 /** 80 * ID pressed class 81 * @public 82 * @type String 83 */ 84 pressedCls: '', 85 86 /** 87 * Text tooltip for closed double map 88 * @public 89 * @type String 90 */ 91 tooltipCloseDoubleMap: 'chiudi la mappa doppia', 92 93 /** 94 * Text tooltip for open double map 95 * @public 96 * @type String 97 */ 98 tooltipOpenDoubleMap: 'apri la mappa doppia', 99 100 /** 101 * Method: constructor 102 * 103 * @private 104 */ 105 constructor: function(config){ 106 framework.widgets.doublemap.ToggleColumnButton.superclass.constructor.apply(this,arguments); 107 108 109 if (this.pressed){ 110 this.removeClass('x-btn-pressed'); 111 this.removeClass('dmBtn'); 112 this.addClass(this.pressedCls); 113 this.setTooltip(this.tooltipCloseDoubleMap); 114 } 115 else { 116 this.addClass('dmBtn'); 117 this.setTooltip(this.tooltipOpenDoubleMap); 118 } 119 }, 120 121 /** 122 * Method: handler 123 * 124 * @private 125 */ 126 handler:function(){ 127 if (this.pressed){ 128 129 var map1 = Ext.getCmp(this.panelsContainer).app1.mapPanel.map; 130 var map2 = Ext.getCmp(this.panelsContainer).app2.mapPanel.map; 131 132 // per trasformazione coordinate in UTM 32N 133 Proj4js.defs["EPSG:32632"]="+title=UTM 32N +proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "; 134 new Proj4js.Proj('EPSG:32632'); 135 136 var fromProjection = map1.getProjectionObject(); 137 var toProjection = map2.getProjectionObject(); 138 139 var center = new OpenLayers.LonLat(map1.getCenter().lon, map1.getCenter().lat).transform(fromProjection, toProjection); 140 var resolution = map1.getResolution(); 141 var zoom = map1.getZoom(); 142 var scale = map1.getScale(); 143 144 Ext.getCmp(this.panelsContainer).showSecondMap(); 145 this.removeClass('x-btn-pressed'); 146 this.removeClass('dmBtn'); 147 this.addClass(this.pressedCls); 148 this.setTooltip(this.tooltipCloseDoubleMap); 149 150 if (map2.getResolutionForZoom(zoom) > resolution) { 151 map2.zoomTo(map2.getNumZoomLevels()); 152 } 153 else { 154 map2.zoomToScale(scale); 155 } 156 157 map2.setCenter(center); 158 159 //HACK per problema refresh pagina.. 160 map2.zoomIn(); 161 map2.zoomOut(); 162 163 }else{ 164 Ext.getCmp(this.panelsContainer).hideSecondMap(); 165 this.addClass('dmBtn'); 166 this.removeClass(this.pressedCls); 167 this.setTooltip(this.tooltipOpenDoubleMap); 168 } 169 } 170 }); 171 172 Ext.reg('framework_togglecolumnbutton',framework.widgets.doublemap.ToggleColumnButton); 173 174 175 176