| 50 | | //calculate relative position |
|---|
| 51 | | this.relativePosition = this.calculateRelativePosition(px); |
|---|
| | 38 | OpenLayers.Popup.Anchored.prototype.draw.apply(this, arguments); |
|---|
| | 39 | |
|---|
| | 40 | // make the content Div |
|---|
| | 41 | var contentSize = this.size.copyOf(); |
|---|
| | 42 | contentSize.h -= (2 * OpenLayers.Popup.AnchoredBubble.CORNER_SIZE); |
|---|
| | 43 | |
|---|
| | 44 | this.contentDiv = OpenLayers.Util.createDiv( |
|---|
| | 45 | this.div.id + "-contentDiv", |
|---|
| | 46 | null, |
|---|
| | 47 | contentSize, |
|---|
| | 48 | "auto", |
|---|
| | 49 | null, |
|---|
| | 50 | "relative"); |
|---|
| | 51 | |
|---|
| | 52 | this.div.appendChild(this.contentDiv); |
|---|
| | 53 | this.setContentHTML(); |
|---|
| 53 | | return OpenLayers.Popup.prototype.draw.apply(this, arguments); |
|---|
| | 55 | this.setRicoCorners(true); |
|---|
| | 56 | |
|---|
| | 57 | //set the popup color and opacity |
|---|
| | 58 | this.setBackgroundColor(); |
|---|
| | 59 | this.setOpacity(); |
|---|
| | 60 | |
|---|
| | 61 | return this.div; |
|---|
| | 62 | }, |
|---|
| | 63 | |
|---|
| | 64 | /** |
|---|
| | 65 | * @param {OpenLayers.Size} size |
|---|
| | 66 | */ |
|---|
| | 67 | setSize:function(size) { |
|---|
| | 68 | OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments); |
|---|
| | 69 | |
|---|
| | 70 | if (this.contentDiv != null) { |
|---|
| | 71 | |
|---|
| | 72 | var contentSize = this.size.copyOf(); |
|---|
| | 73 | contentSize.h -= (2 * OpenLayers.Popup.AnchoredBubble.CORNER_SIZE); |
|---|
| | 74 | |
|---|
| | 75 | this.contentDiv.style.height = contentSize.h + "px"; |
|---|
| | 76 | |
|---|
| | 77 | //size has changed - must redo corners |
|---|
| | 78 | this.setRicoCorners(false); |
|---|
| | 79 | } |
|---|
| | 80 | }, |
|---|
| | 81 | |
|---|
| | 82 | /** |
|---|
| | 83 | * @param {String} color |
|---|
| | 84 | */ |
|---|
| | 85 | setBackgroundColor:function(color) { |
|---|
| | 86 | if (color != undefined) { |
|---|
| | 87 | this.backgroundColor = color; |
|---|
| | 88 | } |
|---|
| | 89 | |
|---|
| | 90 | if (this.div != null) { |
|---|
| | 91 | if (this.contentDiv != null) { |
|---|
| | 92 | this.div.style.background = "transparent"; |
|---|
| | 93 | Rico.Corner.changeColor(this.contentDiv, this.backgroundColor); |
|---|
| | 94 | } |
|---|
| | 95 | } |
|---|
| | 96 | }, |
|---|
| | 97 | |
|---|
| | 98 | /** |
|---|
| | 99 | * @param {float} opacity |
|---|
| | 100 | */ |
|---|
| | 101 | setOpacity:function(opacity) { |
|---|
| | 102 | if (opacity != undefined) { |
|---|
| | 103 | this.opacity = opacity; |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | if (this.div != null) { |
|---|
| | 107 | if (this.contentDiv != null) { |
|---|
| | 108 | Rico.Corner.changeOpacity(this.contentDiv, this.opacity); |
|---|
| | 109 | } |
|---|
| | 110 | } |
|---|
| | 111 | }, |
|---|
| | 112 | |
|---|
| | 113 | /** Bubble Popups can not have a border |
|---|
| | 114 | * |
|---|
| | 115 | * @param {int} border |
|---|
| | 116 | */ |
|---|
| | 117 | setBorder:function(border) { |
|---|
| | 118 | this.border = 0; |
|---|
| | 119 | }, |
|---|
| | 120 | |
|---|
| | 121 | /** |
|---|
| | 122 | * @param {String} contentHTML |
|---|
| | 123 | */ |
|---|
| | 124 | setContentHTML:function(contentHTML) { |
|---|
| | 125 | if (contentHTML != null) { |
|---|
| | 126 | this.contentHTML = contentHTML; |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | if (this.contentDiv != null) { |
|---|
| | 130 | this.contentDiv.innerHTML = this.contentHTML; |
|---|
| | 131 | } |
|---|
| 57 | | * @param {OpenLayers.Pixel} px |
|---|
| 58 | | * |
|---|
| 59 | | * @returns The relative position ("br" "tr" "tl "bl") at which the popup |
|---|
| 60 | | * should be placed |
|---|
| 61 | | * @type String |
|---|
| 62 | | */ |
|---|
| 63 | | calculateRelativePosition:function(px) { |
|---|
| 64 | | var lonlat = this.map.getLonLatFromLayerPx(px); |
|---|
| 65 | | |
|---|
| 66 | | var extent = this.map.getExtent(); |
|---|
| 67 | | var quadrant = extent.determineQuadrant(lonlat); |
|---|
| 68 | | |
|---|
| 69 | | return this.oppositeQuadrant(quadrant); |
|---|
| 70 | | }, |
|---|
| | 135 | * @private |
|---|
| | 136 | * |
|---|
| | 137 | * @param {Boolean} firstTime Is this the first time the corners are being |
|---|
| | 138 | * rounded? |
|---|
| | 139 | * |
|---|
| | 140 | * update the rico corners according to the popup's |
|---|
| | 141 | * current relative postion |
|---|
| | 142 | */ |
|---|
| | 143 | setRicoCorners:function(firstTime) { |
|---|
| | 144 | |
|---|
| | 145 | var corners = this.getCornersToRound(this.relativePosition); |
|---|
| | 146 | var options = {corners: corners, |
|---|
| | 147 | color: this.backgroundColor, |
|---|
| | 148 | bgColor: "transparent", |
|---|
| | 149 | blend: false}; |
|---|
| 72 | | /** |
|---|
| 73 | | * @param {OpenLayers.Pixel} px |
|---|
| 74 | | */ |
|---|
| 75 | | moveTo: function(px) { |
|---|
| 76 | | |
|---|
| 77 | | var newPx = this.calculateNewPx(px); |
|---|
| 78 | | |
|---|
| 79 | | var newArguments = new Array(newPx); |
|---|
| 80 | | OpenLayers.Popup.prototype.moveTo.apply(this, newArguments); |
|---|
| 81 | | }, |
|---|
| 82 | | |
|---|
| 83 | | /** |
|---|
| 84 | | * @param {OpenLayers.Pixel} px |
|---|
| 85 | | * |
|---|
| 86 | | * @returns The the new px position of the popup on the screen |
|---|
| 87 | | * relative to the passed-in px |
|---|
| 88 | | * @type OpenLayers.Pixel |
|---|
| 89 | | */ |
|---|
| 90 | | calculateNewPx:function(px) { |
|---|
| 91 | | |
|---|
| 92 | | var newPx = px.copyOf(); |
|---|
| 93 | | |
|---|
| 94 | | var top = (this.relativePosition.charAt(0) == 't'); |
|---|
| 95 | | newPx.y += (top) ? -this.size.h : this.anchorSize.h; |
|---|
| 96 | | |
|---|
| 97 | | var left = (this.relativePosition.charAt(1) == 'l'); |
|---|
| 98 | | newPx.x += (left) ? -this.size.w : this.anchorSize.w; |
|---|
| 99 | | |
|---|
| 100 | | return newPx; |
|---|
| | 151 | if (firstTime) { |
|---|
| | 152 | Rico.Corner.round(this.div, options); |
|---|
| | 153 | } else { |
|---|
| | 154 | Rico.Corner.reRound(this.contentDiv, options); |
|---|
| | 155 | //set the popup color and opacity |
|---|
| | 156 | this.setBackgroundColor(); |
|---|
| | 157 | this.setOpacity(); |
|---|
| | 158 | } |
|---|
| 111 | | oppositeQuadrant: function(quadrant) { |
|---|
| 112 | | var opp = ""; |
|---|
| 113 | | |
|---|
| 114 | | opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; |
|---|
| 115 | | opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; |
|---|
| 116 | | |
|---|
| 117 | | return opp; |
|---|
| | 168 | getCornersToRound:function() { |
|---|
| | 169 | |
|---|
| | 170 | var corners = ['tl', 'tr', 'bl', 'br']; |
|---|
| | 171 | |
|---|
| | 172 | //we want to round all the corners _except_ the opposite one. |
|---|
| | 173 | var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition); |
|---|
| | 174 | corners.remove(corner); |
|---|
| | 175 | |
|---|
| | 176 | return corners.join(" "); |
|---|