fix(maps): move VENUE_ICON creation after Leaflet loads

L.divIcon() was called at IIFE top level before the dynamic Leaflet
script loaded, throwing ReferenceError and preventing all maps from
rendering. Move icon creation into script.onload callback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-03-06 09:01:54 +01:00
parent 93c9408f6b
commit c5327c4012
2 changed files with 12 additions and 11 deletions

View File

@@ -62,14 +62,7 @@
.catch(function(err) { console.error('Country map fetch failed:', err); });
}
var VENUE_ICON = L.divIcon({
className: '',
html: '<div class="pn-venue"></div>',
iconSize: [10, 10],
iconAnchor: [5, 5],
});
function initCityMap(el) {
function initCityMap(el, venueIcon) {
var countrySlug = el.dataset.countrySlug;
var citySlug = el.dataset.citySlug;
var lat = parseFloat(el.dataset.lat);
@@ -91,7 +84,7 @@
: '')
: '';
var tip = '<strong>' + v.name + '</strong>' + (courtLine ? '<br>' + courtLine : '');
L.marker([v.lat, v.lon], { icon: VENUE_ICON })
L.marker([v.lat, v.lon], { icon: venueIcon })
.bindTooltip(tip, { className: 'map-tooltip', direction: 'top', offset: [0, -7] })
.addTo(map);
});
@@ -104,7 +97,15 @@
script.src = window.LEAFLET_JS_URL || '/static/vendor/leaflet/leaflet.min.js';
script.onload = function() {
if (countryMapEl) initCountryMap(countryMapEl);
if (cityMapEl) initCityMap(cityMapEl);
if (cityMapEl) {
var venueIcon = L.divIcon({
className: '',
html: '<div class="pn-venue"></div>',
iconSize: [10, 10],
iconAnchor: [5, 5],
});
initCityMap(cityMapEl, venueIcon);
}
};
document.head.appendChild(script);
})();