Welcome to SO!
If your sheet map unexpectedly works correctly after resizing the browser window , then you get the classic "map container size is not valid when initializing the map": for proper operation, Leaflet reads the size of the map container when initializing the map ( L.map("mapContainerId")
).
If your application hides this container (usually using CSS display: none;
or some tab framework / modal / whatever ...) or later resizes it, Leaflet will not know about the new size. Therefore, it will not display correctly. Typically, he downloads tiles only for the fraction of the container that, in his opinion, is displayed. This can be a single tile in the upper left corner in the case of a container that was completely hidden during map initialization.
This error often occurs when embedding a map container in a tab or modal panel, possibly using popular frameworks (Bootstrap, Angular, Ionic, etc.).
The flyer listens to the browser window resize event and reads the container size again when this happens. This explains why the card suddenly works when the window is resized.
You can also manually start this update by calling map.invalidateSize()
when the tab bar is displayed (for example, add a listener to the tab button click), at least the first time the container is displayed with its correct size.
As for the implementation of the click button on the tab, do a new SO search in this section: you should have enough resources for this, for most popular frameworks.
source share