-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
124 lines (98 loc) · 3.9 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
// Mapbox-Account with Access-Token // mapbox-static
mapboxgl.accessToken = 'pk.eyJ1Ijoid2VidWlsZGNpdHkiLCJhIjoiY2ptdDlybmQzMG45ZzNwcDhvMmFqaWNraiJ9.-ywTD0VURed2camLe6eoMA';
// Basis-"Map"-Einstellungen von Mapbox...https://www.mapbox.com/mapbox-gl-js/api/#map
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/webuildcity/cjc6ix9zw4sc42smsom3lew8a',
// style: 'mapbox://styles/mapbox/satellite-v9',
center: [9.9899031, 53.5790631], // Inital Position
zoom: 11.5, // initial zoom level
maxZoom: 14.5, // maximales "reinzoomen"
minZoom: 9.3, // maximales "rauszoomen"
interactive: true, // if false, kein scrollen möglich
logoPosition: 'bottom-left', // Position des Mapbox Logos, default 'bottom-left'
keyboard: true, // if false, kann nicht mehr mit den Tastatur-Pfeilen navigiert werden
hash: true,
});
/* CONTROLS SETTINGS */
// Add zoom, compass and rotation controls to the map.
var nav = new mapboxgl.NavigationControl({
showCompass: true,
showZoom: true
});
map.addControl(nav, "top-right"); // oder top-left , top-right , bottom-left , bottom-right
// Deaktiviert den Scroll-Zoom per Mouse, options: if 'disable', else 'enable'
map.scrollZoom.enable();
// Deaktiviert disable map rotation using right click + drag, if 'disable'
map.dragRotate.disable();
// Deaktiviert mit 'disable' das verschieben des Kartenausschnitts per by clicking and dragging the cursor
map.dragPan.enable();
// disable map rotation using touch rotation gesture, if 'disableRotation'
map.touchZoomRotate.enableRotation();
/* End of Control Settings */
/* Daten, Points, Polygone */
// lade Daten aus externer file, z.B. data.geojson
map.on("load", function() {
map.addSource("hamburg", {
"type": "geojson",
"data": 'data/data.geojson'
})
// Layer for Points
// More Icons here: https://www.mapbox.com/maki-icons/
map.addLayer({
"id": "alster-points",
"interactive": true,
// "type": "circle",
"type": "symbol",
"source": "hamburg",
"layout": {
"icon-image": "garden-15",
"icon-size": 3.25,
"icon-allow-overlap": true
},
// "paint": {
// "circle-radius": 12, // Marker size
// "circle-color": "yellow" // Marker color
// },
"filter": ["==", "$type", "Point"],
});
// Layer for Polygons
map.addLayer({
"id": "stadtpark-poly",
"type": "fill",
"source": "hamburg",
"paint": {
"fill-color": "yellow",
"fill-opacity": 0.6
},
"filter": ["==", "$type", "Polygon"]
});
// When a click event occurs on a feature in the places layer, open a popup at the
// location of the feature, with description HTML from its properties.
map.on('click', 'alster-points', function (e) {
var coordinates = e.features[0].geometry.coordinates.slice();
var name = e.features[0].properties.name;
var description = e.features[0].properties.description;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(
'<h1>' + name + '</h1>' +
'<p>' + description + '</p>'
)
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the places layer.
map.on('mouseenter', 'alster-points', function () {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'alster-points', function () {
map.getCanvas().style.cursor = '';
});
});