Leaflet / Mapbox rendering issue (grey area)

一世执手 提交于 2019-12-23 15:37:46

问题


For some reason, my map has a big grey area on it, until I move it which makes it appear.

But on the first look, there's a part missing. I've seen this quite a lot around the web before but never wondered about how to fix it until now.

This is a simple Mapbox map using MarkerClusterGroup for clusters.

Here's a screenshot and the link to the page:

http://vinpin.com/map

So I was wondering, is there any easy known fix for that kind of behavior?

I can add code snippets if required.

Thanks and have a nice day!


回答1:


It seems the map element size has changed since the initialization and you did not invalidate it.

Did you change the visibility (eg. display: none style), position (eg. position: absolute or position: fixed like in affix), or removed any HTML element dynamically (with JS)? Perhaps, you are loading the resources in the wrong order and styles are loaded after the leaflet.js? Or, perhaps you changed margins or padding? These kind of operations can change the size of other elements implicitly and the Leaflet applet loads the tiles only for an area covered by its old size. It shows already loaded tiles correctly in this "grey" area, though, so you can scroll up and the grey space at the bottom will be filled then.

If this is the case, you should execute invalidateSize() method on your Leaflet map object.



来源:https://stackoverflow.com/questions/17863904/leaflet-mapbox-rendering-issue-grey-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!