五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

python用folium繪制地圖并設(shè)置彈窗效果

發(fā)布日期:2022-01-30 10:46 | 文章來源:源碼之家

python–Folium

官方說明:folium.link.

  • map用于生成地圖,主要用到黃色的參數(shù)

Map(location=None, width=‘100%', height=‘100%', left=‘0%', top=‘0%', position=‘relative', tiles=‘OpenStreetMap', attr=None, min_zoom=0, max_zoom=18, zoom_start=10, min_lat=- 90, max_lat=90, min_lon=- 180, max_lon=180, max_bounds=False, crs=‘EPSG3857', control_scale=False, prefer_canvas=False, no_touch=False, disable_3d=False, jpg_enabled=False, zoom_control=True, **kwargs)

Parameters 參數(shù)說明

  • location (tuple or list, default None) – Latitude and Longitude of Map (Northing, Easting).
  • width (pixel int or percentage string (default: ‘100%')) – Width of the map.
  • height (pixel int or percentage string (default: ‘100%')) – Height of the map.
  • tiles (str, default ‘OpenStreetMap') – Map tileset to use. Can choose from a list of built-in tiles, pass a custom URL or pass None to create a map without tiles. For more advanced tile layer options, use the TileLayer class.
  • min_zoom (int, default 0) – Minimum allowed zoom level for the tile layer that is created.
  • max_zoom (int, default 18) – Maximum allowed zoom level for the tile layer that is created.
  • zoom_start (int, default 10) – Initial zoom level for the map.
  • attr (string, default None) – Map tile attribution; only required if passing custom tile URL.
  • crs (str, default ‘EPSG3857') – Defines coordinate reference systems for projecting geographical points into pixel (screen) coordinates and back.定義坐標(biāo)參考系統(tǒng)
  • control_scale (bool, default False) – Whether to add a control scale on the map.
  • prefer_canvas (bool, default False) – Forces Leaflet to use the Canvas back-end (if available) for vector layers instead of SVG.
  • no_touch (bool, default False) – Forces Leaflet to not use touch events even if it detects them.
  • disable_3d (bool, default False) – Forces Leaflet to not use hardware-accelerated CSS 3D transforms for positioning (which may cause glitches in some rare environments) even if they're supported.
  • zoom_control (bool, default True) – Display zoom controls on the map.

basic example

m = folium.Map(location=[45.523, -122.675], width=750, height=500)
m = folium.Map(location=[45.523, -122.675], tiles='cartodb positron')
m = folium.Map(
location=[45.523, -122.675],
zoom_start=2,
tiles='https://api.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg?access_token=mytoken',
attr='Mapbox attribution'
...)

Markers

m = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles="Stamen Terrain")
tooltip = "Click me!"
folium.Marker(
 [45.3288, -121.6625], popup="<i>Mt. Hood Meadows</i>", tooltip=tooltip
).add_to(m)

tooltip:點擊標(biāo)記后彈出的信息
popup:鼠標(biāo)放標(biāo)記上顯示的信息

標(biāo)記樣式修改

m = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles="Stamen Terrain")
folium.Marker(
 location=[45.3288, -121.6625],
 popup="Mt. Hood Meadows",
 icon=folium.Icon(icon="cloud"),
).add_to(m)
folium.Marker(
 location=[45.3311, -121.7113],
 popup="Timberline Lodge",
 icon=folium.Icon(color="green"),
).add_to(m)
folium.Marker(
 location=[45.3300, -121.6823],
 popup="Some Other Location",
 icon=folium.Icon(color="red", icon="info-sign"),
).add_to(m)

標(biāo)記圓形區(qū)域

點擊任意位置出現(xiàn)經(jīng)緯度folium.LatLngPopup()

m = folium.Map(location=[46.1991, -122.1889], tiles="Stamen Terrain", zoom_start=13)
m.add_child(folium.LatLngPopup())

打點功能:點擊任意位置出現(xiàn)標(biāo)記,再點擊彈出信息

m = folium.Map(location=[46.8527, -121.7649], tiles="Stamen Terrain", zoom_start=13)
folium.Marker([46.8354, -121.7325], popup="Camp Muir").add_to(m)
m.add_child(folium.ClickForMarker(popup="Waypoint"))

允許顯示任何HTML對象

m = folium.Map(location=[46.3014, -123.7390], zoom_start=7, tiles="Stamen Terrain")
folium.Marker(
 location=[47.3489, -124.708],
 popup=folium.Popup(max_width=450).add_child(
  folium.Vega(vis1, width=450, height=250)
 ),
).add_to(m)

可以參考的代碼
html參考鏈接

實戰(zhàn)

用folium繪制中國的政策地圖,城市的政策匯總在一個excel表中。要實現(xiàn)的效果是政策可視化,點擊某一個城市,可以彈出這個城市所有的政策。

import folium
import webbrowser as wb
import numpy as np
import xlrd
import pandas as pd
from folium import CustomIcon
def get_data():
 '''
 return:
 df_data:返回城市對應(yīng)的編號,經(jīng)緯度
 df_policy:返回城市的政策名稱、鏈接、編號
 '''
 file_name = 'policy.xls'
 all_data = xlrd.open_workbook(file_name)
 table = all_data.sheet_by_name('num_lat_lon')
 df_data = pd.DataFrame(columns=['city','number','latitude','longitude'])
 for i in range(1,table.nrows):
  df_data.loc[i] = table.row_values(i)
 table_policy = all_data.sheet_by_name('policy')
 df_policy = pd.DataFrame(columns=['number','name','link'])
 for i in range(1,table_policy.nrows):
  df_policy.loc[i,'number'] = table_policy.cell(i,3).value
  df_policy.loc[i,'name'] = table_policy.cell(i,1).value
  df_policy.loc[i,'link'] = table_policy.cell(i,2).value
 return df_data, df_policy
 # 中文轉(zhuǎn)換
def parse_zhch(s):
  return str(str(s).encode('ascii' , 'xmlcharrefreplace'))[2:-1]
def show_map(df_data,df_policy):
 '''
 可以使用高德地圖或默認(rèn)地圖
 m = folium.Map(zoom_start=4,zoom_control=True,tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',attr='default')
 '''
 # 默認(rèn)地圖
 m = folium.Map(location=[39.904,116.408],zoom_start=4,zoom_control=True,tiles='OpenStreetMap')
 for i in range(1,len(df_data)):
  # 得到該城市的編號、經(jīng)緯度
  number = df_data.loc[i,'number']
  latitude = df_data.loc[i,'latitude']
  longitude = df_data.loc[i,'longitude']
  tip = df_data.loc[i,'city']
  # 獲取城市編號對應(yīng)的所有政策和鏈接的行索引
  city_index = df_policy[df_policy.number == number].index.tolist()
  # 將城市名稱和鏈接放同一個list中
  s=[]
  for i in city_index:
s.append(df_policy.loc[i,'name']) 
s.append(df_policy.loc[i,'link'])
  # 計算最大長度
  length = []
  for i in range(len(s)):
length.append(len(s[i]))
  WIDTH = max(length)
  # 點擊彈出內(nèi)容和彈出框大小設(shè)置
  ss=''
  for i in range(len(s)):
ss = ss + s[i] + '</br>' 
  pop = folium.Popup(html=ss,max_width=WIDTH*10)
  icon = CustomIcon(icon_image ='loc.jpg',icon_size=(20, 20))
  # tooltip:懸浮彈出信息;popup:點擊出現(xiàn)信息
  folium.Marker([latitude,longitude],icon=icon, popup=pop,tooltip=parse_zhch(tip)).add_to(m)
 m.save('map.html')
 wb.open('map.html')

if __name__ == '__main__':
 df_data,df_policy = get_data()
 show_map(df_data,df_policy)

實現(xiàn)效果:

到此這篇關(guān)于python用folium繪制地圖并設(shè)置彈窗效果的文章就介紹到這了,更多相關(guān)python folium繪制地圖內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

美國服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部