Add heatmap to a layer in Folium

时间秒杀一切 提交于 2019-12-11 01:28:59

问题


I have this sample code:

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

How can I add this heat map to a layer so I can hide it if needed?


回答1:


I would first add your HeatMap to a FeatureGroup and then add that FeatureGroup to the map(m). I would then add a LayerControl to your map (check the upper right corner). Does this suffice?

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



来源:https://stackoverflow.com/questions/54752175/add-heatmap-to-a-layer-in-folium

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