fix: interactive popups + maxZoom 4 + invisible hit layer
All checks were successful
Deploy Internet for Kids / Build & Push (push) Successful in 10s
Deploy Internet for Kids / Deploy (push) Successful in 6s
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 6s
Deploy Internet for Kids / Promote to Latest (push) Successful in 1s
Deploy Internet for Kids / Rollback (push) Has been skipped
Deploy Internet for Kids / Audit (push) Successful in 2s

Popup click/hover now uses invisible GeoJSON fill layer (raster layers
don't support events). MaxZoom capped at 4 to prevent blurry zoom.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-04-04 18:01:16 +03:00
parent 8e15d1aa0c
commit ccca7ae482

View File

@@ -43,6 +43,7 @@ body { margin: 0; overflow: hidden; }
zoom: 2, zoom: 2,
scrollZoom: false, scrollZoom: false,
fadeDuration: 0, fadeDuration: 0,
maxZoom: 4,
style: 'https://maps.clicksports.de/styles/klokantech-basic/style.json' style: 'https://maps.clicksports.de/styles/klokantech-basic/style.json'
}); });
_ifkMap.addControl(new maplibregl.NavigationControl({ showCompass: false }), 'top-right'); _ifkMap.addControl(new maplibregl.NavigationControl({ showCompass: false }), 'top-right');
@@ -181,8 +182,12 @@ body { margin: 0; overflow: hidden; }
renderChoropleth(); renderChoropleth();
_ifkMap.on('moveend', function() { if (needsRerender()) renderChoropleth(); }); _ifkMap.on('moveend', function() { if (needsRerender()) renderChoropleth(); });
// Keep GeoJSON source for hover/click interaction (invisible) // Invisible GeoJSON layer for hover/click interaction
_ifkMap.addSource('countries', { type: 'geojson', data: geo }); _ifkMap.addSource('countries', { type: 'geojson', data: geo });
_ifkMap.addLayer({
id: 'countries-interaction', type: 'fill', source: 'countries',
paint: { 'fill-color': '#000000', 'fill-opacity': 0, 'fill-antialias': false }
});
_ifkMap.addLayer({ _ifkMap.addLayer({
id: 'choropleth-hover', type: 'fill', source: 'countries', id: 'choropleth-hover', type: 'fill', source: 'countries',
paint: { 'fill-color': '#667eea', 'fill-opacity': 0.2, 'fill-antialias': false }, paint: { 'fill-color': '#667eea', 'fill-opacity': 0.2, 'fill-antialias': false },
@@ -191,18 +196,18 @@ body { margin: 0; overflow: hidden; }
var popup = new maplibregl.Popup({ closeButton: true, closeOnClick: false, maxWidth: '280px' }); var popup = new maplibregl.Popup({ closeButton: true, closeOnClick: false, maxWidth: '280px' });
_ifkMap.on('mousemove', 'choropleth-fill', function(e) { _ifkMap.on('mousemove', 'countries-interaction', function(e) {
var id = e.features[0].properties.isoNum; var id = e.features[0].properties.isoNum;
var c = byIsoNum[id]; var c = byIsoNum[id];
_ifkMap.getCanvas().style.cursor = c ? 'pointer' : ''; _ifkMap.getCanvas().style.cursor = c ? 'pointer' : '';
_ifkMap.setFilter('choropleth-hover', c ? ['==', 'isoNum', id] : ['==', 'isoNum', '']); _ifkMap.setFilter('choropleth-hover', c ? ['==', 'isoNum', id] : ['==', 'isoNum', '']);
}); });
_ifkMap.on('mouseleave', 'choropleth-fill', function() { _ifkMap.on('mouseleave', 'countries-interaction', function() {
_ifkMap.getCanvas().style.cursor = ''; _ifkMap.getCanvas().style.cursor = '';
_ifkMap.setFilter('choropleth-hover', ['==', 'isoNum', '']); _ifkMap.setFilter('choropleth-hover', ['==', 'isoNum', '']);
}); });
_ifkMap.on('click', 'choropleth-fill', function(e) { _ifkMap.on('click', 'countries-interaction', function(e) {
var id = e.features[0].properties.isoNum; var id = e.features[0].properties.isoNum;
var c = byIsoNum[id]; var c = byIsoNum[id];
if (!c) return; if (!c) return;