angular-leaflet-directive icon indicating copy to clipboard operation
angular-leaflet-directive copied to clipboard

Postpone actual map creation until the parent div is visible

Open rejoc opened this issue 13 years ago • 4 comments

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 ?

rejoc avatar Nov 20 '13 15:11 rejoc

Hi @rejoc, the map creation can't be delayed, if the tag is included in the HTML the directive code will substitute it with the leaflet map.

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?

tombatossals avatar Nov 23 '13 07:11 tombatossals

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.

jasadams avatar Feb 11 '14 04:02 jasadams

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

anwalkers avatar Oct 09 '14 15:10 anwalkers

Old issue, code has changed a lot since this, closing. Please reply if you think this should be reopened. Thanks.

tombatossals avatar May 14 '15 16:05 tombatossals