-
Notifications
You must be signed in to change notification settings - Fork 1
/
elabel.js
153 lines (136 loc) · 4.92 KB
/
elabel.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// ELabel.js
//
// This Javascript is provided by Mike Williams
// Blackpool Community Church Javascript Team
// http://www.commchurch.freeserve.co.uk/
// http://econym.googlepages.com/index.htm
//
// This work is licenced under a Creative Commons Licence
// http://creativecommons.org/licenses/by/2.0/uk/
//
// Version 0.2 the .copy() parameters were wrong
// version 1.0 added .show() .hide() .setContents() .setPoint() .setOpacity() .overlap
// version 1.1 Works with GMarkerManager in v2.67, v2.68, v2.69, v2.70 and v2.71
// version 1.2 Works with GMarkerManager in v2.72, v2.73, v2.74 and v2.75
// version 1.3 add .isHidden()
// version 1.4 permit .hide and .show to be used before addOverlay()
// version 1.5 fix positioning bug while label is hidden
// version 1.6 added .supportsHide()
// version 1.7 fix .supportsHide()
// version 1.8 port for use with Google Maps API v3 (Scott Alexander & Rob Day-Reynolds)
function ELabel(point, html, classname, pixelOffset, percentOpacity, overlap) {
// Mandatory parameters
this.point = point;
this.html = html;
// Optional parameters
this.classname = classname||"";
this.pixelOffset = pixelOffset||new google.maps.Size(0,0);
if (percentOpacity) {
if(percentOpacity<0){percentOpacity=0;}
if(percentOpacity>100){percentOpacity=100;}
}
this.percentOpacity = percentOpacity;
this.overlap=overlap||false;
this.hidden = false;
}
ELabel.prototype = new google.maps.OverlayView();
ELabel.prototype.onAdd = function(map) {
var div = document.createElement("div");
var divName = 'map_label';
div.style.position = "absolute";
div.innerHTML = '<div class="' + this.classname + '" name="' + divName + '">' + this.html + '</div>' ;
this.getPanes().floatShadow.appendChild(div);
this.div_ = div;
if (this.percentOpacity) {
if(typeof(div.style.filter)=='string'){div.style.filter='alpha(opacity:'+this.percentOpacity+')';}
if(typeof(div.style.KHTMLOpacity)=='string'){div.style.KHTMLOpacity=this.percentOpacity/100;}
if(typeof(div.style.MozOpacity)=='string'){div.style.MozOpacity=this.percentOpacity/100;}
if(typeof(div.style.opacity)=='string'){div.style.opacity=this.percentOpacity/100;}
}
// if (this.overlap) {
// var z = google.maps.OverlayView.getZIndex(this.point.lat());
// this.div_.style.zIndex = z;
// }
if (this.hidden) {
this.hide();
}
};
ELabel.prototype.onRemove = function() {
this.div_.parentNode.removeChild(this.div_);
};
ELabel.prototype.copy = function() {
return new ELabel(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
};
ELabel.prototype.draw = function(force) {
var projection = this.getProjection(),
p = projection.fromLatLngToDivPixel(this.point);
var h = parseInt(this.div_.clientHeight);
this.div_.style.left = (p.x + this.pixelOffset.width) + "px";
this.div_.style.top = (p.y +this.pixelOffset.height - h) + "px";
};
ELabel.prototype.show = function() {
if (this.div_) {
this.div_.style.display="";
this.draw();
}
this.hidden = false;
};
ELabel.prototype.hide = function() {
if (this.div_) {
this.div_.style.display="none";
}
this.hidden = true;
};
ELabel.prototype.isHidden = function() {
return this.hidden;
};
ELabel.prototype.supportsHide = function() {
return true;
};
ELabel.prototype.setContents = function(html) {
this.html = html;
this.div_.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
this.draw(true);
};
ELabel.prototype.setPoint = function(point) {
this.point = point;
if (this.overlap) {
var z = google.maps.OverlayView.getZIndex(this.point.lat());
this.div_.style.zIndex = z;
}
this.draw(true);
};
ELabel.prototype.setOpacity = function(percentOpacity) {
if (percentOpacity) {
if(percentOpacity<0){percentOpacity=0;}
if(percentOpacity>100){percentOpacity=100;}
}
this.percentOpacity = percentOpacity;
if (this.percentOpacity) {
if(typeof(this.div_.style.filter)=='string'){this.div_.style.filter='alpha(opacity:'+this.percentOpacity+')';}
if(typeof(this.div_.style.KHTMLOpacity)=='string'){this.div_.style.KHTMLOpacity=this.percentOpacity/100;}
if(typeof(this.div_.style.MozOpacity)=='string'){this.div_.style.MozOpacity=this.percentOpacity/100;}
if(typeof(this.div_.style.opacity)=='string'){this.div_.style.opacity=this.percentOpacity/100;}
}
};
ELabel.prototype.getPoint = function() {
return this.point;
};
ELabel.prototype.U = function() {
return this.point;
};
ELabel.prototype.V = function() {
return this.point;
};
ELabel.prototype.W = function() {
return this.point;
};
ELabel.prototype.X = function() {
return this.point;
};
ELabel.prototype.Y = function() {
return this.point;
};
ELabel.prototype.Z = function() {
return this.point;
};