from folium.plugins import HeatMap, Fullscreen
import folium
def draw_map_heat2(data_heat, output_path='.'):
lats = [d[0] for d in data_heat]
lngs = [d[1] for d in data_heat]
lat_mid = sum(lats) / len(lats)
lng_mid = sum(lngs) / len(lngs)
ChinaMap = folium.Map(location=[lat_mid, lng_mid],
tiles=None,
names='高德地图',
attr='高德地图',
overlay=False,
show=False,
zoom_start=10)
#
folium.TileLayer('http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
attr='高德地图', name='高德地图').add_to(ChinaMap)
Fullscreen(
position='topright',
title='全屏',
title_cancel='退出全屏',
force_separate_button=True
).add_to(ChinaMap)
# 候选点所在地
site_candicate_point = folium.FeatureGroup(name="各个需求点地址", show=True)
for d in data_heat:
gis = str(round(d[0], 3)) + ',' + str(round(d[1], 3))
site_candicate_point.add_child(folium.Marker(location=d[:2], popup= gis))
ChinaMap.add_child(site_candicate_point)
site_candicate_heat_point = folium.FeatureGroup(name="热力图", show=True)
site_candicate_heat_point.add_child(HeatMap(data_heat))
ChinaMap.add_child(site_candicate_heat_point)
folium.LayerControl().add_to(ChinaMap)
file_path = output_path + "\MapHeat.html"
ChinaMap.save(file_path)
if __name__ == '__main__':
data_heat = [[23.149486, 113.454709, 100],
[22.797794, 113.140348, 200],
[23.438073, 113.648574, 300]]
draw_map_heat2(data_heat)