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