]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Marker/Box.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Marker / Box.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3  * full text of the license. */
4
5
6 /**
7  * @requires OpenLayers/Marker.js
8  */
9
10 /**
11  * Class: OpenLayers.Marker.Box
12  *
13  * Inherits from:
14  *  - <OpenLayers.Marker> 
15  */
16 OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, {
17
18     /** 
19      * Property: bounds 
20      * {<OpenLayers.Bounds>} 
21      */
22     bounds: null,
23
24     /** 
25      * Property: div 
26      * {DOMElement} 
27      */
28     div: null,
29     
30     /** 
31      * Constructor: OpenLayers.Marker.Box
32      *
33      * Parameters:
34      * bounds - {<OpenLayers.Bounds>} 
35      * borderColor - {String} 
36      * borderWidth - {int} 
37      */
38     initialize: function(bounds, borderColor, borderWidth) {
39         this.bounds = bounds;
40         this.div    = OpenLayers.Util.createDiv();
41         this.div.style.overflow = 'hidden';
42         this.events = new OpenLayers.Events(this, this.div, null);
43         this.setBorder(borderColor, borderWidth);
44     },
45
46     /**
47      * Method: destroy 
48      */    
49     destroy: function() {
50
51         this.bounds = null;
52         this.div = null;
53
54         OpenLayers.Marker.prototype.destroy.apply(this, arguments);
55     },
56
57     /** 
58      * Method: setBorder
59      * Allow the user to change the box's color and border width
60      * 
61      * Parameters:
62      * color - {String} Default is "red"
63      * width - {int} Default is 2
64      */
65     setBorder: function (color, width) {
66         if (!color) {
67             color = "red";
68         }
69         if (!width) {
70             width = 2;
71         }
72         this.div.style.border = width + "px solid " + color;
73     },
74     
75     /** 
76     * Method: draw
77     * 
78     * Parameters:
79     * px - {<OpenLayers.Pixel>} 
80     * sz - {<OpenLayers.Size>} 
81     * 
82     * Returns: 
83     * {DOMElement} A new DOM Image with this markerĀ“s icon set at the 
84     *         location passed-in
85     */
86     draw: function(px, sz) {
87         OpenLayers.Util.modifyDOMElement(this.div, null, px, sz);
88         return this.div;
89     }, 
90
91     /**
92      * Method: onScreen
93      * 
94      * Rreturn:
95      * {Boolean} Whether or not the marker is currently visible on screen.
96      */
97     onScreen:function() {
98         var onScreen = false;
99         if (this.map) {
100             var screenBounds = this.map.getExtent();
101             onScreen = screenBounds.containsBounds(this.bounds, true, true);
102         }    
103         return onScreen;
104     },
105     
106     /**
107      * Method: display
108      * Hide or show the icon
109      * 
110      * Parameters:
111      * display - {Boolean} 
112      */
113     display: function(display) {
114         this.div.style.display = (display) ? "" : "none";
115     },
116
117     CLASS_NAME: "OpenLayers.Marker.Box"
118 });
119