Skip to content

Commit 8742f27

Browse files
committed
documentation updated 3
1 parent d2c38a5 commit 8742f27

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

public/js/allgarage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
async function getSlotInfo(key) {
22
var xhttp = new XMLHttpRequest();
33
xhttp.onreadystatechange = async function () {
4+
//readyState == 4 means the request is done.
5+
//status == 200 means the request is successful.
46
if (this.readyState == 4 && this.status == 200) {
57
document.getElementById(key).innerHTML = this.responseText;
68
}

public/js/clustermap.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ const map = new mapboxgl.Map({
77
zoom: 3,
88
});
99

10+
// Add zoom and rotation controls to the map.
1011
map.addControl(new mapboxgl.NavigationControl());
1112

1213
map.on('load', function () {
14+
// Add a new source from our GeoJSON data and set the
15+
// 'cluster' option to true. GL-JS will add the point_count property to your source data.
1316
map.addSource('garages', {
1417
type: 'geojson',
1518
data: garages,
@@ -18,11 +21,13 @@ map.on('load', function () {
1821
clusterRadius: 50,
1922
});
2023

24+
// Add a cluster layer. This layer will cluster all point features in the source layer
2125
map.addLayer({
2226
id: 'clusters',
2327
type: 'circle',
2428
source: 'garages',
2529
filter: ['has', 'point_count'],
30+
// cluster style configurations
2631
paint: {
2732
'circle-color': [
2833
'step',
@@ -45,6 +50,7 @@ map.on('load', function () {
4550
},
4651
});
4752

53+
// Add a layer for the clusters' count labels
4854
map.addLayer({
4955
id: 'cluster-count',
5056
type: 'symbol',
@@ -57,6 +63,7 @@ map.on('load', function () {
5763
},
5864
});
5965

66+
// Add a layer for the unclustered point features.
6067
map.addLayer({
6168
id: 'unclustered-point',
6269
type: 'circle',
@@ -69,6 +76,8 @@ map.on('load', function () {
6976
'circle-stroke-color': '#fff',
7077
},
7178
});
79+
80+
// inspect a cluster on click on clustered point
7281
map.on('click', 'clusters', function (e) {
7382
const features = map.queryRenderedFeatures(e.point, {
7483
layers: ['clusters'],
@@ -86,19 +95,23 @@ map.on('load', function () {
8695
}
8796
);
8897
});
98+
99+
// inspect a cluster on click on an unclustered point
89100
map.on('click', 'unclustered-point', function (e) {
90101
const { popUpMarkup } = e.features[0].properties;
91102
const coordinates = e.features[0].geometry.coordinates.slice();
92103
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
93104
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
94105
}
95106

107+
// Populate the popup and set its coordinates
96108
new mapboxgl.Popup()
97109
.setLngLat(coordinates)
98110
.setHTML(popUpMarkup)
99111
.addTo(map);
100112
});
101113

114+
// Change the cursor to a pointer when the mouse is over the places layer.
102115
map.on('mouseenter', 'clusters', function () {
103116
map.getCanvas().style.cursor = 'pointer';
104117
});

public/js/viewgarage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
var garage = JSON.parse(garage_raw);
22
mapboxgl.accessToken = mapboxtoken;
3+
4+
// Initialize the map
35
var map = new mapboxgl.Map({
46
container: 'map',
57
style: 'mapbox://styles/mapbox/streets-v11',
68
center: garage.geometry.coordinates,
79
zoom: 9,
810
});
11+
12+
// Add garage marker to map
913
var marker = new mapboxgl.Marker()
1014
.setLngLat(garage.geometry.coordinates)
1115
.setPopup(

0 commit comments

Comments
 (0)