]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Popup/Anchored.js
Disabled edit tab until z13 is reached.
[rails.git] / public / lib / OpenLayers / Popup / Anchored.js
1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3  * text of the license. */
4 // @require: OpenLayers/Popup.js\r
5 \r
6 /**\r
7 * @class\r
8 */\r
9 OpenLayers.Popup.Anchored = Class.create();\r
10 OpenLayers.Popup.Anchored.prototype =\r
11    Object.extend( new OpenLayers.Popup(), {\r
12 \r
13     /** "lr", "ll", "tr", "tl" - relative position of the popup.\r
14      * @type String */\r
15     relativePosition: null,\r
16 \r
17     /** Object which must have expose a 'size' (OpenLayers.Size) and \r
18      *                                 'offset' (OpenLayers.Pixel) \r
19      * @type Object */\r
20     anchor: null,\r
21 \r
22     /** \r
23     * @constructor\r
24     * \r
25     * @param {String} id\r
26     * @param {OpenLayers.LonLat} lonlat\r
27     * @param {OpenLayers.Size} size\r
28     * @param {String} contentHTML\r
29     * @param {Object} anchor  Object which must expose a \r
30     *                         - 'size' (OpenLayers.Size) and \r
31     *                         - 'offset' (OpenLayers.Pixel) \r
32     *                         (this is generally an OpenLayers.Icon)\r
33     */\r
34     initialize:function(id, lonlat, size, contentHTML, anchor) {\r
35         var newArguments = new Array(id, lonlat, size, contentHTML);\r
36         OpenLayers.Popup.prototype.initialize.apply(this, newArguments);\r
37 \r
38         this.anchor = (anchor != null) ? anchor \r
39                                        : { size: new OpenLayers.Size(0,0),\r
40                                            offset: new OpenLayers.Pixel(0,0)};\r
41     },\r
42 \r
43     /** \r
44     * @param {OpenLayers.Pixel} px\r
45     * \r
46     * @returns Reference to a div that contains the drawn popup\r
47     * @type DOMElement\r
48     */\r
49     draw: function(px) {\r
50         if (px == null) {\r
51             if ((this.lonlat != null) && (this.map != null)) {\r
52                 px = this.map.getLayerPxFromLonLat(this.lonlat);\r
53             }\r
54         }\r
55         \r
56         //calculate relative position\r
57         this.relativePosition = this.calculateRelativePosition(px);\r
58         \r
59         return OpenLayers.Popup.prototype.draw.apply(this, arguments);\r
60     },\r
61     \r
62     /** \r
63      * @private\r
64      * \r
65      * @param {OpenLayers.Pixel} px\r
66      * \r
67      * @returns The relative position ("br" "tr" "tl "bl") at which the popup\r
68      *           should be placed\r
69      * @type String\r
70      */\r
71     calculateRelativePosition:function(px) {\r
72         var lonlat = this.map.getLonLatFromLayerPx(px);        \r
73         \r
74         var extent = this.map.getExtent();\r
75         var quadrant = extent.determineQuadrant(lonlat);\r
76         \r
77         return OpenLayers.Bounds.oppositeQuadrant(quadrant);\r
78     }, \r
79 \r
80     /**\r
81     * @param {OpenLayers.Pixel} px\r
82     */\r
83     moveTo: function(px) {\r
84         \r
85         var newPx = this.calculateNewPx(px);\r
86         \r
87         var newArguments = new Array(newPx);        \r
88         OpenLayers.Popup.prototype.moveTo.apply(this, newArguments);\r
89     },\r
90     \r
91     /**\r
92     * @param {OpenLayers.Size} size\r
93     */\r
94     setSize:function(size) { \r
95         OpenLayers.Popup.prototype.setSize.apply(this, arguments);\r
96 \r
97         if ((this.lonlat) && (this.map)) {\r
98             var px = this.map.getLayerPxFromLonLat(this.lonlat);\r
99             this.moveTo(px);\r
100         }\r
101     },  \r
102     \r
103     /** \r
104      * @private \r
105      * \r
106      * @param {OpenLayers.Pixel} px\r
107      * \r
108      * @returns The the new px position of the popup on the screen\r
109      *           relative to the passed-in px\r
110      * @type OpenLayers.Pixel\r
111      */\r
112     calculateNewPx:function(px) {\r
113         var newPx = px.offset(this.anchor.offset);\r
114 \r
115         var top = (this.relativePosition.charAt(0) == 't');\r
116         newPx.y += (top) ? -this.size.h : this.anchor.size.h;\r
117         \r
118         var left = (this.relativePosition.charAt(1) == 'l');\r
119         newPx.x += (left) ? -this.size.w : this.anchor.size.w;\r
120 \r
121         return newPx;   \r
122     },\r
123 \r
124     CLASS_NAME: "OpenLayers.Popup.Anchored"\r
125 });\r