-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
181 lines (158 loc) · 5.29 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
mapboxgl.accessToken = 'pk.eyJ1IjoianZrZWNocmlzIiwiYSI6ImNseWg1aWN6eDAxMHIya3M4dG8xeHlsNDMifQ.72yHrET1FT84q35aJfnr3g';
const map = new mapboxgl.Map({
// Choose from Mapbox's core styles, or make your own style with Mapbox Studio
style: 'mapbox://styles/mapbox/streets-v11',
center: [-73.99852, 40.68161], // Updated coordinates
zoom: 15.5,
container: 'map',
antialias: true
});
// Add a marker at the specified coordinates
const marker = new mapboxgl.Marker()
.setLngLat([-73.99852, 40.68161])
.addTo(map);
// Get the button element
const takeMethere = document.getElementById('tmt');
// Get the map container element
const mapContainer = document.getElementById('map');
// Add a click event listener to the button
takeMethere.addEventListener('click', () => {
// Toggle the map overlay class
mapContainer.classList.toggle('map-overlay');
// Adjust the map size and position
map.resize();
// Get the current zoom level
const currentZoom = map.getZoom();
// Fit the map to the marker's location
map.flyTo({
center: [-73.99852, 40.68161],
zoom: currentZoom,
essential: true // this animation is considered essential with respect to prefers-reduced-motion
});
});
// Locate the user and show the fastest route on page load
navigator.geolocation.getCurrentPosition(function(position) {
const userLocation = [position.coords.longitude, position.coords.latitude];
// Check if user is within a certain area
const destinationLocation = [-73.99852, 40.68161]; // Example destination
const bounds = mapboxgl.LngLatBounds.convert([
[-74.1, 40.6],
[-73.9, 40.8]
]); // Example bounding box
if (bounds.contains(userLocation)) {
// User is within the area, show the fastest route
// Add a marker for the user's location
new mapboxgl.Marker()
.setLngLat(userLocation)
.addTo(map);
// Calculate the fastest route and display it on the map
const directionsClient = new mapboxgl.DirectionsClient({
profile: 'driving',
alternatives: false,
geometries: 'geojson',
waypoints: [
{
coordinates: userLocation
},
{
coordinates: destinationLocation
}
]
});
directionsClient.getDirections((error, response) => {
if (!error) {
const route = response.routes[0];
map.addLayer({
id: 'route',
type: 'line',
source: {
type: 'geojson',
data: {
type: 'Feature',
properties: {},
geometry: route.geometry
}
},
layout: {
'line-join': 'round',
'line-cap': 'round'
},
paint: {
'line-color': '#3887be',
'line-width': 5,
'line-opacity': 0.75
}
});
}
});
} else {
// User is outside the area, display a message or do something else
console.log('User is outside the area');
alert("Whoa! You aren't in Brooklyn mate!")
}
});
const soundScroll = new Audio('scroll_sound.mp3');
const soundTap = new Audio('tap_sound.mp3');
window.addEventListener('scroll', function() {
soundScroll.play();
});
window.addEventListener('touchstart', function() {
soundTap.play();
});
window.addEventListener('click', function() {
soundTap.play();
});
// The End Of Year Date To Countdown Date
document.addEventListener('DOMContentLoaded', () => {
// Unix timestamp (in seconds) to count down to
var toDayFromNow = (new Date("July 17, 2024 12:00:00").getTime() / 1000) + (3600 / 60 / 60 / 24) - 1;
// Set Up FlipDown
var flipdown = new FlipDown(toDayFromNow)
// Start The Count Down
.start()
// Do Something When The Countdown Ends
.ifEnded(() => {
document.querySelector(".flipdown").innerHTML = `<h2>If it's not the 17th, YOU MISSED IT!</h2>`;
});
});
document.addEventListener('DOMContentLoaded', function() {
const slider = document.querySelector('.slider');
const slides = slider.querySelectorAll('.slide');
// Clone the first slide and append it to the end
const firstSlide = slides[0].cloneNode(true);
slider.appendChild(firstSlide);
// Add hover event listener to each slide
slides.forEach((slide) => {
slide.addEventListener('mouseenter', playSound);
});
function playSound() {
const audio = new Audio('scroll_sound.mp3');
audio.play();
}
});
const shareButton = document.getElementById('shareButton');
const shareButton2 = document.getElementById('shareButton2');
shareButton.addEventListener('click', async () => {
try {
await navigator.share({
title: 'We out in South Brooklyn!',
text: "I'm attending a stoop sale in carroll gardens just a lil around the corner of court street and 2nd ave.",
url: 'https://codedex-hackathon.vercel.app',
});
console.log('Successful share');
} catch (error) {
console.error('Error sharing:', error);
}
});
shareButton2.addEventListener('click', async () => {
try {
await navigator.share({
title: 'We out in South Brooklyn!',
text: "I'm attending a stoop sale in carroll gardens just a lil around the corner of court street and 2nd ave.",
url: 'https://codedex-hackathon.vercel.app',
});
console.log('Successful share');
} catch (error) {
console.error('Error sharing:', error);
}
});