-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (63 loc) · 2.22 KB
/
index.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
map.addControl(new MapboxGeocoder({
accessToken: mapboxgl.accessToken
}));
var popup = new mapboxgl.Popup({
closeButton: false
});
map.on('load', function() {
$.getJSON("osm_lines.json", function(osm_lines) {
var source_name = Object.keys(osm_lines["sources"]);
console.log(source_name);
if (typeof(source_name) == "string") {
var source_detail = osm_lines["sources"][source_name];
map.addSource(source_name, source_detail);
} else {
for (i in source_name) {
name = source_name[i];
var source_detail = osm_lines["sources"][name];
map.addSource(name, source_detail);
}
}
for (i in osm_lines["layers"]) {
map.addLayer(osm_lines["layers"][i]);
}
});
map.on('mousemove', 'captain_train', function(e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
// Single out the first found feature.
var feature = e.features[0];
// Display a popup with the name
popup.setLngLat(e.lngLat)
.setText(feature.properties.name)
.addTo(map);
});
map.on('mousemove', 'other_lines', function(e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
// Single out the first found feature.
var feature = e.features[0];
// Display a popup with the name
popup.setLngLat(e.lngLat)
.setText(feature.properties.name)
.addTo(map);
});
});
map.on('render', function(e) {
if (map.loaded()) {
var lines_list = document.getElementById('map-overlay');
lines_list.innerHTML = "Liste des lignes <br>";
all_other_lines = map.queryRenderedFeatures({
layers: ['other_lines']
});
all_other_lines_names = all_other_lines.map(function(x) {
return x.properties.name;
})
var dedup = all_other_lines_names.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
});
for (i in dedup.sort()) {
lines_list.innerHTML += dedup[i] + "<br>";
}
}
});