1
|
|
|
/*jslint |
2
|
|
|
regexp: true |
3
|
|
|
indent: 4 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/*global |
7
|
|
|
$, google, Markers, id2alpha, Cookies, Coordinates, TxtOverlay |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
function Line(themap, id, source, target) { |
11
|
|
|
'use strict'; |
12
|
|
|
|
13
|
|
|
this.m_map = themap; |
14
|
|
|
this.m_id = id; |
15
|
|
|
this.m_lineMapObject = null; |
16
|
|
|
this.m_source = -1; |
17
|
|
|
this.m_target = -1; |
18
|
|
|
this.m_distanceLabel = null; |
19
|
|
|
|
20
|
|
|
$('#dynLineDiv').append( |
21
|
|
|
"<div id=\"dynLine" + id + "\">" + |
22
|
|
|
"<table style=\"width: 100%\">" + |
23
|
|
|
"<tr>" + |
24
|
|
|
"<td>" + |
25
|
|
|
"<select id=\"dynlinesource" + id + "\" class=\"my-small-select\" data-i18n=\"[title]sidebar.lines.source\" onchange=\"Lines.selectLineSource(" + id + ")\"><option value=\"-1\">?</option></select>" + |
26
|
|
|
" → " + |
27
|
|
|
"<select id=\"dynlinetarget" + id + "\" class=\"my-small-select\" data-i18n=\"[title]sidebar.lines.destination\" onchange=\"Lines.selectLineTarget(" + id + ")\"><option value=\"-1\">?</option></select>" + |
28
|
|
|
"</td>" + |
29
|
|
|
"<td>" + |
30
|
|
|
"<button class=\"my-button btn btn-mini btn-danger\" style=\"float: right\" data-i18n=\"[title]sidebar.lines.delete_line\" type=\"button\" onClick=\"trackLine('delete'); Lines.deleteLine(" + id + ")\"><i class=\"fa fa-trash-o\"></i></button>" + |
31
|
|
|
"<div>" + |
32
|
|
|
"</div>" + |
33
|
|
|
"</td>" + |
34
|
|
|
"</tr>" + |
35
|
|
|
"<tr><td colspan=\"2\"><i class=\"fa fa-arrows-h\"></i> <span id=\"dynlinedist" + id + "\">n/a</span> <i class=\"fa fa-compass\"></i> <span id=\"dynlineangle" + id + "\">n/a</span></td></tr>" + |
36
|
|
|
"</table>" + |
37
|
|
|
"</div>" |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
this.updateLists(); |
41
|
|
|
this.setSource(source); |
42
|
|
|
this.setTarget(target); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
Line.prototype.m_map = null; |
47
|
|
|
Line.prototype.m_id = -1; |
48
|
|
|
Line.prototype.m_lineMapObject = null; |
49
|
|
|
Line.prototype.m_source = -1; |
50
|
|
|
Line.prototype.m_target = -1; |
51
|
|
|
Line.prototype.m_distanceLabel = null; |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
Line.prototype.getId = function () { |
55
|
|
|
'use strict'; |
56
|
|
|
|
57
|
|
|
return this.m_id; |
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
Line.prototype.clearMapObject = function () { |
62
|
|
|
'use strict'; |
63
|
|
|
|
64
|
|
|
if (this.m_lineMapObject) { |
65
|
|
|
this.m_lineMapObject.setMap(null); |
66
|
|
|
this.m_lineMapObject = null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (this.m_distanceLabel) { |
70
|
|
|
this.m_distanceLabel.setMap(null); |
71
|
|
|
this.m_distanceLabel = null; |
72
|
|
|
} |
73
|
|
|
}; |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
Line.prototype.updateMapObject = function (pos1, pos2, center) { |
77
|
|
|
'use strict'; |
78
|
|
|
|
79
|
|
|
if (!this.m_lineMapObject) { |
80
|
|
|
this.m_lineMapObject = new google.maps.Polyline({ |
81
|
|
|
strokeColor: '#ff0000', |
82
|
|
|
strokeWeight: 2, |
83
|
|
|
strokeOpacity: 0.7, |
84
|
|
|
geodesic: true, |
85
|
|
|
icons: [{ |
86
|
|
|
icon: { |
87
|
|
|
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW |
88
|
|
|
}, |
89
|
|
|
repeat: '0' |
90
|
|
|
}] |
91
|
|
|
}); |
92
|
|
|
this.m_lineMapObject.setMap(this.m_map); |
93
|
|
|
this.m_distanceLabel = new TxtOverlay(center, "n/a", "mapDistanceLabel", this.m_map); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
var path = new google.maps.MVCArray(); |
97
|
|
|
path.push(pos1); |
98
|
|
|
path.push(pos2); |
99
|
|
|
this.m_lineMapObject.setPath(path); |
100
|
|
|
|
101
|
|
|
this.m_distanceLabel.setPos(center); |
102
|
|
|
}; |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
Line.prototype.getEndpointsString = function () { |
106
|
|
|
'use strict'; |
107
|
|
|
|
108
|
|
|
return id2alpha(this.m_source) + ":" + id2alpha(this.m_target); |
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
Line.prototype.setSource = function (markerId) { |
113
|
|
|
'use strict'; |
114
|
|
|
|
115
|
|
|
if (markerId !== this.m_source) { |
116
|
|
|
this.m_source = markerId; |
117
|
|
|
this.update(); |
118
|
|
|
$("#dynlinesource" + this.m_id + " > option[value=" + markerId + "]").attr("selected", "selected"); |
119
|
|
|
} |
120
|
|
|
}; |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
Line.prototype.setTarget = function (markerId) { |
124
|
|
|
'use strict'; |
125
|
|
|
|
126
|
|
|
if (markerId !== this.m_target) { |
127
|
|
|
this.m_target = markerId; |
128
|
|
|
this.update(); |
129
|
|
|
$("#dynlinetarget" + this.m_id + " > option[value=" + markerId + "]").attr("selected", "selected"); |
130
|
|
|
} |
131
|
|
|
}; |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
Line.prototype.update = function () { |
135
|
|
|
'use strict'; |
136
|
|
|
|
137
|
|
|
if (this.m_source === -1 || this.m_target === -1) { |
138
|
|
|
this.clearMapObject(); |
139
|
|
|
|
140
|
|
|
$("#dynlinedist" + this.m_id).html("n/a"); |
141
|
|
|
$("#dynlineangle" + this.m_id).html("n/a"); |
142
|
|
|
|
143
|
|
|
return; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
var pos1 = Markers.getById(this.m_source).getPosition(), |
147
|
|
|
pos2 = Markers.getById(this.m_target).getPosition(), |
148
|
|
|
dist_angle = Coordinates.dist_angle_geodesic(pos1, pos2), |
149
|
|
|
centerPos = Coordinates.projection_geodesic(pos1, dist_angle.angle, 0.5 * dist_angle.dist); |
150
|
|
|
|
151
|
|
|
this.updateMapObject(pos1, pos2, centerPos); |
152
|
|
|
|
153
|
|
|
if (dist_angle.dist <= 0) { |
154
|
|
|
this.m_distanceLabel.setText(""); |
155
|
|
|
$("#dynlinedist" + this.m_id).html("0m"); |
156
|
|
|
$("#dynlineangle" + this.m_id).html("n/a"); |
157
|
|
|
} else { |
158
|
|
|
this.m_distanceLabel.setText(dist_angle.dist.toFixed() + "m"); |
159
|
|
|
$("#dynlinedist" + this.m_id).html(dist_angle.dist.toFixed() + "m"); |
160
|
|
|
$("#dynlineangle" + this.m_id).html(dist_angle.angle.toFixed(1) + "°"); |
161
|
|
|
} |
162
|
|
|
}; |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
Line.prototype.updateMarkerMoved = function (markerId) { |
166
|
|
|
'use strict'; |
167
|
|
|
|
168
|
|
|
if (this.m_source === markerId || this.m_target === markerId) { |
169
|
|
|
this.update(); |
170
|
|
|
} |
171
|
|
|
}; |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
Line.prototype.updateMarkerRemoved = function (markerId) { |
175
|
|
|
'use strict'; |
176
|
|
|
|
177
|
|
|
if (this.m_source === markerId) { |
178
|
|
|
this.m_source = -1; |
179
|
|
|
this.clearMapObject(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
if (this.m_target === markerId) { |
183
|
|
|
this.m_target = -1; |
184
|
|
|
this.clearMapObject(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
this.updateLists(); |
188
|
|
|
}; |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
Line.prototype.updateMarkerAdded = function () { |
192
|
|
|
'use strict'; |
193
|
|
|
|
194
|
|
|
this.updateLists(); |
195
|
|
|
}; |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
Line.prototype.updateLists = function () { |
199
|
|
|
'use strict'; |
200
|
|
|
|
201
|
|
|
var source = $('#dynlinesource' + this.m_id), |
202
|
|
|
target = $('#dynlinetarget' + this.m_id), |
203
|
|
|
i, |
204
|
|
|
m; |
205
|
|
|
|
206
|
|
|
source.empty(); |
207
|
|
|
target.empty(); |
208
|
|
|
|
209
|
|
|
source.append('<option value="-1">?</option>'); |
210
|
|
|
target.append('<option value="-1">?</option>'); |
211
|
|
|
|
212
|
|
|
for (i = 0; i < Markers.getSize(); i = i + 1) { |
213
|
|
|
m = Markers.getById(i); |
214
|
|
|
if (!m.isFree()) { |
215
|
|
|
source.append('<option value="' + i + '">' + m.getAlpha() + '</option>'); |
216
|
|
|
target.append('<option value="' + i + '">' + m.getAlpha() + '</option>'); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$("#dynlinesource" + this.m_id + " > option[value=" + this.m_source + "]").attr("selected", "selected"); |
221
|
|
|
$("#dynlinetarget" + this.m_id + " > option[value=" + this.m_target + "]").attr("selected", "selected"); |
222
|
|
|
}; |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
var Lines = {}; |
226
|
|
|
Lines.m_map = null; |
227
|
|
|
Lines.m_nextLineId = 0; |
228
|
|
|
Lines.m_lines = []; |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
Lines.init = function (themap) { |
232
|
|
|
'use strict'; |
233
|
|
|
|
234
|
|
|
Lines.m_map = themap; |
235
|
|
|
Lines.m_nextLineId = 0; |
236
|
|
|
Lines.m_lines = []; |
237
|
|
|
}; |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
Lines.newLine = function (source, target) { |
241
|
|
|
'use strict'; |
242
|
|
|
|
243
|
|
|
var m1 = Markers.getById(source), |
244
|
|
|
m2 = Markers.getById(target); |
245
|
|
|
|
246
|
|
|
if (!m1 || m1.isFree()) { |
247
|
|
|
source= -1; |
248
|
|
|
} |
249
|
|
|
if (!m2 || m2.isFree()) { |
250
|
|
|
target = -1; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
this.m_lines.push(new Line(Lines.m_map, this.m_nextLineId, source, target)); |
254
|
|
|
this.m_nextLineId += 1; |
255
|
|
|
this.saveCookie(); |
256
|
|
|
}; |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
Lines.getLineIndex = function (id) { |
260
|
|
|
'use strict'; |
261
|
|
|
|
262
|
|
|
var index, line; |
263
|
|
|
|
264
|
|
|
for (index = 0; index < this.m_lines.length; index += 1) { |
265
|
|
|
line = this.m_lines[index]; |
266
|
|
|
if (line && line.getId() === id) { |
267
|
|
|
return index; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
return -1; |
272
|
|
|
}; |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
Lines.getLineById = function (id) { |
276
|
|
|
'use strict'; |
277
|
|
|
|
278
|
|
|
var index = this.getLineIndex(id); |
279
|
|
|
if (index < 0) { |
280
|
|
|
return null; |
281
|
|
|
} |
282
|
|
|
return this.m_lines[index]; |
283
|
|
|
}; |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
Lines.getLinesText = function () { |
287
|
|
|
'use strict'; |
288
|
|
|
|
289
|
|
|
var a = []; |
290
|
|
|
this.m_lines.map(function (line) { |
291
|
|
|
if (line) { |
292
|
|
|
a.push(line.getEndpointsString()); |
293
|
|
|
} |
294
|
|
|
}); |
295
|
|
|
return a.join("*"); |
296
|
|
|
}; |
297
|
|
|
|
298
|
|
|
|
299
|
|
|
Lines.saveCookie = function () { |
300
|
|
|
'use strict'; |
301
|
|
|
|
302
|
|
|
Cookies.set("lines", this.getLinesText(), {expires: 30}); |
303
|
|
|
}; |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
Lines.selectLineSourceById = function (id, markerId) { |
307
|
|
|
'use strict'; |
308
|
|
|
|
309
|
|
|
this.getLineById(id).setSource(markerId); |
310
|
|
|
this.saveCookie(); |
311
|
|
|
}; |
312
|
|
|
|
313
|
|
|
|
314
|
|
|
Lines.selectLineSource = function (id) { |
315
|
|
|
'use strict'; |
316
|
|
|
|
317
|
|
|
var markerId = -1, |
318
|
|
|
opt = $("#dynlinesource" + id + " option:selected"); |
319
|
|
|
|
320
|
|
|
if (opt) { |
321
|
|
|
markerId = parseInt(opt.val(), 10); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
this.selectLineSourceById(id, markerId); |
325
|
|
|
}; |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
Lines.selectLineTargetById = function (id, markerId) { |
329
|
|
|
'use strict'; |
330
|
|
|
|
331
|
|
|
this.getLineById(id).setTarget(markerId); |
332
|
|
|
this.saveCookie(); |
333
|
|
|
}; |
334
|
|
|
|
335
|
|
|
|
336
|
|
|
Lines.selectLineTarget = function (id) { |
337
|
|
|
'use strict'; |
338
|
|
|
|
339
|
|
|
var markerId = -1, |
340
|
|
|
opt = $("#dynlinetarget" + id + " option:selected"); |
341
|
|
|
|
342
|
|
|
if (opt) { |
343
|
|
|
markerId = parseInt(opt.val(), 10); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
this.selectLineTargetById(id, markerId); |
347
|
|
|
}; |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
Lines.updateLinesMarkerMoved = function (markerId) { |
351
|
|
|
'use strict'; |
352
|
|
|
|
353
|
|
|
this.m_lines.map(function (line) { |
354
|
|
|
if (line) { |
355
|
|
|
line.updateMarkerMoved(markerId); |
356
|
|
|
} |
357
|
|
|
}); |
358
|
|
|
}; |
359
|
|
|
|
360
|
|
|
|
361
|
|
|
Lines.updateLinesMarkerAdded = function () { |
362
|
|
|
'use strict'; |
363
|
|
|
|
364
|
|
|
this.m_lines.map(function (line) { |
365
|
|
|
if (line) { |
366
|
|
|
line.updateMarkerAdded(); |
367
|
|
|
} |
368
|
|
|
}); |
369
|
|
|
}; |
370
|
|
|
|
371
|
|
|
|
372
|
|
|
Lines.updateLinesMarkerRemoved = function (markerId) { |
373
|
|
|
'use strict'; |
374
|
|
|
|
375
|
|
|
this.m_lines.map(function (line) { |
376
|
|
|
if (line) { |
377
|
|
|
line.updateMarkerRemoved(markerId); |
378
|
|
|
} |
379
|
|
|
}); |
380
|
|
|
this.saveCookie(); |
381
|
|
|
}; |
382
|
|
|
|
383
|
|
|
|
384
|
|
|
Lines.updateLine = function (id) { |
385
|
|
|
'use strict'; |
386
|
|
|
|
387
|
|
|
var index = this.getLineIndex(id); |
388
|
|
|
if (index < 0) { |
389
|
|
|
return; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
this.m_lines[index].update(); |
393
|
|
|
}; |
394
|
|
|
|
395
|
|
|
|
396
|
|
|
Lines.deleteLine = function (id) { |
397
|
|
|
'use strict'; |
398
|
|
|
|
399
|
|
|
$('#dynLine' + id).remove(); |
400
|
|
|
|
401
|
|
|
var index = this.getLineIndex(id); |
402
|
|
|
if (index < 0 || !this.m_lines[index]) { |
403
|
|
|
return; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
this.m_lines[index].clearMapObject(); |
407
|
|
|
this.m_lines[index] = null; |
408
|
|
|
|
409
|
|
|
this.saveCookie(); |
410
|
|
|
}; |
411
|
|
|
|
412
|
|
|
|
413
|
|
|
Lines.deleteAllLines = function () { |
414
|
|
|
'use strict'; |
415
|
|
|
|
416
|
|
|
var self = this; |
417
|
|
|
this.m_lines.map(function (line) { |
418
|
|
|
if (line) { |
419
|
|
|
self.deleteLine(line.getId()); |
420
|
|
|
} |
421
|
|
|
}); |
422
|
|
|
}; |
423
|
|
|
|