mirror of
https://github.com/kevin-DL/complete-node-bootcamp.git
synced 2026-01-18 13:55:10 +00:00
Initial commit 🚀
This commit is contained in:
50
4-natours/after-section-12/public/js/mapbox.js
Normal file
50
4-natours/after-section-12/public/js/mapbox.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/* eslint-disable */
|
||||
export const displayMap = locations => {
|
||||
mapboxgl.accessToken =
|
||||
'pk.eyJ1Ijoiam9uYXNzY2htZWR0bWFubiIsImEiOiJjam54ZmM5N3gwNjAzM3dtZDNxYTVlMnd2In0.ytpI7V7w7cyT1Kq5rT9Z1A';
|
||||
|
||||
var map = new mapboxgl.Map({
|
||||
container: 'map',
|
||||
style: 'mapbox://styles/jonasschmedtmann/cjvi9q8jd04mi1cpgmg7ev3dy',
|
||||
scrollZoom: false
|
||||
// center: [-118.113491, 34.111745],
|
||||
// zoom: 10,
|
||||
// interactive: false
|
||||
});
|
||||
|
||||
const bounds = new mapboxgl.LngLatBounds();
|
||||
|
||||
locations.forEach(loc => {
|
||||
// Create marker
|
||||
const el = document.createElement('div');
|
||||
el.className = 'marker';
|
||||
|
||||
// Add marker
|
||||
new mapboxgl.Marker({
|
||||
element: el,
|
||||
anchor: 'bottom'
|
||||
})
|
||||
.setLngLat(loc.coordinates)
|
||||
.addTo(map);
|
||||
|
||||
// Add popup
|
||||
new mapboxgl.Popup({
|
||||
offset: 30
|
||||
})
|
||||
.setLngLat(loc.coordinates)
|
||||
.setHTML(`<p>Day ${loc.day}: ${loc.description}</p>`)
|
||||
.addTo(map);
|
||||
|
||||
// Extend map bounds to include current location
|
||||
bounds.extend(loc.coordinates);
|
||||
});
|
||||
|
||||
map.fitBounds(bounds, {
|
||||
padding: {
|
||||
top: 200,
|
||||
bottom: 150,
|
||||
left: 100,
|
||||
right: 100
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user