-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.html
More file actions
542 lines (506 loc) · 25.6 KB
/
index.html
File metadata and controls
542 lines (506 loc) · 25.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="preconnect" href="https://unpkg.com" crossorigin>
<link rel="preconnect" href="https://a.basemaps.cartocdn.com" crossorigin>
<link rel="preconnect" href="https://b.basemaps.cartocdn.com" crossorigin>
<link rel="preconnect" href="https://c.basemaps.cartocdn.com" crossorigin>
<link rel="preconnect" href="https://d.basemaps.cartocdn.com" crossorigin>
<link rel="dns-prefetch" href="https://unpkg.com">
<link rel="dns-prefetch" href="https://a.basemaps.cartocdn.com">
<link rel="dns-prefetch" href="https://b.basemaps.cartocdn.com">
<link rel="dns-prefetch" href="https://c.basemaps.cartocdn.com">
<link rel="dns-prefetch" href="https://d.basemaps.cartocdn.com">
<title>MXmap — Email Providers of Swiss Municipalities</title>
<meta name="description" content="Interactive map showing the email providers of all ~2,100 Swiss municipalities, based on DNS analysis of MX and SPF records.">
<meta name="keywords" content="Switzerland, municipalities, email, sovereignty, CLOUD Act, MX records, SPF, DNS, Microsoft 365, Google Workspace, digital sovereignty, data protection">
<meta name="author" content="David Huser">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://mxmap.ch/">
<meta property="og:type" content="website">
<meta property="og:title" content="MXmap — Email Providers of Swiss Municipalities">
<meta property="og:description" content="Interactive map showing where Swiss municipalities host their official email. DNS analysis of all ~2,100 municipalities, color-coded by provider.">
<meta property="og:url" content="https://mxmap.ch/">
<meta property="og:locale" content="en_CH">
<meta property="og:site_name" content="MXmap">
<meta property="og:image" content="https://mxmap.ch/og-image.jpg">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="MXmap — Email Providers of Swiss Municipalities">
<meta name="twitter:description" content="Interactive map showing where Swiss municipalities host their official email. DNS analysis of all ~2,100 municipalities.">
<meta name="twitter:image" content="https://mxmap.ch/og-image.jpg">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='2' y='7' width='28' height='18' rx='2' fill='%231a1a2e'/%3E%3Cpath d='M2 9l14 9 14-9' fill='none' stroke='%2316a34a' stroke-width='2'/%3E%3C/svg%3E">
<link rel="stylesheet" href="css/shared.css">
<link rel="stylesheet" href="css/map.css">
<link rel="preload" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"></noscript>
<script defer src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script defer src="https://unpkg.com/topojson-client@3/dist/topojson-client.min.js"></script>
<script defer src="js/nav.js"></script>
<script defer src="js/map-shared.js"></script>
</head>
<body>
<header id="header">
<div class="header-left">
<h1 class="brand">MXmap</h1>
<span class="beta-badge" title="Beta status, this website may contain errors">beta</span>
<nav id="nav"></nav>
</div>
<span class="header-disclaimer">⚠ This data may be out of date or incorrect. A research project is ongoing to further develop such maps.</span>
<div class="header-right">
<button class="toggle-info" id="toggle-info" aria-expanded="true" aria-controls="info-bar">About ▴</button>
</div>
</header>
<section id="info-bar" aria-label="About this project">
<script>if(window.innerWidth<=600)document.getElementById('info-bar').classList.add('collapsed');</script>
<h2 class="info-title">Email Providers of Swiss Municipalities</h2>
<div class="info-grid">
<div class="info-card">
<h3>What is this?</h3>
<p>A map of all ~2,100 Swiss municipalities showing which provider handles their official email — grouped by jurisdiction — based on public DNS records and other public network signals.</p>
</div>
<div class="info-card">
<h3>Context</h3>
<p>Digital sovereignty: US-based providers are subject to the US CLOUD Act, which allows US authorities to request stored data, regardless of where it is physically hosted. This map makes the current provider landscape visible.</p>
</div>
<div class="info-card">
<h3>How does it work?</h3>
<p>Each municipality's official domain is checked via 11 signals from DNS records, SMTP banners, ASN lookups, and a public Microsoft API endpoint, then classified by provider type with confidence scoring.</p>
<p style="font-size:12px;color:#777;margin-top:6px;">Disclaimer: DNS records indicate mail routing and authorized senders, not necessarily where data is stored.</p>
</div>
<div class="info-card">
<h3>Open source & open data</h3>
<p>The code and data are on <a href="https://github.com/davidhuser/mxmap" target="_blank">GitHub</a>.<br>
If you have noticed an error, please <a href="https://github.com/davidhuser/mxmap/issues" target="_blank">submit an issue</a>.</p>
<p id="generated"></p>
</div>
</div>
</section>
<main id="map" role="application" aria-label="Interactive map of Swiss municipality email providers">
<div id="map-loading" style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;z-index:1000;background:rgba(255,255,255,0.85);font-size:15px;color:#555;">Loading map data…</div>
</main>
<script>
document.addEventListener('DOMContentLoaded', function () {
const COLOR_SCHEMES = {
default: {
'us-cloud': { high: '#ffa199', medium: '#ffccb6', low: '#cccccc' },
'swiss-based': { high: '#88faaa', medium: '#daffc2', low: '#cccccc' },
lake: '#89B3D6',
},
colorblind: {
'us-cloud': { high: '#f1be61', medium: '#fde7c4', low: '#cccccc' },
'swiss-based': { high: '#6fa2d0', medium: '#C0D8E8', low: '#cccccc' },
lake: '#c4afff',
},
};
var CATEGORY_COLORS = COLOR_SCHEMES.default;
const GRAY = '#BFBFBF';
const CANTON_CODES = {
'Kanton Zürich': 'ZH', 'Kanton Bern': 'BE', 'Kanton Luzern': 'LU',
'Kanton Uri': 'UR', 'Kanton Schwyz': 'SZ', 'Kanton Obwalden': 'OW',
'Kanton Nidwalden': 'NW', 'Kanton Glarus': 'GL', 'Kanton Zug': 'ZG',
'Kanton Freiburg': 'FR', 'Kanton Solothurn': 'SO', 'Kanton Basel-Stadt': 'BS',
'Kanton Basel-Landschaft': 'BL', 'Kanton Schaffhausen': 'SH',
'Kanton Appenzell Ausserrhoden': 'AR', 'Kanton Appenzell Innerrhoden': 'AI',
'Kanton St. Gallen': 'SG', 'Kanton Graubünden': 'GR', 'Kanton Aargau': 'AG',
'Kanton Thurgau': 'TG', 'Kanton Tessin': 'TI', 'Kanton Waadt': 'VD',
'Kanton Wallis': 'VS', 'Kanton Neuenburg': 'NE', 'Kanton Genf': 'GE',
'Kanton Jura': 'JU'
};
const LABELS = {
microsoft: 'Microsoft 365',
google: 'Google Workspace',
aws: 'Amazon Web Services',
infomaniak: 'Infomaniak',
'swiss-isp': 'Swiss ISP',
'independent': 'Self-hosted / Other',
unknown: 'Unknown'
};
function effectiveCategory(m) {
if (!m || !m.category || m.category === 'unknown') return null;
return m.category;
}
function confidenceLevel(confidence) {
if (confidence >= 90) return 'high';
if (confidence >= 60) return 'medium';
if (confidence >= 30) return 'low';
return 'insufficient'
}
function getColor(m) {
const cat = effectiveCategory(m);
if (!cat) return GRAY;
const level = confidenceLevel(m.classification_confidence || 0);
if (level === 'insufficient') return GRAY;
return CATEGORY_COLORS[cat][level];
}
function classifyHost(host) {
const h = host.toLowerCase();
// Hyperscalers
if (['mail.protection.outlook.com','outlook.com','microsoft','office365','onmicrosoft','spf.protection.outlook.com','sharepointonline'].some(k => h.includes(k)))
return { name: 'Microsoft', category: 'hyperscaler' };
if (['google','googlemail','gmail','aspmx.l.google.com','_spf.google.com'].some(k => h.includes(k)))
return { name: 'Google', category: 'hyperscaler' };
if (['amazonaws','amazonses','awsdns'].some(k => h.includes(k)))
return { name: 'AWS', category: 'hyperscaler' };
// Swiss (explicit)
if (['infomaniak','mxpool.infomaniak'].some(k => h.includes(k)))
return { name: 'Infomaniak', category: 'swiss' };
// Foreign senders
if (['mandrillapp.com','mandrill','mcsv.net'].some(k => h.includes(k)))
return { name: 'Mailchimp', category: 'foreign' };
if (h.includes('sendgrid'))
return { name: 'SendGrid', category: 'foreign' };
if (h.includes('mailjet'))
return { name: 'Mailjet', category: 'foreign' };
if (h.includes('mailgun'))
return { name: 'Mailgun', category: 'foreign' };
if (['sendinblue','brevo'].some(k => h.includes(k)))
return { name: 'Brevo', category: 'foreign' };
if (h.includes('mailchannels'))
return { name: 'MailChannels', category: 'foreign' };
if (h.includes('smtp2go'))
return { name: 'SMTP2GO', category: 'foreign' };
if (h.includes('nl2go'))
return { name: 'Newsletter2Go', category: 'foreign' };
if (h.includes('hubspotemail'))
return { name: 'HubSpot', category: 'foreign' };
if (h.includes('knowbe4'))
return { name: 'KnowBe4', category: 'foreign' };
if (['sophos','sophosxl'].some(k => h.includes(k)))
return { name: 'Sophos', category: 'foreign' };
if (h.includes('trendmicro'))
return { name: 'Trend Micro', category: 'foreign' };
if (['hornetsecurity','hornetdmarc'].some(k => h.includes(k)))
return { name: 'Hornetsecurity', category: 'foreign' };
if (h.includes('barracudanetworks'))
return { name: 'Barracuda', category: 'foreign' };
if (h.includes('mlsend'))
return { name: 'MailerLite', category: 'foreign' };
if (h.includes('createsend'))
return { name: 'Campaign Monitor', category: 'foreign' };
if (h.includes('exclaimer'))
return { name: 'Exclaimer', category: 'foreign' };
if (h.includes('turbo-smtp'))
return { name: 'turboSMTP', category: 'foreign' };
if (h.includes('letsignit'))
return { name: 'Letsignit', category: 'foreign' };
if (h.includes('codetwo'))
return { name: 'CodeTwo', category: 'foreign' };
if (h.includes('freshservice'))
return { name: 'Freshservice', category: 'foreign' };
// Email security gateways
if (['ppe-hosted','pphosted'].some(k => h.includes(k)))
return { name: 'Proofpoint', category: 'foreign' };
if (h.includes('vadesecure'))
return { name: 'Vade Secure', category: 'foreign' };
if (h.includes('fortimailcloud'))
return { name: 'Fortinet FortiMail', category: 'foreign' };
if (h.includes('spamtitan'))
return { name: 'SpamTitan', category: 'foreign' };
if (['spamexperts','antispamcloud'].some(k => h.includes(k)))
return { name: 'SpamExperts', category: 'foreign' };
if (h.includes('iphmx'))
return { name: 'Cisco IronPort', category: 'foreign' };
if (h.includes('mailcontrol'))
return { name: 'MailControl', category: 'foreign' };
if (h.includes('mimecast'))
return { name: 'Mimecast', category: 'foreign' };
if (h.includes('messagelabs'))
return { name: 'MessageLabs', category: 'foreign' };
// Email routing / hosting
if (h.includes('mtaroutes'))
return { name: 'MTARoutes', category: 'foreign' };
if (h.includes('jimdo'))
return { name: 'Jimdo', category: 'foreign' };
if (h.includes('arsmtp'))
return { name: 'Aruba', category: 'foreign' };
if (h.includes('stackmail'))
return { name: 'StackMail', category: 'foreign' };
// SPF-only services
if (h.includes('umantis'))
return { name: 'Haufe', category: 'foreign' };
if (['emailsignatures365','signature365'].some(k => h.includes(k)))
return { name: 'Email Signatures 365', category: 'foreign' };
if (h.includes('crsend'))
return { name: 'CleverReach', category: 'foreign' };
if (h.includes('mailersend'))
return { name: 'MailerSend', category: 'foreign' };
if (h.includes('emailsrvr'))
return { name: 'Rackspace', category: 'foreign' };
if (h.includes('edgepilot'))
return { name: 'EdgePilot', category: 'foreign' };
if (h.includes('appriver'))
return { name: 'AppRiver', category: 'foreign' };
if (h.includes('scnem'))
return { name: 'Evalanche', category: 'foreign' };
if (h.includes('rubicon.eu'))
return { name: 'Rubicon', category: 'foreign' };
// Known Swiss providers with non-.ch TLDs
const SWISS_DOMAINS = [
'abxsec.com','swiss-egov.cloud','sui-inter.net','ch-dns.net','cyon.net',
'seppmail.cloud','swisscom.com','privasphere.com','tinext.com','cloudrexx.com',
'mailomat.cloud','comp-sys.net','engadin.cloud','ti-informatique.com',
'assolo.net','moresi.com',
'naveum.services','spamvor.com','swisscenter.com','seabix.cloud',
'swizzonic.email','tinext.net','hosttech.eu','mailpro.com','tizoo.com'
];
if (SWISS_DOMAINS.some(d => h.endsWith(d) || h.endsWith('.' + d)))
return { name: h.replace(/^_/, '').split('.').slice(-2).join('.'), category: 'swiss' };
// TLD-based fallback
const parts = host.replace(/^_/, '').split('.');
const name = parts.length >= 2 ? parts.slice(-2).join('.') : host;
if (h.endsWith('.ch') || h.endsWith('.swiss'))
return { name, category: 'swiss' };
return { name, category: 'unknown' };
}
function parseSpfDelegations(spf) {
if (!spf) return [];
const results = [];
const includeRe = /include:([^\s]+)/g;
let m;
while ((m = includeRe.exec(spf)) !== null) results.push(m[1]);
const redirectRe = /redirect=([^\s]+)/g;
while ((m = redirectRe.exec(spf)) !== null) results.push(m[1]);
return results;
}
function renderTable(hosts) {
const rows = hosts.map(host => {
const cls = classifyHost(host);
const eName = escapeHtml(cls.name);
const eCat = escapeHtml(cls.category);
const eHost = escapeHtml(host);
return `<tr><td class="dn">${eName}</td><td><span class="cat-badge ${eCat}">${eCat}</span></td><td class="host" title="${eHost}">${eHost}</td></tr>`;
}).join('');
return `<table class="dns-table">${rows}</table>`;
}
const SIGNAL_LABELS = {
mx: 'MX', spf: 'SPF', dkim: 'DKIM', asn: 'ASN',
tenant: 'Tenant', spf_ip: 'SPF IP', txt_verification: 'TXT',
autodiscover: 'Autodisc.', dmarc: 'DMARC', cname_chain: 'CNAME', smtp: 'SMTP'
};
function deduplicateSignals(signals) {
const seen = new Map();
for (const s of signals) {
const key = s.kind + '|' + s.detail;
if (seen.has(key)) {
seen.get(key).count++;
} else {
seen.set(key, { kind: s.kind, provider: s.provider, weight: s.weight, detail: s.detail, count: 1 });
}
}
return Array.from(seen.values()).sort((a, b) => b.weight - a.weight);
}
function condenseDetail(kind, detail) {
var m;
switch (kind) {
case 'mx':
m = detail.match(/^MX\s+(\S+)\s+matches\s+\S+$/);
return m ? m[1] : detail;
case 'spf':
m = detail.match(/^SPF\s+include:(\S+)\s+matches\s+\S+$/);
return m ? m[1] : detail;
case 'dkim':
m = detail.match(/^DKIM\s+(selector\d+)\._domainkey\.\S+\s+CNAME\s+→\s+\S+\._domainkey\.(\S+)$/);
return m ? m[1] + ' \u2192 ' + m[2] : detail;
case 'asn':
m = detail.match(/^ASN\s+(\d+)\s+matches\s+\S+$/);
if (m) return 'AS' + m[1];
m = detail.match(/^ASN\s+(\d+)\s+is Swiss ISP:\s+(.+)$/);
if (m) return 'AS' + m[1] + ' (' + m[2] + ')';
return detail;
case 'tenant':
m = detail.match(/^MS365 tenant detected:\s+(.+)$/);
return m ? m[1] : detail;
case 'autodiscover':
m = detail.match(/^autodiscover\s+(CNAME|SRV)\s+→\s+(.+)$/);
if (m) return (m[1] === 'CNAME' ? '\u2192 ' : m[1] + ' \u2192 ') + m[2];
return detail;
case 'txt_verification':
m = detail.match(/^TXT verification matches\s+(\S+)$/);
if (m) return m[1];
if (detail.includes('AWS SES')) return 'AWS SES';
return detail;
case 'spf_ip':
m = detail.match(/ASN\s+(\d+)\s+is Swiss ISP:\s+(.+)$/);
if (m) return 'AS' + m[1] + ' (' + m[2] + ')';
m = detail.match(/ASN\s+(\d+)\s+matches\s+(\S+)$/);
if (m) return 'AS' + m[1];
return detail;
case 'dmarc':
m = detail.match(/^DMARC record\s+(.+)$/);
return m ? m[1] : detail;
default:
return detail;
}
}
const map = initMap('map');
setupInfoBar(map);
const isMobile = window.innerWidth <= 600;
// Toggle collapsible popup sections (inline onclick, bypasses Leaflet event interception)
window.toggleSection = function(el) {
el.classList.toggle('popup-toggle-open');
var body = el.nextElementSibling;
body.style.display = body.style.display === 'none' ? '' : 'none';
};
var muni = {};
var muniLayer;
var lakeLayer;
function toggleColorScheme() {
var isDefault = CATEGORY_COLORS === COLOR_SCHEMES.default;
CATEGORY_COLORS = isDefault ? COLOR_SCHEMES.colorblind : COLOR_SCHEMES.default;
muniLayer.eachLayer(function (layer) {
var bfs = String(layer.feature.id);
var m = muni[bfs];
layer.setStyle({ fillColor: getColor(m) });
});
if (lakeLayer) {
lakeLayer.setStyle({ fillColor: CATEGORY_COLORS.lake });
}
document.querySelectorAll('.legend-swatch').forEach(function (el) {
el.style.background = CATEGORY_COLORS[el.dataset.cat][el.dataset.level];
});
var btn = document.querySelector('.color-toggle');
btn.textContent = isDefault ? '\u25D0 Default colors' : '\u25D0 Colorblind mode';
}
function legendCategoryHtml(label, colors, count, catKey, levels) {
return `<div class="legend-group">` +
`<span class="legend-group-label">${label} (${count})</span>` +
`<i class="legend-swatch" data-cat="${catKey}" data-level="high" style="background:${colors.high}"></i>High confidence (${levels.high})<br>` +
`<i class="legend-swatch" data-cat="${catKey}" data-level="medium" style="background:${colors.medium}"></i>Medium (${levels.medium})<br>` +
`<i class="legend-swatch" data-cat="${catKey}" data-level="low" style="background:${colors.low}"></i>Low (${levels.low})` +
`</div>`;
}
async function loadData() {
const { topo, dnsData } = await fetchMapData();
muni = dnsData.municipalities;
showGenerated(dnsData);
// Count by jurisdiction and confidence level
const catCounts = { 'us-cloud': 0, 'swiss-based': 0, 'insufficient': 0 };
const levelCounts = {
'us-cloud': { high: 0, medium: 0, low: 0 },
'swiss-based': { high: 0, medium: 0, low: 0 }
};
for (const bfs of Object.keys(muni)) {
const m = muni[bfs];
const cat = effectiveCategory(m);
if (cat) {
catCounts[cat]++;
const level = confidenceLevel(m ? (m.classification_confidence || 0) : 0);
if (level !== 'insufficient') levelCounts[cat][level]++;
} else {
catCounts['insufficient']++;
}
}
const hatchSvg = 'data:image/svg+xml,' +
encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect width="8" height="8" fill="#BFBFBF"/><path d="M-1,1 l2,-2 M0,8 l8,-8 M7,9 l2,-2" stroke="#000" stroke-width="1"/></svg>');
// Legend with counts
const isMobile = window.innerWidth <= 600;
const legend = L.control({ position: isMobile ? 'topright' : 'bottomright' });
legend.onAdd = function () {
const div = L.DomUtil.create('div', 'legend');
if (isMobile) div.classList.add('legend-collapsed');
div.innerHTML =
'<button class="legend-toggle" aria-label="Toggle legend" aria-expanded="' + (!isMobile) + '">' + (isMobile ? 'Legend \u25B8' : '') + '</button>' +
'<div class="legend-content">' +
'<strong>Email Jurisdiction</strong>' +
legendCategoryHtml('US Cloud', CATEGORY_COLORS['us-cloud'], catCounts['us-cloud'], 'us-cloud', levelCounts['us-cloud']) +
legendCategoryHtml('Swiss Based', CATEGORY_COLORS['swiss-based'], catCounts['swiss-based'], 'swiss-based', levelCounts['swiss-based']) +
'<div class="legend-group"><i style="background-image:url(\'' + hatchSvg + '\')"></i>Insufficient data (' + catCounts['insufficient'] + ')</div>' +
'<button class="color-toggle" aria-label="Switch to colorblind-safe colors">\u25D0 Colorblind mode</button>' +
'</div>';
L.DomEvent.disableClickPropagation(div);
return div;
};
legend.addTo(map);
document.querySelector('.legend-toggle').addEventListener('click', toggleLegend);
document.querySelector('.color-toggle').addEventListener('click', toggleColorScheme);
// Render lakes
lakeLayer = addLakes(map, topo, CATEGORY_COLORS.lake);
// Render municipalities
const geojson = topojson.feature(topo, topo.objects.municipalities);
muniLayer = L.geoJSON(geojson, {
style: function (feature) {
const bfs = String(feature.id);
const m = muni[bfs];
return {
fillColor: getColor(m),
weight: 0.6,
color: '#666',
fillOpacity: 1
};
},
onEachFeature: function (feature, layer) {
const bfs = String(feature.id);
const m = muni[bfs];
if (!m) {
layer.bindPopup(`<div class="info-popup"><strong>BFS ${bfs}</strong><br>No data</div>`);
return;
}
const color = getColor(m);
const cat = effectiveCategory(m);
const level = confidenceLevel(m.classification_confidence || 0);
const textColor = '#000';
const label = LABELS[m.provider] || m.provider;
const showBody = isMobile ? 'display:none' : '';
let mxSection = '';
if (m.mx && m.mx.length > 0) {
mxSection = `<div class="popup-section"><div class="popup-toggle${isMobile ? '' : ' popup-toggle-open'}" onclick="window.toggleSection(this)">Incoming mail handled by <span class="popup-section-hint">(MX)</span></div><div class="popup-section-body" style="${showBody}">${renderTable(m.mx)}</div></div>`;
} else {
mxSection = `<div class="popup-section"><div class="popup-toggle${isMobile ? '' : ' popup-toggle-open'}" onclick="window.toggleSection(this)">Incoming mail handled by <span class="popup-section-hint">(MX)</span></div><div class="popup-section-body" style="${showBody}"><span class="popup-empty">No MX records found</span></div></div>`;
}
const spfDelegations = parseSpfDelegations(m.spf);
let spfSection = '';
if (spfDelegations.length > 0) {
spfSection = `<div class="popup-section"><div class="popup-toggle${isMobile ? '' : ' popup-toggle-open'}" onclick="window.toggleSection(this)">Authorized to send mail <span class="popup-section-hint">(SPF)</span></div><div class="popup-section-body" style="${showBody}">${renderTable(spfDelegations)}</div></div>`;
} else if (m.spf) {
spfSection = `<div class="popup-section"><div class="popup-toggle${isMobile ? '' : ' popup-toggle-open'}" onclick="window.toggleSection(this)">Authorized to send mail <span class="popup-section-hint">(SPF)</span></div><div class="popup-section-body" style="${showBody}"><span class="popup-empty">${escapeHtml(m.spf)}</span></div></div>`;
} else {
spfSection = `<div class="popup-section"><div class="popup-toggle${isMobile ? '' : ' popup-toggle-open'}" onclick="window.toggleSection(this)">Authorized to send mail <span class="popup-section-hint">(SPF)</span></div><div class="popup-section-body" style="${showBody}"><span class="popup-empty">No SPF record found</span></div></div>`;
}
const confidence = m.classification_confidence != null ? m.classification_confidence : 0;
const confPct = Math.round(confidence) + '%';
let signalsSection = '';
if (m.classification_signals && m.classification_signals.length > 0) {
const deduped = deduplicateSignals(m.classification_signals);
const uniqueCount = deduped.length;
const signalItems = deduped.map(s => {
const kindLabel = SIGNAL_LABELS[s.kind] || s.kind;
const condensed = condenseDetail(s.kind, s.detail);
const dup = s.count > 1 ? `<span class="signal-dup">\u00d7${s.count}</span>` : '';
return `<div class="signal-item" title="${escapeHtml(s.detail).replace(/"/g, '"')}"><span class="signal-kind">${escapeHtml(kindLabel)}</span><span class="signal-text">${escapeHtml(condensed)}</span>${dup}</div>`;
}).join('');
signalsSection = `<div class="popup-section"><div class="popup-toggle" onclick="window.toggleSection(this)">Classification signals <span class="popup-signal-count" title="DNS and network evidence used to identify the email provider">${uniqueCount}</span></div><div class="popup-section-body" style="display:none"><div class="signal-list">${signalItems}</div></div></div>`;
} else {
signalsSection = `<div class="popup-section"><div class="popup-toggle" onclick="window.toggleSection(this)">Classification signals</div><div class="popup-section-body" style="display:none"><span class="popup-empty">No classification signals</span></div></div>`;
}
const eName = escapeHtml(m.name);
const cantonCode = CANTON_CODES[m.canton] || '';
const nameDisplay = cantonCode ? `${eName} (${cantonCode})` : eName;
const eDomain = escapeHtml(m.domain || 'unknown');
const eLabel = escapeHtml(label);
const badge = `<span class="provider-badge" style="background:${color};color:${textColor}">${eLabel}</span>`;
const metaParts = [`Confidence: ${confPct}`];
if (m.gateway) metaParts.push(`Gateway: ${escapeHtml(m.gateway)}`);
const metaLine = `<div class="popup-meta">${metaParts.join(' · ')}</div>`;
layer.bindPopup(
`<div class="info-popup">` +
`<strong>${nameDisplay}</strong><br>` +
`${eDomain} ${badge}` +
metaLine +
mxSection + spfSection + signalsSection +
`</div>`,
{ maxWidth: isMobile ? 300 : 450 }
);
layer.on('mouseover', function () { this.setStyle({ weight: 2, color: '#333' }); });
layer.on('mouseout', function () { this.setStyle({ weight: 0.5, color: '#666' }); });
}
}).addTo(map);
removeLoading();
map.invalidateSize({ animate: false });
}
loadData().catch(handleLoadError);
});
</script>
</body>
</html>