-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (47 loc) · 1.67 KB
/
script.js
File metadata and controls
54 lines (47 loc) · 1.67 KB
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
const map = L.map('map').setView([47.2313, 39.7233], 11); // Ростов-на-Дону
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap',
}).addTo(map);
let allMarkers = [];
// Загрузка данных
fetch('data.json')
.then(res => res.json())
.then(points => {
renderMarkers(points);
})
.catch(err => console.error('Ошибка загрузки данных:', err));
// Форма добавления
document.getElementById('report-form').addEventListener('submit', function (e) {
e.preventDefault();
const type = document.getElementById('type').value;
const description = document.getElementById('description').value;
const lat = parseFloat(document.getElementById('lat').value);
const lng = parseFloat(document.getElementById('lng').value);
if (type && description && !isNaN(lat) && !isNaN(lng)) {
const marker = L.marker([lat, lng])
.addTo(map)
.bindPopup(`<b>${type}</b><br>${description}`);
allMarkers.push({ marker, type });
document.getElementById('report-form').reset();
}
});
// Рендер маркеров
function renderMarkers(points) {
points.forEach(point => {
const marker = L.marker([point.lat, point.lng])
.addTo(map)
.bindPopup(`<b>${point.type}</b><br>${point.description}`);
allMarkers.push({ marker, type: point.type });
});
}
// Фильтрация
document.getElementById('filter').addEventListener('change', function () {
const selected = this.value;
allMarkers.forEach(({ marker, type }) => {
if (selected === 'Все' || selected === type) {
marker.addTo(map);
} else {
map.removeLayer(marker);
}
});
});