1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, google, |
7
|
|
|
Cookies, Coordinates, Lines, |
8
|
|
|
id2alpha |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
function Marker(parent, id) { |
12
|
|
|
'use strict'; |
13
|
|
|
|
14
|
|
|
this.m_parent = parent; |
15
|
|
|
this.m_id = id; |
16
|
|
|
this.m_alpha = id2alpha(id); |
17
|
|
|
this.m_free = true; |
18
|
|
|
this.m_name = ""; |
19
|
|
|
this.m_marker = null; |
20
|
|
|
this.m_circle = null; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
Marker.prototype.toString = function () { |
25
|
|
|
'use strict'; |
26
|
|
|
|
27
|
|
|
return this.getAlpha() + ":" + this.getPosition().lat().toFixed(6) + ":" + this.getPosition().lng().toFixed(6) + ":" + this.getRadius() + ":" + this.getName(); |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
Marker.prototype.isFree = function () { |
32
|
|
|
'use strict'; |
33
|
|
|
|
34
|
|
|
return this.m_free; |
35
|
|
|
}; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
Marker.prototype.clear = function () { |
39
|
|
|
'use strict'; |
40
|
|
|
|
41
|
|
|
if (this.m_free) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
this.m_free = true; |
46
|
|
|
this.m_marker.setMap(null); |
47
|
|
|
this.m_marker = null; |
48
|
|
|
this.m_circle.setMap(null); |
49
|
|
|
this.m_circle = null; |
50
|
|
|
|
51
|
|
|
$('#dyn' + this.m_id).remove(); |
52
|
|
|
|
53
|
|
|
Lines.updateLinesMarkerRemoved(this.m_id); |
54
|
|
|
this.m_parent.handleMarkerCleared(); |
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
Marker.prototype.getId = function () { |
59
|
|
|
'use strict'; |
60
|
|
|
|
61
|
|
|
return this.m_id; |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
Marker.prototype.getAlpha = function () { |
66
|
|
|
'use strict'; |
67
|
|
|
|
68
|
|
|
return this.m_alpha; |
69
|
|
|
}; |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
Marker.prototype.getName = function () { |
73
|
|
|
'use strict'; |
74
|
|
|
|
75
|
|
|
return this.m_name; |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
Marker.prototype.setName = function (name) { |
80
|
|
|
'use strict'; |
81
|
|
|
|
82
|
|
|
this.m_name = name; |
83
|
|
|
this.update(); |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
Marker.prototype.setPosition = function (position) { |
88
|
|
|
'use strict'; |
89
|
|
|
|
90
|
|
|
this.m_marker.setPosition(position); |
91
|
|
|
this.m_circle.setCenter(position); |
92
|
|
|
this.update(); |
93
|
|
|
}; |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
Marker.prototype.getPosition = function () { |
97
|
|
|
'use strict'; |
98
|
|
|
|
99
|
|
|
return this.m_marker.getPosition(); |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
Marker.prototype.setRadius = function (radius) { |
104
|
|
|
'use strict'; |
105
|
|
|
|
106
|
|
|
this.m_circle.setRadius(radius); |
107
|
|
|
this.update(); |
108
|
|
|
}; |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
Marker.prototype.getRadius = function () { |
112
|
|
|
'use strict'; |
113
|
|
|
|
114
|
|
|
return this.m_circle.getRadius(); |
115
|
|
|
}; |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
Marker.prototype.setNamePositionRadius = function (name, position, radius) { |
119
|
|
|
'use strict'; |
120
|
|
|
|
121
|
|
|
this.m_name = name; |
122
|
|
|
this.m_marker.setPosition(position); |
123
|
|
|
this.m_circle.setCenter(position); |
124
|
|
|
this.m_circle.setRadius(radius); |
125
|
|
|
this.update(); |
126
|
|
|
}; |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
Marker.prototype.initialize = function (map, name, position, radius) { |
130
|
|
|
'use strict'; |
131
|
|
|
|
132
|
|
|
this.m_free = false; |
133
|
|
|
this.m_name = name; |
134
|
|
|
|
135
|
|
|
// marker.png is 26x10 icons (each: 33px x 37px) |
136
|
|
|
var self = this, |
137
|
|
|
iconw = 33, |
138
|
|
|
iconh = 37, |
139
|
|
|
offsetx = (this.m_id % 26) * iconw, |
140
|
|
|
offsety = Math.floor(this.m_id / 26) * iconh, |
141
|
|
|
color = "#0090ff"; |
142
|
|
|
|
143
|
|
|
this.m_marker = new google.maps.Marker({ |
144
|
|
|
position: position, |
145
|
|
|
map: map, |
146
|
|
|
icon: new google.maps.MarkerImage( |
147
|
|
|
"img/markers.png", |
148
|
|
|
new google.maps.Size(iconw, iconh), |
149
|
|
|
new google.maps.Point(offsetx, offsety), |
150
|
|
|
new google.maps.Point(0.5 * iconw, iconh - 1) |
151
|
|
|
), |
152
|
|
|
draggable: true |
153
|
|
|
}); |
154
|
|
|
|
155
|
|
|
google.maps.event.addListener(this.m_marker, "drag", function () { self.update(); }); |
156
|
|
|
google.maps.event.addListener(this.m_marker, "dragend", function () { self.update(); }); |
157
|
|
|
|
158
|
|
|
this.m_circle = new google.maps.Circle({ |
159
|
|
|
center: position, |
160
|
|
|
map: map, |
161
|
|
|
strokeColor: color, |
162
|
|
|
strokeOpacity: 1, |
163
|
|
|
fillColor: color, |
164
|
|
|
fillOpacity: 0.25, |
165
|
|
|
strokeWeight: 1, |
166
|
|
|
radius: radius |
167
|
|
|
}); |
168
|
|
|
}; |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
Marker.prototype.update = function () { |
172
|
|
|
'use strict'; |
173
|
|
|
|
174
|
|
|
if (this.m_free) { |
175
|
|
|
return; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
var pos = this.m_marker.getPosition(), |
179
|
|
|
radius = this.m_circle.getRadius(); |
180
|
|
|
|
181
|
|
|
this.m_circle.setCenter(pos); |
182
|
|
|
|
183
|
|
|
Cookies.set('marker' + this.m_id, pos.lat().toFixed(6) + ":" + pos.lng().toFixed(6) + ":" + radius + ":" + this.m_name, {expires: 30}); |
184
|
|
|
$('#view_name' + this.m_alpha).html(this.m_name); |
185
|
|
|
$('#view_coordinates' + this.m_alpha).html(Coordinates.toString(pos)); |
186
|
|
|
$('#view_circle' + this.m_alpha).html(radius); |
187
|
|
|
$('#edit_name' + this.m_alpha).val(this.m_name); |
188
|
|
|
$('#edit_coordinates' + this.m_alpha).val(Coordinates.toString(pos)); |
189
|
|
|
$('#edit_circle' + this.m_alpha).val(radius); |
190
|
|
|
|
191
|
|
|
Lines.updateLinesMarkerMoved(this.m_id); |
192
|
|
|
}; |
193
|
|
|
|