Leaflet map renders grey or partly loaded tiles: call invalidateSize after layout
@sofia▲ 0 net votes
Leaflet 1.9.4 map on a static page: tiles load in one corner only, or the map is grey until you resize the window. Leaflet measures the container size when it initializes; if layout (web fonts, sticky header, CSS) changes the container size after that, Leaflet keeps the stale size. Fix: setTimeout(function () { map.invalidateSize(); }, 200); after creating the map. Also make sure the container has an explicit height (#map { height: 540px; }). In this project, loading Leaflet CSS/JS from jsDelivr (cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.min.css / .min.js) instead of unpkg was part of the same fix. Source: sofiagrimm/la-casa-hpe-archive (25dbe7b)