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.ToggleMapsSyncButton = Ext.extend(Ext.Button, 25 26 /** 27 * @lends framework.widgets.doublemap.ToggleMapsSyncButton.prototype 28 */ 29 { 30 /** 31 * ID Button 32 * @public 33 * @type String 34 */ 35 enableToggle: true, 36 37 /** 38 * If border (true/false) 39 * @public 40 * @type Boolean 41 */ 42 border:false, 43 44 /** 45 * If pressed button 46 * @public 47 * @type Boolean 48 */ 49 pressed:true, 50 51 /** 52 * Configured map1 (single map) 53 * 54 * @public 55 * @type {Object} OpenLayers.Map 56 */ 57 map1: null, 58 59 /** 60 * Configured map2 (double map) 61 * 62 * @public 63 * @type {Object} OpenLayers.Map 64 */ 65 map2: null, 66 67 /** 68 * ID pressed class 69 * @public 70 * @type String 71 */ 72 pressedCls: '', 73 74 /** 75 * Activate syncronized map 76 * @public 77 * @type Boolean 78 */ 79 syncActive: false, 80 81 /** 82 * Activate oblique photos 83 * @public 84 * @type Boolean 85 */ 86 obliquePhotoActive: false, 87 88 /** 89 * Text tooltip for sync maps 90 * @public 91 * @type String 92 */ 93 tooltipSync: 'attiva la sincronizzazione', 94 95 /** 96 * Text tooltip for unsync maps 97 * @public 98 * @type String 99 */ 100 tooltipUnSync: 'disattiva la sincronizzazione', 101 102 /** 103 * Method: constructor 104 * 105 * @private 106 */ 107 constructor: function(config){ 108 framework.widgets.doublemap.ToggleColumnButton.superclass.constructor.apply(this,arguments); 109 if (!this.pressed){ 110 this.removeClass('x-btn-pressed'); 111 this.addClass(this.pressedCls); 112 this.setTooltip(this.tooltipSync); 113 } 114 else 115 this.setTooltip(this.tooltipUnSync); 116 }, 117 118 /** 119 * Method: registerSync 120 * 121 * @private 122 */ 123 registerSync: function(){ 124 if (!this.syncActive && !this.obliquePhotoActive){ 125 this.map1.events.register("moveend",this,this.syncMap2); 126 this.map2.events.register("moveend",this,this.syncMap1); 127 this.map1.events.register("zoomend",this,this.syncMap2); 128 this.map2.events.register("zoomend",this,this.syncMap1); 129 this.syncActive = true; 130 this.setTooltip(this.tooltipUnSync); 131 } 132 }, 133 134 /** 135 * Method: unregisterSync 136 * 137 * @private 138 */ 139 unregisterSync: function(){ 140 if (this.syncActive){ 141 this.map1.events.unregister("moveend",this,this.syncMap2); 142 this.map2.events.unregister("moveend",this,this.syncMap1); 143 this.map1.events.unregister("zoomend",this,this.syncMap2); 144 this.map2.events.unregister("zoomend",this,this.syncMap1); 145 this.syncActive = false; 146 this.setTooltip(this.tooltipSync); 147 } 148 149 }, 150 151 /** 152 * Method: syncMap2 153 * 154 * @private 155 */ 156 syncMap2: function(e){ 157 this.unregisterSync(); 158 159 // per trasformazione coordinate in UTM 32N 160 Proj4js.defs["EPSG:32632"]="+title=UTM 32N +proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "; 161 new Proj4js.Proj('EPSG:32632'); 162 163 var fromProjection = this.map1.getProjectionObject(); 164 var toProjection = this.map2.getProjectionObject(); 165 166 var center = new OpenLayers.LonLat(this.map1.getCenter().lon, this.map1.getCenter().lat).transform(fromProjection, toProjection); 167 168 this.map2.setCenter(center) 169 this.map2.zoomToScale(this.map1.getScale()); 170 171 this.registerSync(); 172 }, 173 174 /** 175 * Method: syncMap1 176 * 177 * @private 178 */ 179 syncMap1: function(e){ 180 this.unregisterSync(); 181 182 // per trasformazione coordinate in UTM 32N 183 Proj4js.defs["EPSG:32632"]="+title=UTM 32N +proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "; 184 new Proj4js.Proj('EPSG:32632'); 185 186 var fromProjection = this.map2.getProjectionObject(); 187 var toProjection = this.map1.getProjectionObject(); 188 189 var center = new OpenLayers.LonLat(this.map2.getCenter().lon, this.map2.getCenter().lat).transform(fromProjection, toProjection); 190 191 this.map1.setCenter(center) 192 this.map1.zoomToScale(this.map2.getScale()); 193 194 this.registerSync(); 195 }, 196 197 /** 198 * Method: handler 199 * 200 * @private 201 */ 202 handler:function(){ 203 if (this.pressed){ 204 this.registerSync(); 205 this.removeClass(this.pressedCls); 206 }else{ 207 this.unregisterSync(); 208 this.removeClass('x-btn-pressed'); 209 this.addClass(this.pressedCls); 210 } 211 }, 212 213 /** 214 * Method: setVisible 215 * 216 * @public 217 * @param {Boolean} visible set visibile 218 */ 219 setVisible:function(visible){ 220 this.superclass().setVisible.call(this,visible); 221 222 if (visible && this.pressed){ 223 this.registerSync(); 224 }else{ 225 this.unregisterSync(); 226 } 227 }, 228 229 /** 230 * Method: disableButton 231 * 232 * @public 233 */ 234 disableButton: function() { 235 236 this.unregisterSync(); 237 this.hide(); 238 239 }, 240 241 /** 242 * Method: enableButton 243 * 244 * @public 245 */ 246 enableButton: function() { 247 248 this.registerSync(); 249 this.show(); 250 251 } 252 253 }); 254 255 Ext.reg('framework_togglemapssyncbutton',framework.widgets.doublemap.ToggleMapsSyncButton); 256 257 258 259 260 261 262