将热图添加到Folium中的图层

时间:2019-02-18 17:06:45

标签: python dictionary folium

我有以下示例代码:

from glob import glob
import numpy as np
import folium
from folium import plugins
from folium.plugins import HeatMap

lon, lat = -86.276, 30.935 
zoom_start = 5


data = (
    np.random.normal(size=(100, 3)) *
    np.array([[1, 1, 1]]) +
    np.array([[48, 5, 1]])
).tolist()
m = folium.Map([48, 5], tiles='stamentoner', zoom_start=6)

HeatMap(data).add_to(m)
m

enter image description here

如何将此热图添加到图层,以便在需要时可以将其隐藏?

1 个答案:

答案 0 :(得分:1)

我首先将您的HeatMap添加到FeatureGroup,然后将该FeatureGroup添加到map(m)。然后,我将LayerControl添加到您的地图(检查右上角)。这样就够了吗?

from glob import glob
import numpy as np
import folium
from folium import plugins
from folium.plugins import HeatMap

lon, lat = -86.276, 30.935 
zoom_start = 5


data = (
    np.random.normal(size=(100, 3)) *
    np.array([[1, 1, 1]]) +
    np.array([[48, 5, 1]])
).tolist()
m = folium.Map([48, 5], tiles='stamentoner', zoom_start=6)

HeatMap(data).add_to(folium.FeatureGroup(name='Heat Map').add_to(m))
folium.LayerControl().add_to(m)

m

http://website.com/index.php