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 * @requires plugins/Tool.js 12 * @require OpenLayers/Control/ZoomBox.js 13 * @require GeoExt/widgets/Action.js 14 * @require framework/widgets/control/InfoPoint.js 15 */ 16 17 /** 18 * @namespace framework.plugins 19 */ 20 Ext.namespace("framework.plugins"); 21 22 /** 23 * Class Popup with offset position manager. When the feature image has offset position the popup 24 * position will be recalculate to be centred on the feature image. 25 * @name_ PopUp 26 * @class Popup with offset position manager. 27 * @constructor 28 * @extends <a target="_blank" href="http://geoext.org/lib/GeoExt/widgets/Popup.html">GeoExt.Popup</a> 29 */ 30 framework.plugins.PopUp = Ext.extend(GeoExt.Popup, 31 /** 32 * @lends framework.plugins.PopUp.prototype 33 */ 34 { 35 36 /** 37 * x offeset position, 38 * @public 39 * @type number 40 */ 41 xOffset: null, 42 43 /** 44 * y offeset position, 45 * @public 46 * @type number 47 */ 48 yOffset: null, 49 50 51 userAuth: null, 52 53 /** 54 * Dati oggetto 55 */ 56 obj: null, 57 58 /** 59 * Inizialize offset position 60 * @private 61 */ 62 initComponent: function() { 63 if(this.location && this.location instanceof OpenLayers.Feature.Vector){ 64 if(this.location.style && this.location.style.graphicYOffset && this.location.style.graphicYOffset !== 0){ 65 this.yOffset = - this.location.style.graphicYOffset/2; 66 }else this.yOffset = 0; 67 this.xOffset = 0; 68 } 69 70 if(this.location.selfRemove && this.location && this.location.layer){ 71 this.layer = this.location.layer; 72 var feature = this.location; 73 this.buttons = [{text: 'Rimuovi punto', 74 handler : function(){ 75 delete feature.layer.map.boundRicerca; 76 feature.layer.removeFeatures(feature); 77 self.popupAddr.close(); 78 self.popupAddr.destroy(); 79 } 80 }]; 81 this.buttonAlign = 'center'; 82 83 } 84 85 if (this.userAuth) { 86 87 if (this.obj && this.userAuth.validFlag) { 88 89 if(this.isPoisExternal){ 90 this.buttons = [{text: 'Importa', 91 handler : function(){ 92 this.fireEvent('insPOI', this); 93 this.buttons[0].disable(); 94 }, 95 scope:this 96 }]; 97 }else{ 98 this.buttons = [{text: 'Modifica', 99 handler : function(){ 100 if (this.userAuth.categoria == "POI") 101 this.fireEvent('modPOI', this); 102 else if (this.userAuth.categoria == "Toponimi") { 103 this.fireEvent('modTOP', this); 104 } 105 }, 106 scope:this 107 }]; 108 } 109 110 this.buttonAlign = 'center'; 111 112 } 113 } 114 115 var win = framework.plugins.PopUp.superclass.initComponent.call(this); 116 }, 117 118 /** 119 * Positions the popup relative to its location 120 * @private 121 */ 122 position: function() { 123 var me = this; 124 if(me._mapMove === true) { 125 me.insideViewport = me.map.getExtent().containsLonLat(me.location); 126 if(me.insideViewport !== me.isVisible()) { 127 me.setVisible(me.insideViewport); 128 } 129 } 130 131 if(me.isVisible()) { 132 var locationPx = me.map.getPixelFromLonLat(me.location), 133 mapBox = Ext.fly(me.map.div).getBox(true), 134 y = locationPx.y + mapBox.y - this.yOffset, 135 x = locationPx.x + mapBox.x - this.xOffset, 136 elSize = me.el.getSize(), 137 ancSize = me.anc.getSize(), 138 ancPos = me.anchorPosition; 139 if (ancPos.indexOf("right") > -1 || locationPx.x > mapBox.width / 2) { 140 // right 141 me.anc.addClass("right"); 142 var ancRight = me.el.getX(true) + elSize.width - 143 me.anc.getX(true) - ancSize.width; 144 x -= elSize.width - ancRight - ancSize.width / 2; 145 } else { 146 // left 147 me.anc.removeClass("right"); 148 var ancX = me.anc.getLeft(true); 149 x -= ancX + ancSize.width / 2; 150 } 151 152 if (ancPos.indexOf("bottom") > -1 || locationPx.y > mapBox.height / 2) { 153 // bottom 154 me.anc.removeClass("top"); 155 y -= elSize.height + ancSize.height; 156 } else { 157 // top 158 me.anc.addClass("top"); 159 y += ancSize.height; // ok 160 } 161 162 // position in the next cycle - otherwise strange shifts can occur. 163 window.setTimeout(function() { 164 me.setPagePosition(x, y); 165 }, 0); 166 } 167 } 168 }); 169 170 Ext.preg(framework.plugins.PopUp.prototype.ptype, framework.plugins.PopUp);