-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
626 lines (538 loc) · 21.8 KB
/
Copy pathindex.html
File metadata and controls
626 lines (538 loc) · 21.8 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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PolyFNMap - Interactive Fortnite Map</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #121212;
color: #f1f1f1;
}
header {
background-color: #0066cc;
color: white;
padding: 1rem;
text-align: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.container {
display: flex;
flex-direction: column;
max-width: 1200px;
margin: 0 auto;
padding: 1rem;
}
.map-controls {
background-color: #1e1e1e;
padding: 1rem;
border-radius: 10px;
margin-bottom: 1rem;
display: flex;
flex-wrap: wrap;
gap: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
justify-content: space-between;
}
.control-group {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
background-color: #0066cc;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.2s, transform 0.1s;
font-size: 0.9rem;
}
button:hover {
background-color: #0052a3;
transform: translateY(-1px);
}
button:focus {
outline: 2px solid #ff6600;
outline-offset: 2px;
}
button.active {
background-color: #ff6600;
}
.map-container {
position: relative;
width: 100%;
margin-bottom: 1rem;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
#map-image {
width: 100%;
height: auto;
display: block;
}
.poi-marker {
position: absolute;
width: 10px;
height: 10px;
background-color: #ff6600;
border-radius: 50%;
transform: translate(-50%, -50%);
cursor: pointer;
transition: all 0.2s;
border: 2px solid white;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}
.poi-marker:hover, .poi-marker:focus {
width: 14px;
height: 14px;
z-index: 10;
}
.poi-marker.selected {
width: 16px;
height: 16px;
background-color: #ff0000;
z-index: 10;
}
.poi-info {
background-color: #1e1e1e;
padding: 1rem;
border-radius: 10px;
margin-top: 1rem;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
max-height: 200px;
overflow-y: auto;
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { transform: translateY(10px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.poi-list {
background-color: #1e1e1e;
padding: 1rem;
border-radius: 10px;
margin-top: 1rem;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
max-height: 300px;
overflow-y: auto;
}
.poi-item {
background-color: #333;
padding: 8px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.poi-item:hover, .poi-item:focus {
background-color: #444;
}
.search-box {
padding: 10px;
width: 100%;
max-width: 300px;
border-radius: 6px;
border: 1px solid #444;
background-color: #333;
color: white;
font-size: 0.9rem;
}
.search-box:focus {
outline: 2px solid #ff6600;
outline-offset: 2px;
}
.filter-section {
margin-bottom: 1rem;
}
.filter-options {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #0066cc;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.hidden {
display: none;
}
.legend {
display: flex;
align-items: center;
margin-top: 0.5rem;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
margin-right: 1rem;
margin-bottom: 0.5rem;
}
.legend-color {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 5px;
border: 1px solid white;
}
.error-message {
background-color: #ff3333;
color: white;
padding: 1rem;
border-radius: 10px;
margin-top: 1rem;
text-align: center;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.retry-btn {
background-color: #fff;
color: #ff3333;
padding: 8px 16px;
font-weight: bold;
}
.retry-btn:hover {
background-color: #e0e0e0;
}
@media (max-width: 768px) {
.map-controls {
flex-direction: column;
align-items: stretch;
}
.control-group {
justify-content: center;
}
.search-box {
max-width: 100%;
}
.poi-list {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.filter-options {
justify-content: center;
}
}
</style>
</head>
<body>
<header>
<h1>PolyFNMap</h1>
<p>Interactive Fortnite Map Explorer</p>
</header>
<div class="container">
<div class="map-controls" role="toolbar" aria-label="Map controls">
<div class="control-group">
<button id="show-pois-btn" class="active" aria-pressed="true">Show All POIs</button>
<button id="clear-btn" aria-label="Clear selected POI">Clear Selection</button>
<button id="toggle-map-btn" aria-label="Toggle between detailed and blank map">Toggle Map Style</button>
</div>
<div>
<input type="text" id="search-box" class="search-box" placeholder="Search POIs..." aria-label="Search for Points of Interest">
</div>
</div>
<div class="filter-section">
<h3>Filter POIs:</h3>
<div class="filter-options" role="group" aria-label="POI type filters">
<button class="filter-btn" data-filter="named" aria-label="Filter by Named Locations">Named Locations</button>
<button class="filter-btn" data-filter="unnamed" aria-label="Filter by Landmarks">Landmarks</button>
<button class="filter-btn" data-filter="gas" aria-label="Filter by Gas Stations">Gas Stations</button>
<button class="filter-btn" data-filter="outpost" aria-label="Filter by Outposts">Outposts</button>
</div>
<div class="legend" aria-label="Map legend">
<div class="legend-item">
<div class="legend-color" style="background-color: #ff6600;"></div>
<span>POI</span>
</div>
<div class="legend-item">
<div class="legend-color" style="background-color: #ff0000;"></div>
<span>Selected</span>
</div>
<div class="legend-item">
<div class="legend-color" style="background-color: #00cc66;"></div>
<span>Gas Station</span>
</div>
<div class="legend-item">
<div class="legend-color" style="background-color: #0099ff;"></div>
<span>Outpost</span>
</div>
</div>
</div>
<div class="map-container" role="region" aria-label="Interactive Fortnite map">
<img id="map-image" src="" alt="Fortnite Map" aria-hidden="true">
<div id="poi-markers" aria-label="POI markers"></div>
</div>
<div id="poi-info" class="poi-info hidden" role="region" aria-label="Selected POI details">
<h3 id="poi-name">Selected POI</h3>
<p id="poi-details">Details about the selected POI will appear here.</p>
<p id="poi-coords">Coordinates: </p>
</div>
<div class="poi-list" id="poi-list" role="list" aria-label="List of Points of Interest">
<div class="loader" id="loader" aria-label="Loading POIs"></div>
</div>
<div id="error-message" class="error-message hidden" role="alert">
<span id="error-text">Error loading map data. Please try again later.</span>
<button class="retry-btn" id="retry-btn" aria-label="Retry loading map data">Retry</button>
</div>
</div>
<script>
// DOM Elements
const mapImage = document.getElementById('map-image');
const poiMarkers = document.getElementById('poi-markers');
const poiInfo = document.getElementById('poi-info');
const poiName = document.getElementById('poi-name');
const poiDetails = document.getElementById('poi-details');
const poiCoords = document.getElementById('poi-coords');
const poiList = document.getElementById('poi-list');
const searchBox = document.getElementById('search-box');
const loader = document.getElementById('loader');
const errorMessage = document.getElementById('error-message');
const errorText = document.getElementById('error-text');
const retryBtn = document.getElementById('retry-btn');
const showPoisBtn = document.getElementById('show-pois-btn');
const clearBtn = document.getElementById('clear-btn');
const toggleMapBtn = document.getElementById('toggle-map-btn');
const filterBtns = document.querySelectorAll('.filter-btn');
// Map state
let mapData = null;
let selectedPoi = null;
let useBlankMap = false;
let currentFilter = null;
// Constants for map scaling
const MAP_SIZE = 1024; // Fortnite map is normalized to 1024x1024
const MAP_OFFSET = 128000; // Coordinates are offset from -128000 to 128000
// Debounce function for search
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Initialize the map
async function initMap() {
try {
// Show loader
loader.classList.remove('hidden');
errorMessage.classList.add('hidden');
// Fetch map data from Fortnite API
const response = await fetch('https://fortnite-api.com/v1/map');
if (!response.ok) {
throw new Error(`HTTP error ${response.status}: ${response.statusText}`);
}
const data = await response.json();
if (!data.data || !data.data.images || !data.data.pois) {
throw new Error('Invalid map data structure');
}
mapData = data.data;
// Set map image
mapImage.src = mapData.images.pois;
// Render POI markers
renderPoiMarkers();
// Render POI list
renderPoiList();
// Hide loader
loader.classList.add('hidden');
} catch (error) {
console.error('Error initializing map:', error);
loader.classList.add('hidden');
errorMessage.classList.remove('hidden');
errorText.textContent = `Error loading map data: ${error.message}`;
}
}
// Convert map coordinates to screen coordinates
function mapToScreenCoords(x, y) {
const normalizedX = (x + MAP_OFFSET) / (MAP_OFFSET * 2);
const normalizedY = (y + MAP_OFFSET) / (MAP_OFFSET * 2);
return {
x: normalizedX * 100,
y: (1 - normalizedY) * 100
};
}
// Render POI markers on the map
function renderPoiMarkers() {
poiMarkers.innerHTML = '';
if (!mapData) return;
let poiToRender = currentFilter ? filterPois(currentFilter) : mapData.pois;
poiToRender.forEach(poi => {
const { x, y } = mapToScreenCoords(poi.location.x, poi.location.y);
const marker = document.createElement('div');
marker.className = 'poi-marker';
marker.style.left = `${x}%`;
marker.style.top = `${y}%`;
marker.setAttribute('role', 'button');
marker.setAttribute('aria-label', `Select ${poi.name}`);
marker.tabIndex = 0;
if (poi.id.includes('GasStation')) {
marker.style.backgroundColor = '#00cc66';
} else if (poi.id.includes('Outpost') || poi.id.includes('Checkpoint')) {
marker.style.backgroundColor = '#0099ff';
}
marker.addEventListener('click', () => selectPoi(poi));
marker.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
selectPoi(poi);
}
});
poiMarkers.appendChild(marker);
});
}
// Render POI list
function renderPoiList() {
const existingItems = poiList.querySelectorAll('.poi-item');
existingItems.forEach(item => item.remove());
if (!mapData) return;
let poiToRender = currentFilter ? filterPois(currentFilter) : mapData.pois;
poiToRender.sort((a, b) => a.name.localeCompare(b.name));
poiToRender.forEach(poi => {
const item = document.createElement('div');
item.className = 'poi-item';
item.textContent = poi.name;
item.setAttribute('role', 'listitem');
item.setAttribute('aria-label', `Select ${poi.name}`);
item.tabIndex = 0;
item.addEventListener('click', () => selectPoi(poi));
item.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
selectPoi(poi);
}
});
poiList.appendChild(item);
});
}
// Filter POIs by type
function filterPois(filterType) {
if (!mapData) return [];
switch (filterType) {
case 'named':
return mapData.pois.filter(poi => poi.id.includes('POI.Generic'));
case 'unnamed':
return mapData.pois.filter(poi => poi.id.includes('Landmark'));
case 'gas':
return mapData.pois.filter(poi => poi.id.includes('GasStation'));
case 'outpost':
return mapData.pois.filter(poi =>
poi.id.includes('Checkpoint') ||
poi.id.includes('Outpost')
);
default:
return mapData.pois;
}
}
// Select a POI
function selectPoi(poi) {
const selectedMarkers = document.querySelectorAll('.poi-marker.selected');
selectedMarkers.forEach(marker => marker.classList.remove('selected'));
const { x, y } = mapToScreenCoords(poi.location.x, poi.location.y);
const markers = document.querySelectorAll('.poi-marker');
markers.forEach(marker => {
const markerX = parseFloat(marker.style.left);
const markerY = parseFloat(marker.style.top);
if (Math.abs(markerX - x) < 0.1 && Math.abs(markerY - y) < 0.1) {
marker.classList.add('selected');
marker.focus();
}
});
selectedPoi = poi;
poiName.textContent = poi.name;
poiDetails.textContent = `Location Type: ${getPoiType(poi)}`;
poiCoords.textContent = `Coordinates: X: ${Math.round(poi.location.x)}, Y: ${Math.round(poi.location.y)}, Z: ${Math.round(poi.location.z)}`;
poiInfo.classList.remove('hidden');
const listItems = document.querySelectorAll('.poi-item');
listItems.forEach(item => {
item.style.backgroundColor = item.textContent === poi.name ? '#ff6600' : '';
});
}
// Get POI type from ID
function getPoiType(poi) {
if (poi.id.includes('POI.Generic')) return 'Named Location';
if (poi.id.includes('GasStation')) return 'Gas Station';
if (poi.id.includes('Checkpoint') || poi.id.includes('Outpost')) return 'Outpost';
if (poi.id.includes('Landmark')) return 'Landmark';
return 'Other';
}
// Search POIs
function searchPois(query) {
query = query.toLowerCase().trim();
const filteredPois = query ? mapData.pois.filter(poi =>
poi.name.toLowerCase().includes(query)
) : mapData.pois;
const tempMapData = { ...mapData, pois: filteredPois };
const originalMapData = mapData;
mapData = tempMapData;
renderPoiMarkers();
renderPoiList();
mapData = originalMapData;
}
// Debounced search
const debouncedSearch = debounce(searchPois, 300);
// Event listeners
showPoisBtn.addEventListener('click', () => {
currentFilter = null;
renderPoiMarkers();
renderPoiList();
filterBtns.forEach(btn => btn.classList.remove('active'));
showPoisBtn.classList.add('active');
showPoisBtn.setAttribute('aria-pressed', 'true');
filterBtns.forEach(btn => btn.setAttribute('aria-pressed', 'false'));
});
clearBtn.addEventListener('click', () => {
selectedPoi = null;
poiInfo.classList.add('hidden');
const selectedMarkers = document.querySelectorAll('.poi-marker.selected');
selectedMarkers.forEach(marker => marker.classList.remove('selected'));
const listItems = document.querySelectorAll('.poi-item');
listItems.forEach(item => item.style.backgroundColor = '');
});
toggleMapBtn.addEventListener('click', () => {
useBlankMap = !useBlankMap;
mapImage.src = useBlankMap ? mapData.images.blank : mapData.images.pois;
toggleMapBtn.setAttribute('aria-label',
`Toggle to ${useBlankMap ? 'detailed' : 'blank'} map`
);
});
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
const filterType = btn.dataset.filter;
currentFilter = filterType;
filterBtns.forEach(b => b.classList.remove('active'));
showPoisBtn.classList.remove('active');
btn.classList.add('active');
filterBtns.forEach(b => b.setAttribute('aria-pressed', b === btn ? 'true' : 'false'));
showPoisBtn.setAttribute('aria-pressed', 'false');
renderPoiMarkers();
renderPoiList();
});
});
searchBox.addEventListener('input', () => debouncedSearch(searchBox.value));
retryBtn.addEventListener('click', initMap);
// Initialize map on page load
window.addEventListener('load', initMap);
</script>
</body>
</html>