All checks were successful
Deploy Internet for Kids / Build & Push (push) Successful in 14s
Deploy Internet for Kids / Deploy (push) Successful in 7s
Deploy Internet for Kids / Health Check (push) Successful in 2s
Deploy Internet for Kids / Smoke Tests (push) Successful in 3s
Deploy Internet for Kids / IndexNow Ping (push) Successful in 8s
Deploy Internet for Kids / Promote to Latest (push) Successful in 2s
Deploy Internet for Kids / Rollback (push) Has been skipped
Deploy Internet for Kids / Audit (push) Successful in 2s
Canvas renders as single bitmap at devicePixelRatio-matched dimensions. No SVG, no CSS transforms, no GPU scaling = no compositor tile seams. Full redraw on zoom/pan with canvas isPointInPath hit testing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
328 lines
15 KiB
HTML
328 lines
15 KiB
HTML
{{ $lang := .Page.Language.Lang }}
|
|
{{ $countries := hugo.Data.countries }}
|
|
|
|
<style>
|
|
.ifk-map-wrap { max-width: 100%; margin: 2rem 0; }
|
|
.ifk-map-wrap h3 { text-align: center; margin-bottom: 0.5rem; font-size: 1.25rem; }
|
|
.ifk-map-subtitle { text-align: center; color: #666; font-size: 0.85rem; margin-bottom: 1rem; }
|
|
.ifk-map-container { position: relative; width: 100%; height: 420px; border-radius: 8px; overflow: hidden; }
|
|
.ifk-map-canvas { width: 100%; height: 100%; display: block; cursor: grab; image-rendering: auto; }
|
|
.ifk-map-canvas:active { cursor: grabbing; }
|
|
.ifk-map-controls { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 10; }
|
|
.ifk-map-controls button { width: 30px; height: 30px; background: #fff; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #333; }
|
|
.ifk-map-controls button:hover { background: #f0f0f0; }
|
|
.ifk-map-popup { position: absolute; background: #fff; border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); padding: 0.75rem; font-size: 0.85rem; max-width: 280px; line-height: 1.4; z-index: 20; pointer-events: auto; display: none; }
|
|
.ifk-map-popup .popup-close { position: absolute; top: 4px; right: 8px; background: none; border: none; font-size: 16px; cursor: pointer; color: #999; }
|
|
.ifk-popup-status { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-weight: 600; font-size: 0.8rem; color: white; margin: 0.3rem 0; }
|
|
.ifk-popup-age { display: flex; align-items: center; gap: 0.35rem; margin: 0.3rem 0; font-size: 0.8rem; color: #555; }
|
|
.ifk-popup-detail { margin: 0.4rem 0; font-size: 0.82rem; color: #444; }
|
|
.ifk-popup-link { display: inline-block; margin-top: 0.4rem; font-size: 0.8rem; color: #667eea; text-decoration: none; font-weight: 600; }
|
|
.ifk-popup-link:hover { text-decoration: underline; }
|
|
.ifk-map-legend {
|
|
display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center;
|
|
margin-top: 1rem; font-size: 0.8rem;
|
|
}
|
|
.ifk-map-legend-item { display: flex; align-items: center; gap: 0.35rem; }
|
|
.ifk-map-legend-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.1); }
|
|
@media (max-width: 640px) { .ifk-map-container { height: 280px; } }
|
|
</style>
|
|
|
|
<div class="ifk-map-wrap">
|
|
<h3>{{ if eq $lang "de" }}Interaktive Weltkarte: Kinderschutzgesetze{{ else if eq $lang "fr" }}Carte interactive : lois de protection de l'enfance{{ else }}Interactive Map: Child Protection Laws{{ end }}</h3>
|
|
<p class="ifk-map-subtitle">{{ if eq $lang "de" }}Klicken Sie auf ein Land für Details{{ else if eq $lang "fr" }}Cliquez sur un pays pour plus de détails{{ else }}Click a country for details{{ end }}</p>
|
|
<div class="ifk-map-container" id="ifk-map-container">
|
|
<canvas class="ifk-map-canvas" id="ifk-map-canvas"></canvas>
|
|
<div class="ifk-map-controls">
|
|
<button id="ifk-zoom-in" title="Zoom in">+</button>
|
|
<button id="ifk-zoom-out" title="Zoom out">−</button>
|
|
<button id="ifk-zoom-reset" title="Reset"><svg width="14" height="14" viewBox="0 0 14 14"><path d="M2 9H0v5h5v-2H2V9zm0-4h3V3H2V0H0v5zm10 7H9v2h5V9h-2v3zM9 0v2h3v3h2V0H9z" fill="currentColor"/></svg></button>
|
|
</div>
|
|
<div class="ifk-map-popup" id="ifk-map-popup"><button class="popup-close" id="ifk-popup-close">×</button><div id="ifk-popup-content"></div></div>
|
|
</div>
|
|
<div class="ifk-map-legend">
|
|
<div class="ifk-map-legend-item"><div class="ifk-map-legend-swatch" style="background:#667eea"></div>{{ if eq $lang "de" }}In Kraft{{ else if eq $lang "fr" }}En vigueur{{ else }}Enforced{{ end }}</div>
|
|
<div class="ifk-map-legend-item"><div class="ifk-map-legend-swatch" style="background:#764ba2"></div>{{ if eq $lang "de" }}Verabschiedet{{ else if eq $lang "fr" }}Adopté{{ else }}Passed{{ end }}</div>
|
|
<div class="ifk-map-legend-item"><div class="ifk-map-legend-swatch" style="background:#a5b4fc"></div>{{ if eq $lang "de" }}In Bearbeitung{{ else if eq $lang "fr" }}En cours{{ else }}In Progress{{ end }}</div>
|
|
<div class="ifk-map-legend-item"><div class="ifk-map-legend-swatch" style="background:#e0e7ff"></div>{{ if eq $lang "de" }}Richtlinien{{ else if eq $lang "fr" }}Directives{{ else }}Guidelines{{ end }}</div>
|
|
<div class="ifk-map-legend-item"><div class="ifk-map-legend-swatch" style="background:#e2e8f0"></div>{{ if eq $lang "de" }}Keine Daten{{ else if eq $lang "fr" }}Pas de données{{ else }}No Data{{ end }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="{{ "js/topojson-client.min.js" | relURL }}"></script>
|
|
<script>
|
|
(function() {
|
|
var LANG = "{{ $lang }}";
|
|
var STATUS_COLORS = { enforced: '#667eea', passed: '#764ba2', progress: '#a5b4fc', guidelines: '#e0e7ff' };
|
|
var STATUS_LABELS = {
|
|
en: { enforced: 'Enforced', passed: 'Passed', progress: 'In Progress', guidelines: 'Guidelines' },
|
|
de: { enforced: 'In Kraft', passed: 'Verabschiedet', progress: 'In Bearbeitung', guidelines: 'Richtlinien' },
|
|
fr: { enforced: 'En vigueur', passed: 'Adopté', progress: 'En cours', guidelines: 'Directives' }
|
|
};
|
|
var AGE_LABELS = { en: 'Min. social media age', de: 'Min. Social-Media-Alter', fr: '\u00c2ge min. r\u00e9seaux sociaux' };
|
|
var ARTICLE_ANCHORS = { AUS: 'australia', DEU: 'germany', USA: 'the-united-states', FRA: 'france', BRA: 'brazil' };
|
|
if (LANG === 'de') { ARTICLE_ANCHORS.AUS = 'australien'; ARTICLE_ANCHORS.USA = 'die-vereinigten-staaten'; ARTICLE_ANCHORS.DEU = 'deutschland'; ARTICLE_ANCHORS.BRA = 'brasilien'; }
|
|
|
|
var countries = {{ $countries | jsonify | safeJS }};
|
|
var byIsoNum = {};
|
|
countries.forEach(function(c) { byIsoNum[c.isoNum] = c; });
|
|
|
|
var W = 960, H = 480;
|
|
var canvas = document.getElementById('ifk-map-canvas');
|
|
var container = document.getElementById('ifk-map-container');
|
|
var popup = document.getElementById('ifk-map-popup');
|
|
var popupContent = document.getElementById('ifk-popup-content');
|
|
var dpr = window.devicePixelRatio || 1;
|
|
|
|
// ViewBox state
|
|
var vb = { x: 0, y: 0, w: W, h: H };
|
|
var VB_INIT = { x: 0, y: 0, w: W, h: H };
|
|
var MIN_W = W / 16;
|
|
|
|
// Sizing: match exact device pixels to prevent GPU scaling
|
|
function sizeCanvas() {
|
|
var rect = container.getBoundingClientRect();
|
|
canvas.width = Math.round(rect.width * dpr);
|
|
canvas.height = Math.round(rect.height * dpr);
|
|
canvas.style.width = rect.width + 'px';
|
|
canvas.style.height = rect.height + 'px';
|
|
}
|
|
|
|
function projectCoord(lon, lat) {
|
|
return [(lon + 180) * (W / 360), (90 - lat) * (H / 180)];
|
|
}
|
|
|
|
// Pre-computed paths for hit testing
|
|
var countryPaths = [];
|
|
var geoData = null;
|
|
|
|
function drawMap() {
|
|
var ctx = canvas.getContext('2d');
|
|
var cw = canvas.width, ch = canvas.height;
|
|
// Transform from viewBox to canvas
|
|
var sx = cw / vb.w, sy = ch / vb.h;
|
|
|
|
ctx.clearRect(0, 0, cw, ch);
|
|
|
|
// Ocean background
|
|
ctx.fillStyle = '#c8d3df';
|
|
ctx.fillRect(0, 0, cw, ch);
|
|
|
|
if (!geoData) return;
|
|
|
|
// Draw land base fill
|
|
ctx.fillStyle = '#ffffff';
|
|
drawGeometry(ctx, geoData.land, sx, sy, true);
|
|
|
|
// Draw country fills
|
|
geoData.features.forEach(function(f) {
|
|
var id = String(f.id).padStart(3, '0');
|
|
var c = byIsoNum[id];
|
|
if (c) {
|
|
ctx.globalAlpha = 0.65;
|
|
ctx.fillStyle = STATUS_COLORS[c.status];
|
|
} else {
|
|
ctx.globalAlpha = 1;
|
|
ctx.fillStyle = '#ffffff';
|
|
}
|
|
drawGeometry(ctx, f.geometry, sx, sy, true);
|
|
});
|
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
// Draw borders
|
|
ctx.strokeStyle = '#94a3b8';
|
|
ctx.lineWidth = 0.5 * sx / (cw / vb.w);
|
|
drawGeometry(ctx, geoData.borders, sx, sy, false);
|
|
}
|
|
|
|
function drawGeometry(ctx, geom, sx, sy, fill) {
|
|
ctx.beginPath();
|
|
var coords;
|
|
if (geom.type === 'Polygon') {
|
|
geom.coordinates.forEach(function(ring) { traceRing(ctx, ring, sx, sy); });
|
|
} else if (geom.type === 'MultiPolygon') {
|
|
geom.coordinates.forEach(function(poly) {
|
|
poly.forEach(function(ring) { traceRing(ctx, ring, sx, sy); });
|
|
});
|
|
} else if (geom.type === 'MultiLineString') {
|
|
geom.coordinates.forEach(function(line) { traceLine(ctx, line, sx, sy); });
|
|
} else if (geom.type === 'LineString') {
|
|
traceLine(ctx, geom.coordinates, sx, sy);
|
|
}
|
|
if (fill) ctx.fill('evenodd');
|
|
else ctx.stroke();
|
|
}
|
|
|
|
function traceRing(ctx, ring, sx, sy) {
|
|
for (var i = 0; i < ring.length; i++) {
|
|
var p = projectCoord(ring[i][0], ring[i][1]);
|
|
var x = (p[0] - vb.x) * sx;
|
|
var y = (p[1] - vb.y) * sy;
|
|
if (i === 0) ctx.moveTo(x, y);
|
|
else ctx.lineTo(x, y);
|
|
}
|
|
ctx.closePath();
|
|
}
|
|
|
|
function traceLine(ctx, line, sx, sy) {
|
|
for (var i = 0; i < line.length; i++) {
|
|
var p = projectCoord(line[i][0], line[i][1]);
|
|
var x = (p[0] - vb.x) * sx;
|
|
var y = (p[1] - vb.y) * sy;
|
|
if (i === 0) ctx.moveTo(x, y);
|
|
else ctx.lineTo(x, y);
|
|
}
|
|
}
|
|
|
|
// Load data
|
|
fetch('{{ "data/countries-50m.json" | relURL }}')
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(topo) {
|
|
var geo = topojson.feature(topo, topo.objects.countries);
|
|
var borders = topojson.mesh(topo, topo.objects.countries, function(a, b) { return a !== b; });
|
|
var land = topojson.feature(topo, topo.objects.land);
|
|
var landGeom = land.features ? land.features[0].geometry : land.geometry;
|
|
|
|
geoData = { features: geo.features, borders: borders, land: landGeom };
|
|
|
|
// Pre-build hit-test data
|
|
geo.features.forEach(function(f) {
|
|
var id = String(f.id).padStart(3, '0');
|
|
var c = byIsoNum[id];
|
|
if (c) countryPaths.push({ id: id, geometry: f.geometry, data: c });
|
|
});
|
|
|
|
sizeCanvas();
|
|
drawMap();
|
|
});
|
|
|
|
// Resize handler
|
|
var resizeTimer;
|
|
window.addEventListener('resize', function() {
|
|
clearTimeout(resizeTimer);
|
|
resizeTimer = setTimeout(function() { sizeCanvas(); drawMap(); }, 100);
|
|
});
|
|
|
|
// Hit test: check if point is inside a country polygon
|
|
function hitTest(clientX, clientY) {
|
|
var rect = canvas.getBoundingClientRect();
|
|
var mx = clientX - rect.left;
|
|
var my = clientY - rect.top;
|
|
// Convert to map coords
|
|
var mapX = vb.x + (mx / rect.width) * vb.w;
|
|
var mapY = vb.y + (my / rect.height) * vb.h;
|
|
// Convert to lon/lat
|
|
var lon = (mapX / W) * 360 - 180;
|
|
var lat = 90 - (mapY / H) * 180;
|
|
|
|
// Use canvas isPointInPath for hit testing
|
|
var ctx = canvas.getContext('2d');
|
|
var sx = canvas.width / vb.w, sy = canvas.height / vb.h;
|
|
for (var i = 0; i < countryPaths.length; i++) {
|
|
ctx.beginPath();
|
|
var geom = countryPaths[i].geometry;
|
|
if (geom.type === 'Polygon') {
|
|
geom.coordinates.forEach(function(ring) { traceRing(ctx, ring, sx, sy); });
|
|
} else if (geom.type === 'MultiPolygon') {
|
|
geom.coordinates.forEach(function(poly) {
|
|
poly.forEach(function(ring) { traceRing(ctx, ring, sx, sy); });
|
|
});
|
|
}
|
|
if (ctx.isPointInPath(mx * dpr, my * dpr, 'evenodd')) {
|
|
return countryPaths[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Hover cursor
|
|
canvas.addEventListener('mousemove', function(e) {
|
|
var hit = hitTest(e.clientX, e.clientY);
|
|
canvas.style.cursor = hit ? 'pointer' : 'grab';
|
|
});
|
|
|
|
// Click handler
|
|
canvas.addEventListener('click', function(e) {
|
|
var hit = hitTest(e.clientX, e.clientY);
|
|
if (!hit) { popup.style.display = 'none'; return; }
|
|
var c = hit.data;
|
|
var loc = c[LANG] || c.en;
|
|
var labels = STATUS_LABELS[LANG] || STATUS_LABELS.en;
|
|
var ageLabel = AGE_LABELS[LANG] || AGE_LABELS.en;
|
|
var html = '<strong>' + c.flag + ' ' + loc.name + '</strong><br>' +
|
|
'<em>' + loc.law + '</em><br>' +
|
|
'<span class="ifk-popup-status" style="background:' + STATUS_COLORS[c.status] + '">' + labels[c.status] + ' (' + c.year + ')</span>' +
|
|
'<div class="ifk-popup-age">\u{1F464} ' + ageLabel + ': <strong>' + c.ageLimitSocial + '+</strong></div>' +
|
|
'<div class="ifk-popup-detail">' + loc.detail + '</div>';
|
|
var anchor = ARTICLE_ANCHORS[c.iso3];
|
|
if (anchor) {
|
|
var readMore = { en: 'Read more \u2193', de: 'Weiterlesen \u2193', fr: 'En savoir plus \u2193' };
|
|
html += '<a class="ifk-popup-link" href="#' + anchor + '">' + (readMore[LANG] || readMore.en) + '</a>';
|
|
}
|
|
popupContent.innerHTML = html;
|
|
var rect = container.getBoundingClientRect();
|
|
var px = e.clientX - rect.left;
|
|
var py = e.clientY - rect.top;
|
|
popup.style.display = 'block';
|
|
var pw = popup.offsetWidth, ph = popup.offsetHeight;
|
|
popup.style.left = Math.min(px + 10, rect.width - pw - 10) + 'px';
|
|
popup.style.top = Math.max(py - ph - 10, 10) + 'px';
|
|
});
|
|
|
|
document.getElementById('ifk-popup-close').addEventListener('click', function(e) {
|
|
e.stopPropagation();
|
|
popup.style.display = 'none';
|
|
});
|
|
|
|
// Zoom
|
|
function zoomBy(factor) {
|
|
var cx = vb.x + vb.w / 2, cy = vb.y + vb.h / 2;
|
|
var nw = Math.max(MIN_W, Math.min(VB_INIT.w, vb.w * factor));
|
|
var nh = nw * (H / W);
|
|
vb.w = nw; vb.h = nh;
|
|
vb.x = Math.max(0, Math.min(W - vb.w, cx - vb.w / 2));
|
|
vb.y = Math.max(0, Math.min(H - vb.h, cy - vb.h / 2));
|
|
drawMap();
|
|
}
|
|
document.getElementById('ifk-zoom-in').addEventListener('click', function() { zoomBy(0.5); });
|
|
document.getElementById('ifk-zoom-out').addEventListener('click', function() { zoomBy(2); });
|
|
document.getElementById('ifk-zoom-reset').addEventListener('click', function() {
|
|
vb = { x: 0, y: 0, w: W, h: H };
|
|
drawMap();
|
|
});
|
|
|
|
// Pan
|
|
var dragging = false, dragStart = null;
|
|
canvas.addEventListener('mousedown', function(e) {
|
|
dragging = true;
|
|
dragStart = { x: e.clientX, y: e.clientY, vbx: vb.x, vby: vb.y };
|
|
e.preventDefault();
|
|
});
|
|
window.addEventListener('mousemove', function(e) {
|
|
if (!dragging) return;
|
|
var rect = canvas.getBoundingClientRect();
|
|
var scale = vb.w / rect.width;
|
|
vb.x = Math.max(0, Math.min(W - vb.w, dragStart.vbx - (e.clientX - dragStart.x) * scale));
|
|
vb.y = Math.max(0, Math.min(H - vb.h, dragStart.vby - (e.clientY - dragStart.y) * scale));
|
|
drawMap();
|
|
});
|
|
window.addEventListener('mouseup', function() { dragging = false; });
|
|
|
|
// Touch
|
|
canvas.addEventListener('touchstart', function(e) {
|
|
if (e.touches.length !== 1) return;
|
|
dragging = true;
|
|
dragStart = { x: e.touches[0].clientX, y: e.touches[0].clientY, vbx: vb.x, vby: vb.y };
|
|
}, { passive: true });
|
|
canvas.addEventListener('touchmove', function(e) {
|
|
if (!dragging || e.touches.length !== 1) return;
|
|
var rect = canvas.getBoundingClientRect();
|
|
var scale = vb.w / rect.width;
|
|
vb.x = Math.max(0, Math.min(W - vb.w, dragStart.vbx - (e.touches[0].clientX - dragStart.x) * scale));
|
|
vb.y = Math.max(0, Math.min(H - vb.h, dragStart.vby - (e.touches[0].clientY - dragStart.y) * scale));
|
|
drawMap();
|
|
}, { passive: true });
|
|
canvas.addEventListener('touchend', function() { dragging = false; }, { passive: true });
|
|
})();
|
|
</script>
|