Closed johnedvard closed 6 years ago
Is the map fixed when you resize your browser?
Can you verify in the console that the leaflet.css file is being properly loaded and applied to the element?
Also, like mcurtis22 said, you should check to see if resizing the window fixes the issue. If there's something causing the DOM elements to resize, Leaflet requires you to call "map.invalidateSize()". ngx-leaflet will handle this automatically for you for window resizes, but there's no straightforward way to generically handle anything that might resize the page via javascript.
Thank you for your comments. I think the css was not properly loaded and applied as you say. When I opened the application today, I was able to render the map perfectly. Maybe I forgot to rebuild the application after adding the Leaflet module. Thank you for your rapid replies though. Cheers
I have the same problem even with my css properly loaded. but if I do resize the window the map is fixed, how can this be "fixed" without resizing the window?
fyi: I'm using bootstrap 4 flex columns
Edit: I could fix it with this guys help https://github.com/Asymmetrik/ngx-leaflet/issues/104#issuecomment-349086565
That weird broken map issue is almost always either missing Leaflet CSS or that you need to call invalidateSize
because something you're doing is causing the DIV the map's on to change size.
When the DIV containing the map is resized, you have to call invalidateSize
. This is inherent to leaflet itself, and has been the subject of many issues on their repo.
The ngx-leaflet plugin listens to window resize events and calls invalidateSize
for you. This handles probably 95%+ of the cases in which the map changes size. The only other way the DIV elements can change is through some kind of page manipulation that is happening through JavaScript. Since the issue is fixed when you resize the window, it's most likely that your problem is that you need to call invalidateSize
and not missing CSS files. You just need to figure out what's causing the page to change size and then add the invalidateSize
call.
Common examples of JavaScript size manipulation:
[hide]='...'
input bindingIf you're doing any of these things, you either need to manually call invalidateSize
after the the change. You can also add some custom code that just tracks the size of your map div and calls it when it detects changes.
In my projects, this often happens when we use [hide]
instead of *ngIf
and when we use things like ngx-bootstrap tabs (which dynamically shows and hides page content).
@reblace Is there any more general solution possible? In a complex angular application all of the above could certainly change for many reasons, many of those reasons inside of other libraries even. How about a setting in ngx-leaflet
to perform the workaround mentioned above, tracking the size and calling this method automatically?
Hi! I am having the same problem in polymer2 the leaflet map doesnt show properly??can any one know how to fix it??i dont have any error only it give me the style error! could not find style data in module named shared-styles!!!! thnx for helping!!
I tried out ngx-leaflet with a Angular CLI project and ended up having the same problem. @reblace 's hint "That weird broken map issue is almost always either missing Leaflet CSS" was the key: in the "styles" section of angular.json I had to add the line:
"node_modules/leaflet/dist/leaflet.css"
Maybe you can an *ngIf="show"
directive and after the view init, set it on true. That worked for me. I guess the problem is when the map is loaded, so if you wait until the component is fully loaded, it'll work properly.
The solution to this problem is simple, just insert in the index.html the following codes:
Check if your leaflet.css file is correctly added to the angular.json! I added leaflet.scss and that caused the problem.
It seems the map is not drawn correctly (see picture). I am using the latest version of Angular as of this writing (Agnular 5).![screenshot 2017-12-06 10 02 54](https://user-images.githubusercontent.com/656024/33653723-3d27118a-da6e-11e7-8334-6cf974e9f7c7.png)
I have followed the steps in the installation guide:
I added Styles in Angular CLI
I added module in app.module
I have the current DOM-element:
in my component using the map, I have the following setup:
Is it a bug, or am I doing something wrong?