Postpone actual map creation until the parent div is visible
When a leaflet tag is included in a div that is not visible when the page is loaded, the map is not initialized correctly and sometime, even a map.invalidateSize() is not enough to redraw the map correctly.
So isn't a way to postpone the actuel map creation (new L.map... ) until a specific signal or the changed value of an attribute ?
Hi @rejoc, the map creation can't be delayed, if the
You could load the <leaflet ..> code as a partial via ng-route and ng-view, this way the map creation will be delayed until the ng-view condition is accomplished and the <leaflet..> tag is loaded via AJAX.
In any case, "invalidateSize()" should be enough to redraw the map always. Could you provide an example where invalidateSize doesn't work for you?
I have a similar issue. I have a map container whose size is not known until the DOM is rendered. eg position:absolute, top:0, left:0, right:0, bottom:0; In the directive when the map is created on the container, the clientHeight and clientWidth are zero. This leads to Leaflet thinking the map size is zero and therefore doesn't render the tiles correctly. If I resize the browser then everything works fine.
I see you mention the use of "invalidateSize()" above, however I think this directive should handle the case of having a dynamically sized container which may be zero before the DOM is rendered, without having to perform any such calls manually.
In our project we don't have the initial map sizing problem but needed a way to call invalidateSize when we show the map in full screen mode. We added an event listener to the library. See the pull request. https://github.com/tombatossals/angular-leaflet-directive/pull/492
Old issue, code has changed a lot since this, closing. Please reply if you think this should be reopened. Thanks.