-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
413 lines (371 loc) · 11 KB
/
index.html
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>bands-on-maps</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" type="text/javascript"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/jquery.easy-autocomplete.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/easy-autocomplete.min.css"/>
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet" type="text/css">
<style type="text/css">
* {
margin: 0;
padding: 0;
outline: none;
font-family: inherit;
font-size: inherit;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
font-family: arial, serif;
font-size: 13px;
}
body {
display: flex;
flex-direction: row;
}
aside {
width: 300px;
}
aside section {
margin: 20px 20px 0;
}
aside section header {
font-weight: bold;
margin-bottom: 5px;
}
aside section div.range {
display: flex;
justify-content: space-between;
}
aside section input, aside section textarea {
padding: 5px;
border: 1px solid #aaa;
}
aside section input.range {
width: 125px;
display: inline-block;
}
aside section label {
display: flex;
justify-content: space-between;
align-items: center;
padding: 3px 0;
user-select: none;
cursor: pointer;
}
aside section label:hover {
background: #eee;
}
aside section label span {
margin-right: auto;
}
aside section label div {
border: 2px solid;
width: 12px;
height: 12px;
margin-right: 5px;
display: flex;
justify-content: center;
align-items: center;
}
aside section label b {
font-size: 25px;
line-height: 0;
}
aside section label b:hover {
color: #f00;
}
aside section textarea {
width: 260px;
min-width: 260px;
max-width: 260px;
}
aside section button {
margin-top: 5px;
padding: 5px;
}
#strip {
background: url('/map/img/bg.gif');
width: 100%;
height: 10px;
display: none;
margin-top: 20px;
}
main {
flex: 1 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.visually-hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.leaflet-marker-icon {
border: none;
background: none;
}
.verified {
width: 10px;
height: 10px;
margin-right: 2px;
}
</style>
</head>
<body>
<aside>
<!--
<section>
<header>Диапазон дат</header>
<div class="range">
<input type="date" class="range"><input type="date" class="range">
</div>
</section>
-->
<section>
<header>Список групп</header>
<div id="list">
</div>
</section>
<section>
<header>Добавить</header>
<label for="addition" class="visually-hidden">Названия исполнителей</label>
<input id="addition" placeholder="Названия исполнителей"/>
</section>
<section>
<header>Фильтровать по датам</header>
<label>
<input type="text" name="date-filter" value=""/>
</label>
</section>
<div id="strip"></div>
</aside>
<main>
</main>
<script type="text/javascript">
const map = L.map($('main')[0]).setView([60, 30], 3);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org" target="_blank">OpenStreetMap</a> contributors.'
}).addTo(map);
const $list = $("#list");
const $strip = $("#strip");
let requestsPending = 0;
const markers = {};
const events = [];
const artistsByName = localStorage.list ? JSON.parse(localStorage.list) : {};
const dateFilter = $('input[name="date-filter"]');
let dateRange = localStorage.dateRange ? parseDateRange(localStorage.dateRange) : null;
function parseDateRange() {
const strings = JSON.parse(localStorage.dateRange);
return strings ? {
start: moment(strings.start),
end: moment(strings.end)
} : null;
}
function setDateRange(range) {
dateRange = range;
localStorage.dateRange = JSON.stringify(range ? {
start: range.start.toISOString(),
end: range.end.toISOString()
} : null);
}
dateFilter.daterangepicker({
autoUpdateInput: false,
locale: {
cancelLabel: 'Clear'
}
});
if (dateRange != null) {
dateFilter.val(formatDateRange(dateRange.start, dateRange.end));
}
function formatDateRange(startDate, endDate) {
return startDate.format('YYYY-MM-DD') + ' - ' + endDate.format('YYYY-MM-DD');
}
dateFilter.on('apply.daterangepicker', function (ev, picker) {
$(this).val(formatDateRange(picker.startDate, picker.endDate));
setDateRange({
start: picker.startDate,
end: picker.endDate
});
redrawMarkers();
});
dateFilter.on('cancel.daterangepicker', function () {
$(this).val('');
dateRange = setDateRange(null);
redrawMarkers();
});
const $addition = $("#addition");
$addition.easyAutocomplete({
url: term => "suggestions.php?term=" + encodeURI(term),
getValue: "name",
template: {
type: "custom",
method: (term, item) => (item.icon != null ? `<img src='${item.icon}' alt="" class="verified"/>` : "") + item.name
},
list: {
onChooseEvent: () => push()
}
});
function updateList() {
localStorage.list = JSON.stringify(artistsByName);
}
function check($label) {
const $div = $label.find('div');
const name = $label.find('span').text();
const checked = artistsByName[name].checked;
$div.css({background: checked ? $div.css('borderTopColor') : "transparent"});
if (markers[name]) {
redrawMarkers();
}
}
function addToList(artist) {
const $label = $('<label><div style="border-color: ' + artist.color + ';"></div><span>' + artist.name + '</span><b onmouseup="event.stopPropagation(); remove($(this).parent())">×</b></label>');
$label.off().on('mouseup', function () {
const $this = $(this);
const name = $this.find('span').text();
artistsByName[name].checked = !artistsByName[name].checked;
localStorage.list = JSON.stringify(artistsByName);
check($this);
});
$list.append($label);
if (artist.checked) {
check($label);
}
}
function redrawMarker(artistName, datetime, marker) {
if (!artistsByName[artistName].checked || dateRange != null && !moment(datetime).isBetween(dateRange.start, dateRange.end)) {
marker.getElement().style["display"] = "none";
} else {
marker.getElement().style["display"] = "";
}
}
function redrawMarkers() {
for (const {marker, datetime, artistName} of events) {
redrawMarker(artistName, datetime, marker);
}
}
for (const name of Object.getOwnPropertyNames(artistsByName)) {
const item = artistsByName[name];
addToList(item);
addMarkers(item.name);
}
redrawMarkers();
function randColor() {
let c = "#";
for (let i = 0; i < 6; i++) {
c += Math.floor(Math.random() * 0x10).toString(16);
}
return c;
}
function push() {
const lines = $addition.val().split("\n");
for (const line of lines) {
const name = line.trim();
if (name !== "" && !artistsByName[name]) {
const artist = {
name: name,
color: randColor(),
checked: true
};
artistsByName[name] = artist;
addToList(artist);
addMarkers(name);
}
}
updateList();
$addition.val("");
redrawMarkers();
}
function remove($label) {
const name = $label.find("span").text();
$label.remove();
for (const marker of markers[name]) {
marker.remove();
}
delete markers[name];
delete artistsByName[name];
updateList();
}
function addMarkers(artistName) {
$strip.show();
requestsPending++;
// noinspection JSUnusedGlobalSymbols
$.ajax({
url: "request.php",
data: {
name: artistName
},
success: function (response) {
const responseEvents = JSON.parse(response);
const size = 10;
const markerHtmlStyles = `
background-color: ${artistsByName[artistName].color};
width: ${2 * size}px;
height: ${2 * size}px;
display: block;
left: ${-size}px;
top: ${-size}px;
position: relative;
border-radius: ${size}px ${size}px 0;
transform: rotate(45deg);
border: 1px solid #FFFFFF`;
if (!markers[artistName]) markers[artistName] = [];
for (const event of responseEvents) {
const marker = L.marker([Number(event["lat"]), Number(event["lng"])], {
icon: L.divIcon({
iconAnchor: [0, size * Math.sqrt(2)],
popupAnchor: [0, -size],
html: `<span style="${markerHtmlStyles}" />`
})
}).addTo(map);
marker.bindPopup(`
<b>${event["city"]}</b><br>
${new Date(event["datetime"]).toDateString()}<br>
<a href='${event["url"]}' target='_blank'>${artistName}</a>
`);
redrawMarker(artistName, event["datetime"], marker);
/*
var marker = new google.maps.Marker({
icon: {
path: google.maps.SymbolPath.BACKWARD_CLOSED_ARROW,
fillColor: list[name].color,
strokeOpacity: 0,
fillOpacity: 1,
scale: 3
},
map: map,
visible: list[name].checked,
title: item.city + ", " + item.datetime,
position: {lat: Number(item.lat), lng: Number(item.lng)}
});
*/
markers[artistName].push(marker);
events.push({
marker,
artistName,
datetime: event["datetime"]
});
}
requestsPending--;
if (requestsPending === 0) {
$strip.hide();
}
}
});
}
</script>
</body>
</html>