-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
173 lines (149 loc) · 3.65 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
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
const map = new maplibregl.Map({
container: 'map',
center: [36.36563, 55.21050], // starting position [lng, lat]
zoom: 12, // starting zoom
minZoom: 10,
maxZoom: 20,
maxBounds: [
[36.29, 55.178], // westSouth coordinates
[36.44, 55.24] // eastNorth coordinates
],
style: "./cybersatino.json"
});
// Popups
map.getCanvas().style.cursor = 'pointer';
layers = ['landUse', 'waterLines', 'waterPolygons', 'contours', 'roadsBlur', 'stars-blur1']
map.on('click', (e) => {
const coordinates = e.lngLat
let description = "";
const bbox = [
[e.point.x - 2, e.point.y - 2],
[e.point.x + 2, e.point.y + 2]
];
// TODO: create rectangle representing the bbox on click and hide it after 2sec https://github.com/mapbox/mapbox-gl-js/issues/9209
const features = map.queryRenderedFeatures(bbox, { layers: layers })
features.forEach(feature => {
console.log(feature)
if (feature.properties.Land_Type) description += feature.properties.Land_Type + "<br>"
if (feature.properties.RiverName) description += feature.properties.RiverName + "<br>"
if (feature.properties.Value_) description += "Горизонталь " + feature.properties.Value_ + " м<br>"
if (feature.sourceLayer == "roads") description += "Дорога<br>"
if (feature.source == "stars") description += "Terra Incognita"
});
new maplibregl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
// Controls
map.addControl(new maplibregl.ScaleControl());
const scalebar = document.getElementsByClassName("maplibregl-ctrl-scale")[0]
scalebar.classList.add("blinking");
map.addControl(new maplibregl.AttributionControl({compact: true,customAttribution: '<a href="https://aentin.github.io/qgis-course/map-design-quaternary.html">Данные</a>, <a href="https://github.com/gtitov/cybersatino">Исходный код</a>, <a href="#">2022</a>'}));
map.addControl(new maplibregl.NavigationControl(), 'bottom-right');
// Background
const stars = {
'type': 'MultiPoint',
'coordinates': [[
36.42036437988281,
55.20023061331437
], [
36.3237190246582,
55.19425406139583
],
[
36.31702423095703,
55.19944685432541
],
[
36.320457458496094,
55.21795903813508
],
[
36.33831024169922,
55.18710061539658
],
[
36.38603210449219,
55.185532565186726
],
[
36.372642517089844,
55.18719861648563
],
[
36.41366958618164,
55.211495444210776
],
[
36.42036437988281,
55.20023061331437
],
[
36.413841247558594,
55.22412785315607
],
[
36.311187744140625,
55.18974656018768
],
[
36.413326263427734,
55.23372188680824
],
[
36.422595977783196,
55.18651260379994
],
[
36.299686431884766,
55.211299561341384
],
[
36.429805755615234,
55.210907792710714
],
[
36.31135940551758,
55.22765246093339
]
]
};
map.on('load', () => {
// Add a source and layer displaying a point which will be animated in a circle.
map.addSource('stars', {
'type': 'geojson',
'data': stars
});
map.addLayer({
'id': 'stars-blur2',
'source': 'stars',
'type': 'circle',
'paint': {
'circle-radius': 10,
'circle-opacity': 0.5,
'circle-blur': 1,
'circle-color': '#FFFF00'
}
});
map.addLayer({
'id': 'stars-blur1',
'source': 'stars',
'type': 'circle',
'paint': {
'circle-radius': 5,
'circle-opacity': 0.5,
'circle-blur': 1,
'circle-color': '#FFFF00'
}
});
map.addLayer({
'id': 'stars-core',
'source': 'stars',
'type': 'circle',
'paint': {
'circle-radius': 2,
'circle-color': '#ffffff'
}
});
})