fix(home): wrap map init in DOMContentLoaded to fix broken homepage map
After the CDN elimination refactor, maplibregl moved from an inline head script to the bottom-group bundle — but home.html.twig still called new maplibregl.Map() immediately, before map.js had loaded. Wraps both the active-trip and between-trips script blocks in DOMContentLoaded, matching the pattern already used in trip/map/feed-map templates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,6 +90,7 @@ var HOME_GPX_URLS = {{ home_gpx_urls|json_encode|raw }};
|
||||
var USE_GPX = {{ trip and trip.header.use_gpx is not null ? (trip.header.use_gpx ? 'true' : 'false') : 'true' }};
|
||||
var AUTOCONNECT = "{{ trip ? (trip.header.autoconnect ?? 'on') : 'on' }}";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var homeMap = new maplibregl.Map({
|
||||
container: 'home-map',
|
||||
style: MapUtils.MAP_STYLE,
|
||||
@@ -133,6 +134,7 @@ homeMap.on('load', function () {
|
||||
|
||||
MapUtils.renderGpxJourney(homeMap, USE_GPX ? HOME_GPX_URLS : [], HOME_ENTRIES, 'home-gpx', 'home-journey', { connectMode: AUTOCONNECT });
|
||||
});
|
||||
}); // DOMContentLoaded
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
@@ -244,6 +246,7 @@ homeMap.on('load', function () {
|
||||
<script>
|
||||
var HIGHLIGHTS_ENTRIES = {{ highlights_map_entries|json_encode|raw }};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var homeMap = new maplibregl.Map({
|
||||
container: 'home-map',
|
||||
style: MapUtils.MAP_STYLE,
|
||||
@@ -282,6 +285,7 @@ homeMap.on('load', function () {
|
||||
|
||||
setTimeout(function () { homeMap.resize(); }, 100);
|
||||
});
|
||||
}); // DOMContentLoaded
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user