1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, |
7
|
|
|
Conversion, Cookies, Coordinates, Lines, Marker, |
8
|
|
|
id2alpha, mytrans, showAlert, trackMarker |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
var Markers = {}; |
12
|
|
|
Markers.m_map = null; |
13
|
|
|
Markers.m_markers = null; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
Markers.init = function (themap) { |
17
|
|
|
'use strict'; |
18
|
|
|
|
19
|
|
|
this.m_map = themap; |
20
|
|
|
this.m_markers = new Array(26 * 10); |
21
|
|
|
|
22
|
|
|
var id; |
23
|
|
|
for (id = 0; id !== this.m_markers.length; id = id + 1) { |
24
|
|
|
this.m_markers[id] = new Marker(this, id); |
25
|
|
|
} |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
Markers.getSize = function () { |
30
|
|
|
'use strict'; |
31
|
|
|
|
32
|
|
|
return this.m_markers.length; |
33
|
|
|
}; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
Markers.isValid = function (id) { |
37
|
|
|
'use strict'; |
38
|
|
|
|
39
|
|
|
return 0 <= id && id < this.m_markers.length; |
40
|
|
|
}; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
Markers.getById = function (id) { |
44
|
|
|
'use strict'; |
45
|
|
|
|
46
|
|
|
if (id < 0 || id >= this.m_markers.length) { |
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return this.m_markers[id]; |
51
|
|
|
}; |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
Markers.getUsedMarkers = function () { |
55
|
|
|
'use strict'; |
56
|
|
|
|
57
|
|
|
var count = 0; |
58
|
|
|
this.m_markers.map(function (m) { |
59
|
|
|
if (!m.isFree()) { |
60
|
|
|
count = count + 1; |
61
|
|
|
} |
62
|
|
|
}); |
63
|
|
|
return count; |
64
|
|
|
}; |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
Markers.getFreeMarkers = function () { |
68
|
|
|
'use strict'; |
69
|
|
|
|
70
|
|
|
return this.getSize() - this.getUsedMarkers(); |
71
|
|
|
}; |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
Markers.getFreeId = function () { |
75
|
|
|
'use strict'; |
76
|
|
|
|
77
|
|
|
var id; |
78
|
|
|
for (id = 0; id < this.m_markers.length; id = id + 1) { |
79
|
|
|
if (this.m_markers[id].isFree()) { |
80
|
|
|
return id; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
return -1; |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
Markers.getNextUsedId = function (id) { |
88
|
|
|
'use strict'; |
89
|
|
|
|
90
|
|
|
var i; |
91
|
|
|
for (i = id + 1; i < this.m_markers.length; i = i + 1) { |
92
|
|
|
if (!this.m_markers[i].isFree()) { |
93
|
|
|
return i; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
return -1; |
97
|
|
|
}; |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
Markers.removeById = function (id) { |
101
|
|
|
'use strict'; |
102
|
|
|
|
103
|
|
|
if (id >= 0 && id < this.m_markers.length) { |
104
|
|
|
this.m_markers[id].clear(); |
105
|
|
|
} |
106
|
|
|
}; |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
Markers.deleteAll = function () { |
110
|
|
|
'use strict'; |
111
|
|
|
|
112
|
|
|
this.m_markers.map( |
113
|
|
|
function (m) { |
114
|
|
|
m.clear(); |
115
|
|
|
} |
116
|
|
|
); |
117
|
|
|
}; |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
Markers.saveMarkersList = function () { |
121
|
|
|
'use strict'; |
122
|
|
|
|
123
|
|
|
var ids = []; |
124
|
|
|
this.m_markers.map( |
125
|
|
|
function (m) { |
126
|
|
|
if (!m.isFree()) { |
127
|
|
|
ids.push(m.getId()); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
); |
131
|
|
|
Cookies.set('markers', ids.join(":"), {expires: 30}); |
132
|
|
|
}; |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
Markers.toString = function () { |
136
|
|
|
'use strict'; |
137
|
|
|
|
138
|
|
|
var parts = []; |
139
|
|
|
this.m_markers.map( |
140
|
|
|
function (m) { |
141
|
|
|
if (!m.isFree()) { |
142
|
|
|
parts.push(m.toString()); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
); |
146
|
|
|
return parts.join("*"); |
147
|
|
|
}; |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
Markers.update = function () { |
151
|
|
|
'use strict'; |
152
|
|
|
|
153
|
|
|
this.m_markers.map( |
154
|
|
|
function (m) { |
155
|
|
|
m.update(); |
156
|
|
|
} |
157
|
|
|
); |
158
|
|
|
}; |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
Markers.handleMarkerCleared = function () { |
162
|
|
|
'use strict'; |
163
|
|
|
|
164
|
|
|
if (this.getUsedMarkers() === 0) { |
165
|
|
|
$('#btnmarkers2').hide(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
this.saveMarkersList(); |
169
|
|
|
}; |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
Markers.goto = function (id) { |
173
|
|
|
'use strict'; |
174
|
|
|
|
175
|
|
|
trackMarker('goto'); |
176
|
|
|
|
177
|
|
|
var m = this.getById(id); |
178
|
|
|
if (m) { |
179
|
|
|
this.m_map.setCenter(m.getPosition()); |
180
|
|
|
} |
181
|
|
|
}; |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
Markers.center = function (id) { |
185
|
|
|
'use strict'; |
186
|
|
|
|
187
|
|
|
trackMarker('center'); |
188
|
|
|
|
189
|
|
|
var m = this.getById(id); |
190
|
|
|
if (m) { |
191
|
|
|
m.setPosition(this.m_map.getCenter()); |
192
|
|
|
} |
193
|
|
|
}; |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
Markers.newMarker = function (coordinates, id, radius, name) { |
197
|
|
|
'use strict'; |
198
|
|
|
|
199
|
|
|
radius = Math.max(radius, 0); |
200
|
|
|
|
201
|
|
|
if (id < 0 || id >= this.getSize() || !this.getById(id).isFree()) { |
202
|
|
|
id = this.getFreeId(); |
203
|
|
|
} |
204
|
|
|
if (id < 0) { |
205
|
|
|
showAlert( |
206
|
|
|
mytrans("dialog.error"), |
207
|
|
|
mytrans("dialog.toomanymarkers_error.content").replace(/%1/, Markers.getSize()) |
208
|
|
|
); |
209
|
|
|
return null; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
var self = this, |
213
|
|
|
alpha = id2alpha(id), |
214
|
|
|
marker, |
215
|
|
|
div, |
216
|
|
|
nextid; |
217
|
|
|
|
218
|
|
|
if (!name || name === "") { |
219
|
|
|
name = "marker_" + alpha; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
marker = this.getById(id); |
223
|
|
|
marker.initialize(this.m_map, name, coordinates, radius); |
224
|
|
|
div = this.createMarkerDiv(id); |
225
|
|
|
|
226
|
|
|
nextid = this.getNextUsedId(id); |
227
|
|
|
if (nextid < 0) { |
228
|
|
|
$('#dynMarkerDiv').append(div); |
229
|
|
|
} else { |
230
|
|
|
$(div).insertBefore('#dyn' + nextid); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
$('#dyn' + id + ' > .markeredit .edit_name').keydown(function (e) { |
234
|
|
|
if (e.which === 27) { |
235
|
|
|
self.leaveEditMode(id, false); |
236
|
|
|
} else if (e.which === 13) { |
237
|
|
|
self.leaveEditMode(id, true); |
238
|
|
|
} |
239
|
|
|
}); |
240
|
|
|
|
241
|
|
|
$('#edit_coordinates' + alpha).keydown(function (e) { |
242
|
|
|
if (e.which === 27) { |
243
|
|
|
self.leaveEditMode(id, false); |
244
|
|
|
} else if (e.which === 13) { |
245
|
|
|
self.leaveEditMode(id, true); |
246
|
|
|
} |
247
|
|
|
}); |
248
|
|
|
|
249
|
|
|
$('#edit_circle' + alpha).keydown(function (e) { |
250
|
|
|
if (e.which === 27) { |
251
|
|
|
self.leaveEditMode(id, false); |
252
|
|
|
} else if (e.which === 13) { |
253
|
|
|
self.leaveEditMode(id, true); |
254
|
|
|
} |
255
|
|
|
}); |
256
|
|
|
|
257
|
|
|
$('#btnmarkers2').show(); |
258
|
|
|
$('#btnmarkersdelete1').removeAttr('disabled'); |
259
|
|
|
$('#btnmarkersdelete2').removeAttr('disabled'); |
260
|
|
|
|
261
|
|
|
marker.update(); |
262
|
|
|
this.saveMarkersList(); |
263
|
|
|
Lines.updateLinesMarkerAdded(); |
264
|
|
|
|
265
|
|
|
return marker; |
266
|
|
|
}; |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
|
270
|
|
|
|
271
|
|
|
Markers.createMarkerDiv = function (id) { |
272
|
|
|
'use strict'; |
273
|
|
|
|
274
|
|
|
var alpha = id2alpha(id), |
275
|
|
|
iconw = 33, |
276
|
|
|
iconh = 37, |
277
|
|
|
offsetx = (id % 26) * iconw, |
278
|
|
|
offsety = Math.floor(id / 26) * iconh; |
279
|
|
|
|
280
|
|
|
return "<div id=\"dyn" + id + "\">" + |
281
|
|
|
"<table class=\"markerview\" style=\"width: 100%; vertical-align: middle;\">\n" + |
282
|
|
|
" <tr>\n" + |
283
|
|
|
" <td rowspan=\"3\" style=\"vertical-align: top\">\n" + |
284
|
|
|
" <span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\"> </span>\n" + |
285
|
|
|
" </td>\n" + |
286
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-map-marker\"></i></td>\n" + |
287
|
|
|
" <td id=\"view_name" + alpha + "\" colspan=\"2\">marker</td>\n" + |
288
|
|
|
" </tr>\n" + |
289
|
|
|
" <tr>\n" + |
290
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-globe\"></i></td>\n" + |
291
|
|
|
" <td id=\"view_coordinates" + alpha + "\" colspan=\"2\">N 48° 00.123 E 007° 51.456</td>\n" + |
292
|
|
|
" </tr>\n" + |
293
|
|
|
" <tr>\n" + |
294
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-circle-o\"></i></td>\n" + |
295
|
|
|
" <td id=\"view_circle" + alpha + "\">16100 m</td>\n" + |
296
|
|
|
" <td>\n" + |
297
|
|
|
" <div class=\"btn-group\" style=\"padding-bottom: 2px; padding-top: 2px; float: right\">\n" + |
298
|
|
|
" <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.edit_marker\" type=\"button\" onclick=\"Marker.enterEditMode(" + id + ");\"><i class=\"fa fa-edit\"></i></button>\n" + |
299
|
|
|
" <button class=\"my-button btn btn-mini btn-danger\" data-i18n=\"[title]sidebar.markers.delete_marker\" type=\"button\" onClick=\"Markers.removeById(" + id + ");\"><i class=\"fa fa-trash-o\"></i></button>\n" + |
300
|
|
|
" <button class=\"my-button btn btn-mini btn-info\" data-i18n=\"[title]sidebar.markers.move_to\" type=\"button\" onClick=\"Markers.goto(" + id + ");\"><i class=\"fa fa-search\"></i></button>\n" + |
301
|
|
|
" <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.center\" type=\"button\" onClick=\"Markers.center(" + id + ");\"><i class=\"fa fa-crosshairs\"></i></button>\n" + |
302
|
|
|
" <button class=\"my-button btn btn-mini btn-success\" data-i18n=\"[title]sidebar.markers.project\" type=\"button\" onClick=\"projectFromMarker(" + id + ");\"><i class=\"fa fa-location-arrow\"></i></button>\n" + |
303
|
|
|
" </div>\n" + |
304
|
|
|
" </td>\n" + |
305
|
|
|
" </tr>\n" + |
306
|
|
|
"</table>\n" + |
307
|
|
|
"<table class=\"markeredit\" style=\"display: none; width: 100%; vertical-align: middle;\">\n" + |
308
|
|
|
" <tr>\n" + |
309
|
|
|
" <td rowspan=\"4\" style=\"vertical-align: top\"><span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\"> </span>\n" + |
310
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-map-marker\"></i></td>\n" + |
311
|
|
|
" <td><input data-i18n=\"[title]sidebar.markers.name;[placeholder]sidebar.markers.name_placeholder\" class=\"edit_name form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
312
|
|
|
" </tr>\n" + |
313
|
|
|
" <tr>\n" + |
314
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-globe\"></i></td>\n" + |
315
|
|
|
" <td><input id=\"edit_coordinates" + alpha + "\" data-i18n=\"[title]sidebar.markers.coordinates;[placeholder]sidebar.markers.coordinates_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
316
|
|
|
" </tr>\n" + |
317
|
|
|
" <tr>\n" + |
318
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-circle-blank\"></i></td>\n" + |
319
|
|
|
" <td><input id=\"edit_circle" + alpha + "\" data-i18n=\"[title]sidebar.markers.radius;[placeholder]sidebar.markers.radius_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
320
|
|
|
" </tr>\n" + |
321
|
|
|
" <tr>\n" + |
322
|
|
|
" <td colspan=\"2\" style=\"text-align: right\">\n" + |
323
|
|
|
" <button class=\"btn btn-small btn-primary\" type=\"button\" onclick=\"Markers.leaveEditMode(" + id + ", true);\" data-i18n=\"dialog.ok\">OK</button>\n" + |
324
|
|
|
" <button class=\"btn btn-small\" type=\"button\" onclick=\"Marker.leaveEditMode(" + id + ", false);\" data-i18n=\"dialog.cancel\">CANCEL</button>\n" + |
325
|
|
|
" </td>\n" + |
326
|
|
|
" </tr>\n" + |
327
|
|
|
"</table>" + |
328
|
|
|
"</div>"; |
329
|
|
|
}; |
330
|
|
|
|
331
|
|
|
|
332
|
|
|
Markers.enterEditMode = function (id) { |
333
|
|
|
'use strict'; |
334
|
|
|
|
335
|
|
|
trackMarker('edit'); |
336
|
|
|
var m = this.getById(id); |
337
|
|
|
if (!m) { |
338
|
|
|
return; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
$('#dyn' + id + ' > .markeredit .edit_name').val(m.getName()); |
342
|
|
|
$('#edit_coordinates' + m.getAlpha()).val(Coordinates.toString(m.getPosition())); |
343
|
|
|
$('#edit_circle' + m.getAlpha()).val(m.getRadius()); |
344
|
|
|
|
345
|
|
|
$('#dyn' + id + ' > .markerview').hide(); |
346
|
|
|
$('#dyn' + id + ' > .markeredit').show(); |
347
|
|
|
}; |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
Markers.leaveEditMode = function (id, takenew) { |
351
|
|
|
'use strict'; |
352
|
|
|
|
353
|
|
|
if (!this.isValid(id)) { |
354
|
|
|
return; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
if (takenew) { |
358
|
|
|
var m = this.getById(id), |
359
|
|
|
name = $('#dyn' + id + ' > .markeredit .edit_name').val(), |
360
|
|
|
name_ok = /^([a-zA-Z0-9-_]*)$/.test(name), |
361
|
|
|
s_coordinates = $('#edit_coordinates' + m.getAlpha()).val(), |
362
|
|
|
coordinates = Coordinates.fromString(s_coordinates), |
363
|
|
|
s_radius = $('#edit_circle' + m.getAlpha()).val(), |
364
|
|
|
radius = Conversion.getInteger(s_radius, 0, 100000000000), |
365
|
|
|
errors = []; |
366
|
|
|
|
367
|
|
|
if (!name_ok) { |
368
|
|
|
errors.push(mytrans("sidebar.markers.error_badname").replace(/%1/, name)); |
369
|
|
|
} |
370
|
|
|
if (!coordinates) { |
371
|
|
|
errors.push(mytrans("sidebar.markers.error_badcoordinates").replace(/%1/, s_coordinates)); |
372
|
|
|
} |
373
|
|
|
if (radius === null) { |
374
|
|
|
errors.push(mytrans("sidebar.markers.error_badradius").replace(/%1/, s_radius)); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
if (errors.length > 0) { |
378
|
|
|
showAlert(mytrans("dialog.error"), errors.join("<br /><br />")); |
379
|
|
|
} else { |
380
|
|
|
m.setNamePositionRadius(name, coordinates, radius); |
381
|
|
|
$('#dyn' + id + ' > .markerview').show(); |
382
|
|
|
$('#dyn' + id + ' > .markeredit').hide(); |
383
|
|
|
} |
384
|
|
|
} else { |
385
|
|
|
$('#dyn' + id + ' > .markerview').show(); |
386
|
|
|
$('#dyn' + id + ' > .markeredit').hide(); |
387
|
|
|
} |
388
|
|
|
}; |
389
|
|
|
|