-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.ejs
More file actions
145 lines (131 loc) · 5.29 KB
/
index2.ejs
File metadata and controls
145 lines (131 loc) · 5.29 KB
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
<% layout('layouts/boiler') %>
<div id="cluster-map" style='width:100%;height:300px'></div>
<div class="container">
<h1>All campgrounds</h1>
<a href="/campground/new">Add new campground</a>
<% for(let camp of campgrounds) {%>
<div class="card mb-3" style="max-width: 900px;">
<div class="row g-0">
<div class="col-md-4">
<img crossorigin="anonymous" src="<%=camp.images[0].url%>" class="img-fluid rounded-start" alt="">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title" href="/campground/show"><%=camp.title%></h5>
<p class="card-text" href="/campground/show"><%=camp.description%></p>
<p class="card-text" ><small class="text-body-secondary"><%=camp.location%></small></p>
<a href="/campground/<%=camp._id%>" class="btn btn-primary">View</a>
</div>
</div>
</div>
</div>
<% } %>
</div>
<script>
const maptilerApiKey = '<%- process.env.MAPTILER_API_KEY %>';
const campgrounds = { features: <%- JSON.stringify(campgrounds) %>}
maptilersdk.config.apiKey = maptilerApiKey;
const map = new maptilersdk.Map({
container: 'cluster-map',
style: maptilersdk.MapStyle.STREETS,
center: [-103.59179687498357, 40.66995747013945],
zoom: 3
});
map.on('load', function () {
map.addSource('campgrounds', {
type: 'geojson',
data: campgrounds,
cluster: true,
clusterMaxZoom: 14, // Max zoom to cluster points on
clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50)
});
map.addLayer({
id: 'clusters',
type: 'circle',
source: 'campgrounds',
filter: ['has', 'point_count'],
paint: {
// Use step expressions (https://docs.maptiler.com/gl-style-specification/expressions/#step)
// with three steps to implement three types of circles:
'circle-color': [
'step',
['get', 'point_count'],
'#00BCD4',
10,
'#2196F3',
30,
'#3F51B5'
],
'circle-radius': [
'step',
['get', 'point_count'],
15,
10,
20,
30,
25
]
}
});
map.addLayer({
id: 'cluster-count',
type: 'symbol',
source: 'campgrounds',
filter: ['has', 'point_count'],
layout: {
'text-field': '{point_count_abbreviated}',
'text-font': ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'],
'text-size': 12
}
});
map.addLayer({
id: 'unclustered-point',
type: 'circle',
source: 'campgrounds',
filter: ['!', ['has', 'point_count']],
paint: {
'circle-color': '#11b4da',
'circle-radius': 4,
'circle-stroke-width': 1,
'circle-stroke-color': '#fff'
}
});
// inspect a cluster on click
map.on('click', 'clusters', async (e) => {
const features = map.queryRenderedFeatures(e.point, {
layers: ['clusters']
});
const clusterId = features[0].properties.cluster_id;
const zoom = await map.getSource('campgrounds').getClusterExpansionZoom(clusterId);
map.easeTo({
center: features[0].geometry.coordinates,
zoom
});
});
// When a click event occurs on a feature in
// the unclustered-point layer, open a popup at
// the location of the feature, with
// description HTML from its properties.
map.on('click', 'unclustered-point', function (e) {
const { popUpMarkup } = e.features[0].properties;
const coordinates = e.features[0].geometry.coordinates.slice();
// 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 maptilersdk.Popup()
.setLngLat(coordinates)
.setHTML(popUpMarkup)
.addTo(map);
});
map.on('mouseenter', 'clusters', () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'clusters', () => {
map.getCanvas().style.cursor = '';
});
});
</script>
<!-- <script src="/public/javascript/clustermap.js"></script> -->