-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.html
More file actions
407 lines (377 loc) · 17 KB
/
map.html
File metadata and controls
407 lines (377 loc) · 17 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Map - John's Work</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<!-- Mapbox GL JS CSS -->
<link href='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css' rel='stylesheet' />
<style>
.map-container {
width: 100%;
height: 600px;
position: relative;
}
#map {
width: 100%;
height: 100%;
}
.map-controls {
position: relative;
margin-bottom: 20px;
display: flex;
gap: 10px;
justify-content: flex-start;
}
.map-button {
padding: 8px 16px;
background-color: white;
border: 1px solid #ccc;
border-radius: 4px;
cursor: pointer;
font-family: 'Lexend', sans-serif;
font-size: 14px;
transition: all 0.3s ease;
}
.map-button:hover {
background-color: #f0f0f0;
}
.map-button.active {
background-color: #383838;
color: white;
border-color: #383838;
}
.mapboxgl-popup {
max-width: 200px;
font-family: 'Lexend', sans-serif;
}
.mapboxgl-popup-content {
text-align: center;
padding: 10px;
background-color: #ffffff;
color: #383838;
}
.project-preview-popup {
position: absolute;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 10px;
z-index: 1000;
max-width: 300px;
display: none;
max-height: 80vh; /* Limit height to 80% of viewport height */
overflow: hidden; /* Hide overflow for main container */
}
.location-header {
text-align: center;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
font-family: 'Lexend', sans-serif;
position: sticky;
top: 0;
background: white;
z-index: 1;
}
.location-header h3 {
font-size: 18px;
color: #383838;
margin: 0;
font-weight: 500;
}
.location-header p {
font-size: 14px;
color: #666;
margin: 5px 0 0 0;
}
.project-preview-image {
width: 100%;
height: 150px; /* Reduced height to show more projects */
background-size: cover;
background-position: center;
border-radius: 4px;
margin-bottom: 8px;
transition: transform 0.2s;
}
.project-preview-image:hover {
transform: scale(1.02); /* Subtle zoom on hover */
}
.project-preview-title {
font-family: 'Lexend', sans-serif;
font-size: 14px;
color: #383838;
margin: 5px 0;
text-align: center;
}
.preview-container {
display: flex;
flex-direction: column;
gap: 10px;
max-height: calc(80vh - 100px); /* Account for header height */
overflow-y: auto; /* Make projects container scrollable */
padding-right: 5px; /* Space for scrollbar */
}
/* Style the scrollbar */
.preview-container::-webkit-scrollbar {
width: 6px;
}
.preview-container::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
.preview-container::-webkit-scrollbar-thumb {
background: #888;
border-radius: 3px;
}
.preview-container::-webkit-scrollbar-thumb:hover {
background: #555;
}
.project-link {
text-decoration: none;
color: inherit;
display: block;
cursor: pointer;
transition: transform 0.2s;
}
.project-link:hover {
transform: scale(1.02);
}
</style>
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-57VEQPXVGX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-57VEQPXVGX');
</script>
<body>
<header>
<nav>
<ul>
<li><a href="index.html" data-key="home">Home</a></li>
<li><a href="about.html" data-key="about">About</a></li>
<li><a href="contact.html" data-key="contact">Contact</a></li>
<li><a href="map.html" data-key="map">Map</a></li>
<!-- <li><a href="news.html" data-key="news">News</a></li> -->
<li><a href="work.html" data-key="work">Work</a></li>
<li><a href="https://www.instagram.com/jjjhiker/" target="_blank" data-key="instagram">Instagram</a></li>
<li><a href="https://www.linkedin.com/in/johnmasataka-xianfeng-jiang/" target="_blank" data-key="linkedin">LinkedIn</a></li>
</ul>
</nav>
<div class="language-selector">
<select id="language-select">
<option value="en">English</option>
<option value="ja">日本語</option>
<option value="zh-CN">简体中文</option>
<option value="zh-TW">繁體中文</option>
</select>
</div>
</header>
<main>
<section class="map">
<!-- <h1>Interactive World Map</h1> -->
<div class="map-controls">
<button id="flatMap" class="map-button active">Flat Map</button>
<button id="earth" class="map-button">Earth</button>
</div>
<div class="map-content">
<div class="map-container">
<div id="map"></div>
</div>
</div>
</section>
</main>
<footer>
<p>Copyright © - All Rights Reserved.</p>
</footer>
<!-- Mapbox GL JS -->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js'></script>
<script>
// Replace with your Mapbox access token
mapboxgl.accessToken = 'pk.eyJ1Ijoiam9obm1hc2F0YWthIiwiYSI6ImNseDl0ZnByMzJ1cnQyam9lbnB5ajQ3d3EifQ.vDNx6tuvH4CxRBRu-Tt0Tg';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v11',
center: [0, 0],
zoom: 1.5,
projection: 'mercator'
});
// City coordinates with country information
const cities = [
{ name: 'Toruń', country: 'Poland', coordinates: [18.5984, 53.0138] },
{ name: 'Honolulu', country: 'United States', coordinates: [-157.8583, 21.3069] },
{ name: 'Los Angeles', country: 'United States', coordinates: [-118.2437, 34.0522] },
{ name: 'Ishigaki', country: 'Japan', coordinates: [124.1556, 24.3406] },
{ name: 'London', country: 'United Kingdom', coordinates: [-0.1276, 51.5074] },
{ name: 'Portland', country: 'United States', coordinates: [-122.6765, 45.5155] },
{ name: 'Miami', country: 'United States', coordinates: [-80.1918, 25.7617] },
{ name: 'Vancouver', country: 'Canada', coordinates: [-123.1207, 49.2827] },
{ name: 'Sapporo', country: 'Japan', coordinates: [141.3545, 43.0618] },
{ name: 'Borabora', country: 'French Polynesia', coordinates: [-151.7517, -16.5004] },
{ name: 'Nagasaki', country: 'Japan', coordinates: [129.8777, 32.7503] },
{ name: 'Concepción', country: 'Chile', coordinates: [-73.0498, -36.8270] },
{ name: 'Taichung', country: 'Taiwan', coordinates: [120.6839, 24.1477] },
{ name: 'San Francisco', country: 'United States', coordinates: [-122.4194, 37.7749] },
{ name: 'Neom', country: 'Saudi Arabia', coordinates: [35.0, 28.0] },
{ name: 'Jakarta', country: 'Indonesia', coordinates: [106.8456, -6.2088] },
{ name: 'Bali', country: 'Indonesia', coordinates: [115.1889, -8.4095] },
{ name: 'Atlanta', country: 'United States', coordinates: [-84.3880, 33.7490] },
{ name: 'Naha', country: 'Japan', coordinates: [127.6791, 26.2124] },
{ name: 'Kyoto', country: 'Japan', coordinates: [135.7681, 35.0116] },
{ name: 'New York', country: 'United States', coordinates: [-74.0060, 40.7128] },
{ name: 'Beijing', country: 'China', coordinates: [116.4074, 39.9042] },
{ name: 'Milan', country: 'Italy', coordinates: [9.1914, 45.4642] }
];
// Create a popup element for project previews
const previewPopup = document.createElement('div');
previewPopup.className = 'project-preview-popup';
document.body.appendChild(previewPopup);
// Function to get projects for a city
function getProjectsForCity(cityName) {
// Define tag variations for cities
const cityTagVariations = {
'New York': ['newyork'],
'Los Angeles': ['la'],
'San Francisco': ['sf'],
'Bora Bora': ['borabora'],
'Bali': ['bali'],
'Beijing': ['china', 'hitchhiking'],
'Milan': ['italia', 'italy', 'milan'],
// Add other variations if needed
};
// Fetch projects from work.html
return fetch('work.html')
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const projects = [];
// Find all project items that have the city tag
doc.querySelectorAll('.project-item').forEach(item => {
const tags = item.getAttribute('data-tags').toLowerCase().split(' ');
const cityNameLower = cityName.toLowerCase();
// Get variations for this city
const variations = cityTagVariations[cityName] || [];
// Check if the project has the city tag or any of its variations
if (tags.includes(cityNameLower) || variations.some(v => tags.includes(v))) {
const imageUrl = item.querySelector('.project-image').style.backgroundImage
.replace('url(', '').replace(')', '').replace(/"/g, '');
const title = item.querySelector('.project-title').textContent;
projects.push({ imageUrl, title });
}
});
return projects;
});
}
// Add markers when map loads
map.on('load', () => {
cities.forEach(city => {
// Create marker element
const el = document.createElement('div');
el.className = 'marker';
// Get projects count first
getProjectsForCity(city.name).then(projects => {
const projectCount = projects.length;
// Base size is 16 px, increase exponentially with number of projects
const size = projectCount === 0 ? 16 : Math.min(16 + Math.pow(projectCount, 1.5), 50);
// Base size is 16px, scales linearly with project count
// const baseSize = 16;
// const size = projectCount === 0 ? baseSize : baseSize * projectCount;
el.style.width = `${size}px`;
el.style.height = `${size}px`;
el.style.backgroundColor = '#383838';
el.style.border = '2px solid #ffffff';
el.style.borderRadius = '50%';
el.style.cursor = 'pointer';
el.style.boxShadow = '0 0 2px rgba(0,0,0,0.3)';
// Add project count if there are projects
if (projectCount > 0) {
el.style.display = 'flex';
el.style.alignItems = 'center';
el.style.justifyContent = 'center';
el.style.color = '#ffffff';
el.style.fontSize = `${Math.max(10, size/2)}px`;
el.style.fontFamily = "'Lexend', sans-serif";
el.style.fontWeight = '500';
el.innerText = projectCount.toString();
}
// Create and add the marker
const marker = new mapboxgl.Marker(el)
.setLngLat(city.coordinates)
.addTo(map);
// Handle click on marker
el.addEventListener('click', async (e) => {
e.stopPropagation(); // Prevent document click from immediately closing
const projects = await getProjectsForCity(city.name);
if (projects.length > 0) {
// Create preview content with location header
let previewContent = `
<div class="location-header">
<h3>${city.name}</h3>
<p>${city.country}</p>
</div>
<div class="preview-container">
`;
projects.forEach(project => {
previewContent += `
<div>
<a href="work.html#${project.title.toLowerCase().replace(/\s+/g, '-')}" class="project-link" target="_blank">
<div class="project-preview-image" style="background-image: url(${project.imageUrl})"></div>
<div class="project-preview-title">${project.title}</div>
</a>
</div>
`;
});
previewContent += '</div>';
// Update and show popup
previewPopup.innerHTML = previewContent;
previewPopup.style.display = 'block';
// Position popup near the marker
const markerRect = el.getBoundingClientRect();
previewPopup.style.left = `${markerRect.right + 10}px`;
previewPopup.style.top = `${markerRect.top}px`;
}
});
// Close popup when clicking outside
document.addEventListener('click', (e) => {
const isOverMarker = el.contains(e.target) || el === e.target;
const isOverPopup = previewPopup.contains(e.target) || previewPopup === e.target;
if (!isOverMarker && !isOverPopup) {
previewPopup.style.display = 'none';
}
});
});
});
// Apply monochrome filter to all layers
const layers = map.getStyle().layers;
for (const layer of layers) {
if (layer.type === 'symbol') continue;
map.setPaintProperty(layer.id, 'raster-saturation', -1);
map.setPaintProperty(layer.id, 'raster-contrast', 0.5);
}
});
const flatMapBtn = document.getElementById('flatMap');
const earthBtn = document.getElementById('earth');
flatMapBtn.addEventListener('click', () => {
map.setProjection('mercator');
flatMapBtn.classList.add('active');
earthBtn.classList.remove('active');
});
earthBtn.addEventListener('click', () => {
map.setProjection('globe');
earthBtn.classList.add('active');
flatMapBtn.classList.remove('active');
});
// Add navigation controls
map.addControl(new mapboxgl.NavigationControl());
</script>
<script src="script.js"></script>
</body>
</html>