-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
117 lines (105 loc) · 3.55 KB
/
main.js
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
const map = new maplibregl.Map({
container: "map", // container id
style:
"https://raw.githubusercontent.com/gtitov/basemaps/master/dark-matter-nolabels.json", // style URL
center: [0, 0], // starting position [lng, lat]
zoom: 1, // starting zoom
});
map.on("load", () => {
fetch("https://docs.google.com/spreadsheets/d/1f0waZduz5CXdNig_WWcJDWWntF-p5gN2-P-CNTLxEa0/export?format=csv")
.then((response) => response.text())
.then((csv) => {
const rows = Papa.parse(csv, { header: true })
// console.log(rows)
const geojsonFeatures = rows.data.map((row) => {
return {
type: "Feature",
properties: row,
geometry: {
type: "Point",
coordinates: [row.lon, row.lat],
}
}
})
const geojson = {
type: "FeatureCollection",
features: geojsonFeatures
}
map.addSource("vacancies", {
type: "geojson",
data: geojson,
cluster: true,
clusterRadius: 20,
});
map.addLayer({
id: "clusters",
source: "vacancies",
type: "circle",
paint: {
"circle-color": "#7EC8E3",
"circle-stroke-width": 1,
"circle-stroke-color": "#FFFFFF",
"circle-radius": [
"step", ["get", "point_count"],
12,
3,
20,
6,
30
],
},
});
map.addLayer({
id: "clusters-labels",
type: "symbol",
source: "vacancies",
layout: {
"text-field": ["get", "point_count"],
"text-size": 10,
},
});
geojson.features.map((f) => {
document.getElementById(
"list-all"
).innerHTML += `<div class="list-item">
<h4>${f.properties["Вакансия"]}</h4>
<a href='#' onclick="map.flyTo({center: [${f.geometry.coordinates}], zoom: 10})">Найти на карте</a>
</div><hr>`;
});
map.on('moveend', () => {
const features = map.queryRenderedFeatures({
layers: ["clusters"]
});
document.getElementById("list-selected").innerHTML = "<h2>Сейчас на карте</h2>"
features.map(f => {
if (f.properties.cluster) {
const clusterId = f.properties.cluster_id;
const pointCount = f.properties.point_count;
map.getSource("vacancies").getClusterLeaves(clusterId, pointCount, 0)
.then((clusterFeatures) => {
clusterFeatures.map((feature) => document.getElementById("list-selected")
.innerHTML += `<div class="list-item">
<h4>${feature.properties["Вакансия"]}</h4>
<a target="blank_" href='${feature.properties["Ссылка на сайте Картетики"]}'>Подробнее</a>
</div><hr>`)
});
} else {
document.getElementById("list-selected")
.innerHTML += `<div class="list-item">
<h4>${f.properties["Вакансия"]}</h4>
<a target="blank_" href='${f.properties["Ссылка на сайте Картетики"]}'>Подробнее</a>
</div><hr>`
}
})
})
})
map.on("click", "clusters", function (e) {
map.flyTo({ center: e.lngLat, zoom: 8 });
})
map.on("mouseenter", "clusters", function () {
map.getCanvas().style.cursor = "pointer";
});
map.on("mouseleave", "clusters", function () {
map.getCanvas().style.cursor = "";
});
});