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.control'); 14 15 /** 16 * Compass control to select an angle for 45° views 17 * 18 * @name_ Compass 19 * @class Ccontrol to select an angle for 45° views 20 * @constructor 21 * @extends <a target="_blank" href="http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.Button">Ext.Button</a> 22 */ 23 framework.widgets.control.ViewDirection = OpenLayers.Class(OpenLayers.Control.Panel, 24 /** 25 * @lends framework.widgets.control.ViewDirection.prototype 26 */ 27 { 28 /** 29 * Constant for modes enum 30 */ 31 //MODES: { COMPASS: {id: 0, name: 'Compass'}, ORTHO: {id: 1, name:'Orthophoto'}}, 32 /** 33 * Current direction id 34 * @private 35 * @type int 36 */ 37 directionId: 0, 38 /** 39 * Mode: can be compass or orthophoto 40 */ 41 mode: null, 42 /** 43 * Start direction. Fixed North (N) 44 * 45 * @public 46 * @type String 47 */ 48 initDirection: 'N', 49 /** 50 * Prefix for element css class 51 * @private 52 * @type String 53 */ 54 classPrefix: null, 55 /** 56 * Initialize the component 57 * @param {Object} options Parameters for object creation 58 * @private 59 */ 60 initialize: function(options) { 61 options.autoActivate = false; 62 //this.mode = this.MODES.COMPASS; 63 this.classPrefix = options.displayClass; 64 //toward north 65 this.directionId = 0; 66 options.displayClass += this.initDirection; 67 this.oldCssClass = options.displayClass; 68 /*options.eventListeners = { 69 'activate': function(evt) { 70 Ext.get(this.id).on('mousedown', this.onClick, this); 71 }, 72 'deactivate': function() { 73 Ext.get(this.id).un('mousedown', this.onClick, this); 74 }};*/ 75 OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); 76 }, 77 /** 78 * Encapsulate the object in an Extjs Element 79 * @return {Ext.Element} ExtJs element 80 * @public 81 */ 82 getElement: function() { 83 return Ext.get(this.id); 84 }, 85 /** 86 * Returns current direction 87 * @return {String} current direction 88 * @public 89 */ 90 getDirection: function() { 91 if (this.initDirection == "N") 92 var dirs = ['N', 'E', 'S', 'W']; 93 else 94 var dirs = ['NE', 'SE', 'SW', 'NW']; 95 return dirs[this.directionId]; 96 }, 97 /** 98 * Setting direction 99 * 100 * @public 101 */ 102 setDirection: function(dir) { 103 if (this.initDirection == "N") 104 var dirs = ['N', 'E', 'S', 'W']; 105 else 106 var dirs = ['NE', 'SE', 'SW', 'NW']; 107 this.directionId = dirs.indexOf(dir); 108 }, 109 /** 110 * Refreshes css class using current direction info 111 * @private 112 */ 113 refreshCssClass: function() { 114 /* var newClass = (this.mode === this.MODES.COMPASS) ? 115 this.classPrefix + this.getDirection() : 116 this.classPrefix + this.mode.name;*/ 117 var newClass = this.classPrefix + this.getDirection(); 118 this.getElement().replaceClass(this.oldCssClass, newClass); 119 this.oldCssClass = newClass; 120 }, 121 /** 122 * Changes mode from compass to orthophoto and back 123 * @public 124 */ 125 switchMode: function() { 126 //this.mode = (this.mode === this.MODES.COMPASS) ? this.MODES.ORTHO : this.MODES.COMPASS; 127 this.refreshCssClass(); 128 }, 129 /** 130 * Rotates compass left 131 * @public 132 */ 133 rotateLeft: function() { 134 if (this.directionId === 0) { 135 this.directionId = 3; 136 } else { 137 this.directionId--; 138 } 139 this.refreshCssClass(); 140 }, 141 /** 142 * Rotates compass right 143 * @public 144 */ 145 rotateRight: function() { 146 if (this.directionId === 3) { 147 this.directionId = 0; 148 } else { 149 this.directionId++; 150 } 151 this.refreshCssClass(); 152 153 }, 154 hide: function() { 155 var newClass = this.classPrefix + 'H'; 156 this.getElement().replaceClass(this.oldCssClass, newClass); 157 this.oldCssClass = newClass; 158 159 }, 160 show: function() { 161 this.refreshCssClass(); 162 } 163 /** 164 * Management of click event 165 * @param {Object} evt event parameters 166 * @private 167 */ 168 /* 169 onClick: function(evt) { 170 if (!Ext.isEmpty(evt)) { 171 var self = this.getElement(); 172 var x = evt.xy[0] - self.getLeft(); 173 var y = evt.xy[1] - self.getTop(); 174 if ((this.mode === this.MODES.COMPASS) && x <= 15) { 175 //rotate left event 176 this.rotateLeft(); 177 this.events.triggerEvent('rotateLeft', this.getDirection()); 178 } else if ((this.mode === this.MODES.COMPASS) && x >= 35) { 179 //rotate right event 180 this.rotateRight(); 181 this.events.triggerEvent('rotateRight', this.getDirection()); 182 } else { 183 //orthophoto 184 this.switchMode(); 185 this.events.triggerEvent('modeSwitched', this.mode); 186 } 187 } 188 evt.preventDefault(); 189 evt.stopPropagation(); 190 }*/ 191 }); 192 193 Ext.reg('framework_viewdirection', framework.widgets.control.ViewDirection); 194 195 196 197 198