forked from steveseguin/social_stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.html
More file actions
2464 lines (2263 loc) · 110 KB
/
Copy pathmap.html
File metadata and controls
2464 lines (2263 loc) · 110 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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>World Map Overlay - Social Stream Ninja</title>
<link rel="icon" href="./favicon.ico" />
<script src="./thirdparty/d3.min.js"></script>
<script src="./thirdparty/topojson-client.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&display=swap');
:root {
--bg: rgba(6, 10, 16, 0.35);
--grid: rgba(255, 255, 255, 0.08);
--text: #e8edf6;
--muted: #9fb4cf;
--accent: #6ef7c8;
--accent-2: #f4b556;
--panel: rgba(14, 20, 32, 0.65);
--stroke: rgba(255, 255, 255, 0.14);
--country-fill: rgba(255, 255, 255, 0.06);
--country-highlight: rgba(255, 255, 255, 0.45);
--stroke-width: 0.6;
--country-opacity: 1;
--surface-opacity: 0.45;
--surface-blend: lighten;
--surface-rotate: 0deg;
--surface-shift-x: 0px;
--surface-shift-y: 0px;
--surface-scale: 1;
--surface-filter: none;
--map-zoom: 1;
--map-pan-x: 0px;
--map-pan-y: 0px;
--map-rotate: 0deg;
--map-tilt: 0deg;
--map-perspective: none;
--map-filter: none;
--panel-border: 1px solid rgba(255, 255, 255, 0.1);
--hud-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
--hud-blur: 10px;
--status-bg: rgba(0, 0, 0, 0.4);
--status-color: var(--text);
}
* { box-sizing: border-box; }
body {
margin: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
font-family: 'Space Grotesk', 'Sora', 'Segoe UI', system-ui, -apple-system, sans-serif;
color: var(--text);
perspective: var(--map-perspective, none);
background:
radial-gradient(120% 90% at 15% 15%, rgba(110, 247, 200, 0.12), transparent),
radial-gradient(80% 70% at 80% 20%, rgba(244, 181, 86, 0.14), transparent),
var(--bg);
}
.map-surface {
position: absolute;
inset: 0;
background: repeating-linear-gradient(
0deg,
transparent 0,
transparent 32px,
var(--grid) 32px,
var(--grid) 33px
), repeating-linear-gradient(
90deg,
transparent 0,
transparent 32px,
var(--grid) 32px,
var(--grid) 33px
);
pointer-events: none;
mix-blend-mode: var(--surface-blend, lighten);
opacity: var(--surface-opacity, 0.45);
transform: translate(var(--surface-shift-x, 0px), var(--surface-shift-y, 0px)) scale(var(--surface-scale, 1)) rotate(var(--surface-rotate, 0deg));
transform-origin: center;
transition: opacity 0.8s ease, transform 1s ease;
filter: var(--surface-filter, none);
}
svg#world-map {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
transform: translate(var(--map-pan-x, 0px), var(--map-pan-y, 0px)) scale(var(--map-zoom, 1)) rotate(var(--map-rotate, 0deg)) rotateX(var(--map-tilt, 0deg));
transform-origin: center;
transform-style: preserve-3d;
transition: transform 1.2s ease, filter 1s ease, opacity 0.6s ease;
filter: var(--map-filter, none);
}
.country {
fill: var(--country-fill, rgba(255, 255, 255, 0.06));
stroke: var(--stroke);
stroke-width: var(--stroke-width, 0.6);
opacity: var(--country-opacity, 1);
transition: fill 0.4s ease, stroke 0.4s ease, opacity 0.4s ease;
}
.country.has-data {
stroke: var(--country-highlight, rgba(255, 255, 255, 0.45));
}
.country-label {
fill: var(--text);
font-size: 12px;
font-weight: 700;
text-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
pointer-events: none;
}
.marker {
pointer-events: none;
filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.35));
}
.marker circle {
fill: var(--accent);
opacity: 0.22;
stroke: var(--accent);
stroke-width: 1.4;
stroke-opacity: 0.65;
}
.marker text {
fill: #0b141f;
font-size: 11px;
font-weight: 700;
}
.pulse {
fill: none;
stroke: var(--accent);
stroke-width: 2px;
opacity: 0.85;
}
#hud {
position: absolute;
right: 24px;
bottom: 24px;
min-width: 280px;
max-width: 520px;
padding: 16px 18px;
background: var(--panel);
border: var(--panel-border, 1px solid rgba(255, 255, 255, 0.1));
border-radius: 16px;
backdrop-filter: blur(var(--hud-blur, 10px));
box-shadow: var(--hud-shadow, 0 18px 60px rgba(0, 0, 0, 0.35));
}
#title {
margin: 0 0 8px;
font-weight: 700;
letter-spacing: 0.3px;
text-transform: uppercase;
font-size: 16px;
color: var(--text);
}
.stats {
display: flex;
gap: 12px;
margin-bottom: 10px;
flex-wrap: wrap;
}
.stat-pill {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.06);
border: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 13px;
}
.stat-pill .value {
color: var(--text);
font-weight: 700;
font-size: 15px;
}
.stat-pill .label {
color: var(--muted);
font-size: 12px;
letter-spacing: 0.2px;
}
.top-list {
margin: 6px 0 0;
padding: 0;
list-style: none;
}
.top-list li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 6px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
color: var(--muted);
font-size: 13px;
letter-spacing: 0.2px;
}
.top-list li:last-child {
border-bottom: none;
}
.pill {
padding: 4px 8px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.08);
color: var(--text);
font-weight: 700;
min-width: 36px;
text-align: center;
}
#status {
position: absolute;
top: 18px;
left: 18px;
padding: 10px 14px;
border-radius: 12px;
background: var(--status-bg, rgba(0, 0, 0, 0.4));
color: var(--status-color, var(--text));
font-weight: 600;
letter-spacing: 0.2px;
pointer-events: none;
}
.hidden { display: none; }
@keyframes grid-drift {
0% { transform: translate3d(0, 0, 0); }
50% { transform: translate3d(24px, -18px, 0); }
100% { transform: translate3d(0, 0, 0); }
}
@keyframes hud-float {
0% { transform: translate3d(0, 0, 0); }
50% { transform: translate3d(-8px, -4px, 0); }
100% { transform: translate3d(0, 0, 0); }
}
.motion-drift .map-surface {
animation: grid-drift 36s ease-in-out infinite;
}
.motion-drift #hud {
animation: hud-float 16s ease-in-out infinite;
}
@media (max-width: 768px) {
#hud {
bottom: 14px;
left: 14px;
right: 14px;
}
}
</style>
</head>
<body>
<div id="status">Loading map...</div>
<svg id="world-map"></svg>
<div class="map-surface"></div>
<div id="hud">
<p id="title">Where is everyone watching from?</p>
<div class="stats">
<span class="stat-pill">
<span class="value" id="total-people">0</span>
<span class="label" id="total-people-label">participants</span>
</span>
<span class="stat-pill">
<span class="value" id="countries-count">0</span>
<span class="label" id="location-label">countries</span>
</span>
</div>
<ol class="top-list" id="top-list"></ol>
</div>
<script>
(() => {
const rawParams = new URLSearchParams(window.location.search);
const urlParams = rawParams;
const normalizedParams = new Map();
for (const [key, value] of rawParams.entries()) {
const lower = key.toLowerCase();
normalizedParams.set(key, value);
if (!normalizedParams.has(lower)) {
normalizedParams.set(lower, value);
}
}
function getParam(key) {
if (!key) return null;
if (rawParams.has(key)) return rawParams.get(key);
const lower = key.toLowerCase();
if (rawParams.has(lower)) return rawParams.get(lower);
return normalizedParams.has(lower) ? normalizedParams.get(lower) : null;
}
function hasParam(key) {
if (!key) return false;
const lower = key.toLowerCase();
return rawParams.has(key) || rawParams.has(lower) || normalizedParams.has(lower);
}
const TRUE_STRINGS = new Set(['1', 'true', 'yes', 'on']);
const FALSE_STRINGS = new Set(['0', 'false', 'no', 'off']);
function normalizeBoolean(value, fallback) {
if (value === undefined || value === null) return fallback;
if (typeof value === 'boolean') return value;
const normalized = value.toString().trim().toLowerCase();
if (TRUE_STRINGS.has(normalized)) return true;
if (FALSE_STRINGS.has(normalized)) return false;
return fallback;
}
const debugMode = normalizeBoolean(getParam('debug'), false);
const settings = {
title: getParam('title') || 'Where is everyone watching from?',
showList: normalizeBoolean(getParam('showlist') ?? getParam('showList'), true),
showTotals: normalizeBoolean(getParam('showtotals') ?? getParam('showTotals'), true),
allowChanges: normalizeBoolean(getParam('allowchanges') ?? getParam('allowChanges'), false),
accent: getParam('accent') || null,
accentAlt: getParam('accentalt') ?? getParam('accentAlt') ?? null,
mapType: (getParam('maptype') ?? getParam('mapType') ?? 'country').toLowerCase(),
mapStyle: (getParam('mapstyle') ?? getParam('mapStyle') ?? 'default').toLowerCase(),
region: (getParam('region') ?? getParam('mapregion') ?? 'global').toLowerCase(),
multiVote: (() => {
const keys = ['multi', 'mapspam', 'mapSpam'];
for (const key of keys) {
const raw = getParam(key);
if (raw !== null && raw !== undefined && raw !== '') {
return normalizeBoolean(raw, false);
}
if (hasParam(key)) return true; // presence without value counts as true
}
return false;
})(),
motion: normalizeBoolean(getParam('motion') ?? getParam('mapmotion') ?? getParam('mapMotion'), false),
autoStart: normalizeBoolean(getParam('autostart') ?? getParam('autoStart'), true),
autoFitMarkers: normalizeBoolean(getParam('autofit') ?? getParam('autoFit') ?? getParam('autofitmarkers') ?? getParam('autoFitMarkers') ?? getParam('mapautofit') ?? getParam('mapAutoFit'), false),
hideNumbers: normalizeBoolean(getParam('hidenumbers') ?? getParam('hideNumbers') ?? getParam('maphidenumbers') ?? getParam('mapHideNumbers'), false),
colorIntensity: normalizeBoolean(getParam('colorintensity') ?? getParam('colorIntensity') ?? getParam('mapcolorintensity') ?? getParam('mapColorIntensity'), false),
mapScale: parseFloat(getParam('mapscale') ?? getParam('mapScale') ?? '100') / 100 || 1
};
const VALID_MAP_TYPES = new Set(['country', 'state', 'city']);
if (!VALID_MAP_TYPES.has(settings.mapType)) settings.mapType = 'country';
settings.region = settings.region || 'global';
const statusEl = document.getElementById('status');
const titleEl = document.getElementById('title');
const totalPeopleEl = document.getElementById('total-people');
const totalPeopleLabelEl = document.getElementById('total-people-label');
const countryCountEl = document.getElementById('countries-count');
const locationLabelEl = document.getElementById('location-label');
const topListEl = document.getElementById('top-list');
const hudEl = document.getElementById('hud');
// Apply initial map scale after hudEl is defined
if (settings.mapScale !== 1) {
hudEl.style.transform = `scale(${settings.mapScale})`;
hudEl.style.transformOrigin = 'bottom right';
}
const svg = d3.select('#world-map');
const mapLayer = svg.append('g');
const markerLayer = svg.append('g');
const pulseLayer = svg.append('g');
let projection;
let pathGenerator;
let atlasFeatures = [];
let stateFeatures = [];
let isoLookup = new Map();
let isoByNumeric = new Map();
let isoMeta = new Map(); // iso -> { region, subRegion }
let regionSets = new Map(); // key -> Set(iso)
let renderedFeatures = [];
let featureByIso = new Map();
let featureNameLookup = new Map();
let ready = false;
const pendingMessages = [];
let isPaused = !settings.autoStart;
let isEnabled = true;
let totalEntries = 0;
const uniqueVoters = new Set();
const voters = new Map(); // voterKey -> countryKey
const countryTally = new Map(); // countryKey -> { key, code, name, count, feature }
const placeTally = new Map(); // mapType specific tally (state/city)
const aliasToIso = new Map();
const cityHints = new Map();
const placeCoords = new Map(); // normalized key -> { lat, lon, label, iso }
const placeFeatureLookup = new Map(); // normalized key (optionally with iso) -> feature
let regionalCityData = [];
const boostedCityRegions = new Set();
const US_STATE_ABBR = {
'01': 'AL', '02': 'AK', '04': 'AZ', '05': 'AR', '06': 'CA', '08': 'CO', '09': 'CT',
'10': 'DE', '11': 'DC', '12': 'FL', '13': 'GA', '15': 'HI', '16': 'ID', '17': 'IL',
'18': 'IN', '19': 'IA', '20': 'KS', '21': 'KY', '22': 'LA', '23': 'ME', '24': 'MD',
'25': 'MA', '26': 'MI', '27': 'MN', '28': 'MS', '29': 'MO', '30': 'MT', '31': 'NE',
'32': 'NV', '33': 'NH', '34': 'NJ', '35': 'NM', '36': 'NY', '37': 'NC', '38': 'ND',
'39': 'OH', '40': 'OK', '41': 'OR', '42': 'PA', '44': 'RI', '45': 'SC', '46': 'SD',
'47': 'TN', '48': 'TX', '49': 'UT', '50': 'VT', '51': 'VA', '53': 'WA', '54': 'WV',
'55': 'WI', '56': 'WY'
};
const CA_PROV_ABBR = {
'alberta': 'AB',
'british columbia': 'BC',
'manitoba': 'MB',
'new brunswick': 'NB',
'newfoundland and labrador': 'NL',
'nova scotia': 'NS',
'ontario': 'ON',
'prince edward island': 'PE',
'quebec': 'QC',
'saskatchewan': 'SK',
'northwest territories': 'NT',
'yukon': 'YT',
'nunavut': 'NU'
};
const MX_STATE_ABBR = {
'aguascalientes': 'AGS',
'baja california': 'BC',
'baja california sur': 'BCS',
'campeche': 'CAM',
'chiapas': 'CHP',
'chihuahua': 'CHH',
'coahuila': 'COA',
'colima': 'COL',
'durango': 'DUR',
'guanajuato': 'GUA',
'guerrero': 'GRO',
'hidalgo': 'HID',
'jalisco': 'JAL',
'mexico': 'MEX',
'estado de mexico': 'MEX',
'michoacan': 'MIC',
'michoacán': 'MIC',
'morelos': 'MOR',
'nayarit': 'NAY',
'nuevo leon': 'NL',
'nuevo león': 'NL',
'oaxaca': 'OAX',
'puebla': 'PUE',
'queretaro': 'QRO',
'querétaro': 'QRO',
'quintana roo': 'QR',
'san luis potosi': 'SLP',
'san luis potosí': 'SLP',
'sinaloa': 'SIN',
'sonora': 'SON',
'tabasco': 'TAB',
'tamaulipas': 'TAM',
'tlaxcala': 'TLA',
'veracruz': 'VER',
'yucatan': 'YUC',
'yucatán': 'YUC',
'zacatecas': 'ZAC'
};
const COUNTRY_COORD_OVERRIDES = {
FR: { lat: 46.2276, lon: 2.2137, label: 'France' }, // avoid overseas centroid drift
PT: { lat: 39.3999, lon: -8.2245, label: 'Portugal' }, // avoid Azores/Madeira skew
ES: { lat: 40.4637, lon: -3.7492, label: 'Spain' }, // avoid Canary Islands skew
NO: { lat: 60.472, lon: 8.4689, label: 'Norway' }, // avoid Svalbard skew
DK: { lat: 55.6761, lon: 12.5683, label: 'Denmark' }, // avoid Greenland skew
NL: { lat: 52.1326, lon: 5.2913, label: 'Netherlands' }, // avoid Aruba/Caribbean skew
DE: { lat: 51.1657, lon: 10.4515, label: 'Germany' } // mainland reference
};
function debugLog(msg, payload) {
if (!debugMode) return;
if (payload !== undefined) console.log('[map debug]', msg, payload);
else console.log('[map debug]', msg);
}
debugLog('init start', {
mapType: settings.mapType,
region: settings.region,
multiVote: settings.multiVote,
autoStart: settings.autoStart,
motion: settings.motion
});
function normalizeForMatch(input) {
if (!input && input !== 0) return '';
return input.toString()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.replace(/[^a-z0-9\s]/g, ' ')
.replace(/\s+/g, ' ')
.trim();
}
function buildVoterKey(name, source, userId) {
const normalizedSource = source ? source.toString().trim().toLowerCase() : 'unknown';
const idPart = userId ? `id:${userId}` : name ? `name:${name.toString().trim().toLowerCase()}` : 'anon';
return `${idPart}:${normalizedSource}`;
}
function derivePlaceLabel(rawInput, fallback) {
if (!rawInput && rawInput !== 0) return fallback;
const cleaned = rawInput.toString().replace(/^#+/, '').trim();
return cleaned || fallback;
}
function activeTally() {
return settings.mapType === 'country' ? countryTally : placeTally;
}
function shouldAcceptVotes() {
return ready && isEnabled && !isPaused;
}
function setStatus(text) {
if (!text) {
statusEl.classList.add('hidden');
return;
}
statusEl.textContent = text;
statusEl.classList.remove('hidden');
}
const STYLE_PRESETS = {
default: {
'--bg': 'rgba(6, 10, 16, 0.35)',
'--grid': 'rgba(255, 255, 255, 0.08)',
'--text': '#e8edf6',
'--muted': '#9fb4cf',
'--accent': '#6ef7c8',
'--accent-2': '#f4b556',
'--panel': 'rgba(14, 20, 32, 0.65)',
'--stroke': 'rgba(255, 255, 255, 0.14)',
'--country-fill': 'rgba(255, 255, 255, 0.06)',
'--country-highlight': 'rgba(255, 255, 255, 0.45)',
'--stroke-width': '0.6',
'--country-opacity': '1',
'--surface-opacity': '0.45',
'--surface-blend': 'lighten',
'--surface-rotate': '0deg',
'--surface-shift-x': '0px',
'--surface-shift-y': '0px',
'--surface-scale': '1',
'--surface-filter': 'none',
'--map-zoom': '1',
'--map-pan-x': '0px',
'--map-pan-y': '0px',
'--map-rotate': '0deg',
'--map-tilt': '0deg',
'--map-perspective': 'none',
'--map-filter': 'none',
'--panel-border': '1px solid rgba(255, 255, 255, 0.1)',
'--hud-shadow': '0 18px 60px rgba(0, 0, 0, 0.35)',
'--hud-blur': '10px',
'--status-bg': 'rgba(0, 0, 0, 0.4)',
'--status-color': '#e8edf6'
},
aurora: {
'--bg': 'radial-gradient(120% 90% at 10% 10%, rgba(114, 210, 255, 0.12), transparent), radial-gradient(90% 80% at 80% 20%, rgba(141, 255, 196, 0.14), transparent), rgba(4, 10, 18, 0.55)',
'--grid': 'rgba(255, 255, 255, 0.06)',
'--text': '#ecf7ff',
'--muted': '#a7c7e7',
'--accent': '#7fffd4',
'--accent-2': '#6bb7ff',
'--panel': 'rgba(10, 18, 32, 0.72)',
'--stroke': 'rgba(255, 255, 255, 0.16)',
'--country-fill': 'rgba(255, 255, 255, 0.08)',
'--country-highlight': '#bce5ff',
'--stroke-width': '0.8',
'--surface-opacity': '0.52',
'--surface-blend': 'screen',
'--surface-scale': '1.05',
'--surface-rotate': '-2deg',
'--surface-shift-y': '-4px',
'--map-zoom': '1.05',
'--map-pan-y': '-6px',
'--map-tilt': '2deg',
'--map-perspective': '1000px',
'--map-filter': 'drop-shadow(0 12px 28px rgba(0, 0, 0, 0.5))',
'--panel-border': '1px solid rgba(123, 207, 255, 0.22)',
'--hud-blur': '14px'
},
ember: {
'--bg': 'radial-gradient(90% 60% at 20% 20%, rgba(255, 171, 92, 0.22), transparent), radial-gradient(80% 80% at 80% 10%, rgba(255, 94, 98, 0.18), transparent), rgba(16, 8, 6, 0.68)',
'--grid': 'rgba(255, 255, 255, 0.05)',
'--text': '#fff3ec',
'--muted': '#f0cbb8',
'--accent': '#ff9f6f',
'--accent-2': '#ff5f6d',
'--panel': 'rgba(24, 12, 8, 0.75)',
'--stroke': 'rgba(255, 255, 255, 0.12)',
'--country-fill': 'rgba(255, 225, 210, 0.1)',
'--country-highlight': '#ffb48a',
'--stroke-width': '0.9',
'--surface-opacity': '0.38',
'--surface-blend': 'soft-light',
'--surface-rotate': '1deg',
'--map-zoom': '1.03',
'--map-rotate': '1deg',
'--map-filter': 'sepia(0.25) drop-shadow(0 12px 32px rgba(0, 0, 0, 0.5))',
'--panel-border': '1px solid rgba(255, 159, 111, 0.22)',
'--hud-shadow': '0 18px 55px rgba(0, 0, 0, 0.45)'
},
neon: {
'--bg': 'radial-gradient(100% 70% at 15% 15%, rgba(133, 255, 205, 0.14), transparent), radial-gradient(80% 80% at 80% 20%, rgba(97, 164, 255, 0.16), transparent), #04060a',
'--grid': 'rgba(110, 247, 200, 0.18)',
'--text': '#e9f5ff',
'--muted': '#9ac3ff',
'--accent': '#6ef7c8',
'--accent-2': '#8bd4ff',
'--panel': 'rgba(8, 12, 20, 0.75)',
'--stroke': 'rgba(110, 247, 200, 0.2)',
'--country-fill': 'rgba(255, 255, 255, 0.09)',
'--country-highlight': '#c2e9ff',
'--stroke-width': '0.8',
'--surface-opacity': '0.58',
'--surface-scale': '1.05',
'--surface-blend': 'screen',
'--surface-shift-x': '8px',
'--map-zoom': '1.08',
'--map-pan-x': '6px',
'--map-tilt': '4deg',
'--map-perspective': '1100px',
'--map-filter': 'drop-shadow(0 16px 38px rgba(0, 0, 0, 0.55)) saturate(1.1)',
'--panel-border': '1px solid rgba(110, 247, 200, 0.26)',
'--hud-blur': '14px'
},
blueprint: {
'--bg': 'radial-gradient(120% 90% at 15% 10%, rgba(48, 154, 255, 0.18), transparent), #051428',
'--grid': 'rgba(126, 196, 255, 0.25)',
'--text': '#d6e9ff',
'--muted': '#7fb4f0',
'--accent': '#8bd4ff',
'--accent-2': '#63b3ff',
'--panel': 'rgba(5, 22, 45, 0.82)',
'--stroke': 'rgba(139, 212, 255, 0.7)',
'--country-fill': 'rgba(255, 255, 255, 0.08)',
'--country-highlight': '#b7e5ff',
'--stroke-width': '1.05',
'--surface-opacity': '0.58',
'--surface-blend': 'screen',
'--surface-rotate': '-6deg',
'--surface-scale': '1.08',
'--surface-shift-x': '-12px',
'--surface-shift-y': '-8px',
'--surface-filter': 'drop-shadow(0 12px 28px rgba(0, 0, 0, 0.5))',
'--map-zoom': '1.1',
'--map-pan-y': '-10px',
'--map-rotate': '-1.8deg',
'--map-tilt': '6deg',
'--map-perspective': '1200px',
'--map-filter': 'drop-shadow(0 14px 34px rgba(0, 0, 0, 0.55))',
'--panel-border': '1px solid rgba(139, 212, 255, 0.28)',
'--hud-shadow': '0 20px 50px rgba(0, 0, 0, 0.48)',
'--hud-blur': '16px'
},
minimal: {
'--bg': 'radial-gradient(120% 80% at 12% 10%, rgba(91, 121, 182, 0.08), transparent), #f6f8fc',
'--grid': 'rgba(12, 26, 47, 0.06)',
'--text': '#0f1b2e',
'--muted': '#48607d',
'--accent': '#2d7dd2',
'--accent-2': '#8ecae6',
'--panel': 'rgba(255, 255, 255, 0.8)',
'--stroke': 'rgba(12, 26, 47, 0.16)',
'--country-fill': 'rgba(12, 26, 47, 0.08)',
'--country-highlight': 'rgba(12, 26, 47, 0.6)',
'--stroke-width': '0.8',
'--surface-opacity': '0.08',
'--surface-blend': 'multiply',
'--surface-rotate': '0deg',
'--surface-shift-y': '-6px',
'--map-zoom': '1.04',
'--map-pan-y': '-10px',
'--map-tilt': '3deg',
'--map-perspective': '900px',
'--map-filter': 'drop-shadow(0 8px 18px rgba(12, 26, 47, 0.18))',
'--panel-border': '1px solid rgba(12, 26, 47, 0.12)',
'--hud-shadow': '0 14px 38px rgba(12, 26, 47, 0.15)',
'--hud-blur': '12px',
'--status-bg': 'rgba(255, 255, 255, 0.82)',
'--status-color': '#0f1b2e'
},
retro: {
'--bg': 'radial-gradient(140% 100% at 20% 15%, rgba(255, 196, 130, 0.16), transparent), #1d1208',
'--grid': 'rgba(255, 186, 120, 0.14)',
'--text': '#f8e8d1',
'--muted': '#d0b89a',
'--accent': '#f2a65a',
'--accent-2': '#d7263d',
'--panel': 'rgba(28, 14, 6, 0.8)',
'--stroke': 'rgba(255, 230, 200, 0.18)',
'--country-fill': 'rgba(255, 230, 200, 0.1)',
'--country-highlight': '#f2a65a',
'--stroke-width': '0.9',
'--surface-opacity': '0.35',
'--surface-blend': 'soft-light',
'--surface-rotate': '3deg',
'--surface-scale': '1.04',
'--surface-filter': 'sepia(0.35)',
'--map-zoom': '1.02',
'--map-rotate': '1.5deg',
'--map-pan-x': '-6px',
'--map-pan-y': '8px',
'--map-filter': 'sepia(0.28) contrast(1.05) drop-shadow(0 12px 28px rgba(0, 0, 0, 0.45))',
'--panel-border': '1px solid rgba(242, 166, 90, 0.22)',
'--hud-shadow': '0 18px 48px rgba(0, 0, 0, 0.45)',
'--hud-blur': '10px'
},
radar: {
'--bg': 'radial-gradient(120% 90% at 50% 50%, rgba(16, 96, 80, 0.28), #03100c)',
'--grid': 'rgba(110, 247, 200, 0.18)',
'--text': '#dff7ed',
'--muted': '#96c7ad',
'--accent': '#7fffd4',
'--accent-2': '#00ffc3',
'--panel': 'rgba(4, 18, 14, 0.78)',
'--stroke': 'rgba(127, 255, 212, 0.22)',
'--country-fill': 'rgba(0, 255, 195, 0.08)',
'--country-highlight': '#a0ffe0',
'--stroke-width': '0.75',
'--surface-opacity': '0.62',
'--surface-blend': 'lighten',
'--surface-scale': '1.02',
'--surface-shift-x': '16px',
'--surface-shift-y': '-6px',
'--map-zoom': '1.12',
'--map-pan-x': '6px',
'--map-perspective': '1100px',
'--map-tilt': '5deg',
'--map-filter': 'saturate(1.2) contrast(1.15) drop-shadow(0 16px 40px rgba(0, 0, 0, 0.55))',
'--panel-border': '1px solid rgba(127, 255, 212, 0.18)',
'--hud-shadow': '0 16px 44px rgba(0, 0, 0, 0.52)',
'--hud-blur': '14px'
}
};
function applyStylePreset(presetName) {
const base = STYLE_PRESETS.default;
const preset = STYLE_PRESETS[presetName] || base;
Object.entries(base).forEach(([key, value]) => {
document.documentElement.style.setProperty(key, value);
});
if (preset !== base) {
Object.entries(preset).forEach(([key, value]) => {
document.documentElement.style.setProperty(key, value);
});
}
document.body.dataset.mapStyle = presetName in STYLE_PRESETS ? presetName : 'default';
}
function applyMotionPreference(enabled) {
document.body.classList.toggle('motion-drift', !!enabled);
}
applyStylePreset(settings.mapStyle);
applyMotionPreference(settings.motion);
// Apply map scale is called after hudEl is defined
if (settings.accent) document.documentElement.style.setProperty('--accent', settings.accent);
if (settings.accentAlt) document.documentElement.style.setProperty('--accent-2', settings.accentAlt);
const REGION_PRESETS = {
global: (meta) => true,
northamerica: (meta) => {
if (meta.iso === 'MX') return true; // ensure Mexico is included
return meta.region === 'Americas' && ['Northern America', 'Caribbean', 'Central America', 'Latin America and the Caribbean'].includes(meta.subRegion);
},
southamerica: (meta) => meta.region === 'Americas' && meta.subRegion === 'South America',
europe: (meta) => meta.region === 'Europe',
asia: (meta) => meta.region === 'Asia',
africa: (meta) => meta.region === 'Africa',
oceania: (meta) => meta.region === 'Oceania'
};
const VALID_REGION_KEYS = new Set(Object.keys(REGION_PRESETS));
const REGION_EXCLUDES = {
northamerica: new Set(['GL', 'NU', 'NT', 'YT']), // avoid Greenland and far north territories dominating the viewport
europe: new Set(['RU', 'SJ']) // trim Russia + Svalbard from Europe framing
};
const REGION_LONGITUDE_CENTERS = {
northamerica: -100
};
const REGION_VIEWBOXES = {
northamerica: { west: -170, east: -50, south: 5, north: 75 },
europe: { west: -25, east: 45, south: 30, north: 72 }
};
const normalizedFeatureCache = new WeakMap();
function buildRegionSets() {
regionSets = new Map();
Object.entries(REGION_PRESETS).forEach(([key, matcher]) => {
const set = new Set();
for (const [iso, meta] of isoMeta.entries()) {
if (matcher(meta)) {
if (REGION_EXCLUDES[key] && REGION_EXCLUDES[key].has(iso)) continue;
set.add(iso);
}
}
regionSets.set(key, set);
});
}
function normalizeRegionKey(value) {
if (!value) return 'global';
const key = value.toString().trim().toLowerCase();
const aliases = {
'north-america': 'northamerica',
'north_america': 'northamerica',
'north america': 'northamerica',
na: 'northamerica',
'south-america': 'southamerica',
'south_america': 'southamerica',
'south america': 'southamerica',
sa: 'southamerica',
eu: 'europe',
apac: 'asia',
'asia-pacific': 'asia'
};
const normalized = aliases[key] || key;
if (VALID_REGION_KEYS.has(normalized)) return normalized;
if (VALID_REGION_KEYS.has(key)) return key;
if (regionSets.has(key)) return key;
if (regionSets.has(normalized)) return normalized;
return 'global';
}
function isIsoAllowedForRegion(iso, regionKey = settings.region) {
if (!iso) return true;
const isoUpper = iso.toString().toUpperCase();
const key = regionKey || 'global';
const set = regionSets.get(key);
if (!set || !set.size) return true;
return set.has(isoUpper);
}
function isIsoAllowed(iso) {
return isIsoAllowedForRegion(iso, settings.region);
}
function getVisibleFeatures() {
const regionKey = settings.region || 'global';
if (regionKey === 'global') return atlasFeatures;
const set = regionSets.get(regionKey);
if (!set || !set.size) return atlasFeatures;
const filtered = atlasFeatures.filter(feature => {
const iso = feature.properties.iso_a2;
if (!iso) return false;
return set.has(iso);
});
return filtered.length ? filtered : atlasFeatures;
}
function getStateFeaturesForRegion() {
if (!stateFeatures.length) return [];
const filtered = stateFeatures.filter(feature => {
const iso = feature.properties.iso_a2 || feature.properties.iso;
return isIsoAllowed(iso);
});
if (settings.region === 'northamerica') {
const exclude = new Set(['Nunavut', 'Northwest Territories', 'Yukon']);
return filtered.filter(f => !exclude.has(f.properties.name));
}
return filtered;
}
function getActiveFeatures() {
if (settings.mapType === 'state') {
const filtered = getStateFeaturesForRegion();
if (filtered.length) return filtered;
}
return getVisibleFeatures();
}
function wrapLongitude(lon, center) {
if (center === undefined) return lon;
let adjusted = lon;
while (adjusted - center > 180) adjusted -= 360;
while (center - adjusted > 180) adjusted += 360;
return adjusted;
}
function normalizeCoordinates(coords, center) {
if (typeof coords[0] === 'number') {
return [wrapLongitude(coords[0], center), coords[1]];
}
return coords.map(part => normalizeCoordinates(part, center));
}
function normalizeFeatureGeometry(feature, center) {
if (!feature || center === undefined) return feature;
let cache = normalizedFeatureCache.get(feature);
if (!cache) {
cache = new Map();
normalizedFeatureCache.set(feature, cache);
}
if (cache.has(center)) return cache.get(center);
const normalized = {
...feature,
geometry: {
...feature.geometry,
coordinates: normalizeCoordinates(feature.geometry.coordinates, center)
}
};
cache.set(center, normalized);
return normalized;
}
function featureForProjection(feature) {
const center = REGION_LONGITUDE_CENTERS[settings.region];
if (center === undefined) return feature;
return normalizeFeatureGeometry(feature, center);
}
function normalizeCollectionForRegion(featureCollection) {
const center = REGION_LONGITUDE_CENTERS[settings.region];
if (center === undefined) return featureCollection;
return {
type: 'FeatureCollection',
features: featureCollection.features.map(f => featureForProjection(f)).filter(Boolean)
};
}
function boundsToFeatureCollection(bounds) {
if (!bounds) return null;
const { west, east, south, north } = bounds;
if (![west, east, south, north].every(Number.isFinite)) return null;
return {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Polygon',
// Use clockwise ring order so d3 treats the rectangle as the interior rather than the inverted globe
coordinates: [[[west, south], [west, north], [east, north], [east, south], [west, south]]]
},
properties: { kind: 'viewport-bounds' }
}]
};
}
function getRegionBoundsCollection() {
const bounds = REGION_VIEWBOXES[settings.region];
if (!bounds) return null;
return boundsToFeatureCollection(bounds);
}
function clampBoundsToRegion(bounds) {
if (!bounds) return null;
const regionBox = REGION_VIEWBOXES[settings.region];
if (!regionBox) return bounds;
return {
west: Math.max(bounds.west, regionBox.west),
east: Math.min(bounds.east, regionBox.east),
south: Math.max(bounds.south, regionBox.south),
north: Math.min(bounds.north, regionBox.north)
};
}
function getMarkerBoundsCollection(tallyOverride = null) {
const tally = tallyOverride || activeTally();
const entries = Array.from(tally.values()).filter(entry => entry.count > 0);
if (!entries.length) return null;
let west = Infinity;
let east = -Infinity;
let south = Infinity;
let north = -Infinity;
const pushBounds = (w, e, s, n) => {
if (!Number.isFinite(w) || !Number.isFinite(e) || !Number.isFinite(s) || !Number.isFinite(n)) return;
west = Math.min(west, w);
east = Math.max(east, e);
south = Math.min(south, s);
north = Math.max(north, n);
};
entries.forEach(entry => {
if (entry.coord) {
pushBounds(entry.coord.lon, entry.coord.lon, entry.coord.lat, entry.coord.lat);