如何在Folium地图中添加“ Circle”大小的图例在python中以及如何注释文本以便在所有情况下都可见? 有人对如何执行此操作有想法吗? Web上对Folium的支持并不广泛,因此找不到类似的东西

如何解决如何在Folium地图中添加“ Circle”大小的图例在python中以及如何注释文本以便在所有情况下都可见? 有人对如何执行此操作有想法吗? Web上对Folium的支持并不广泛,因此找不到类似的东西

在下面找到我的代码我有一张欧洲地图和一些我想标记的城市及其人口规模。我想用“圆圈”标记那些城市,其大小应与缩放后的“人口”相对应。

  1. 我正在尝试在此地图上添加“圆圈”大小的图例,但我找不到解决方法。使用Circle Layer时,无法添加图例。

  2. 我也在尝试使用DivIcon在地图上注释城市名称,并且确实可以,但是有些城市彼此之间距离太近,因此,如果我可以将这些城市的名称进一步移动,我希望远离相应的点,并用一条线连接它们。

只需提一下,这里我仅显示一些英国城市,但总的来说,我具有整个欧洲和许多城市的地图,因此英国的那些城市名称实际上是不可见的。

有人对如何执行此操作有想法吗? Web上对folium支持并不广泛,因此找不到类似的东西。

import pandas as pd
import numpy as np
import folium
import json
import geopandas as gpd
# Pretty display for notebooks
%matplotlib inline

data = [['Birmingham',1141374,52.4796992,-1.9026911],['Bradford',537173,53.7944229,-1.7519186],['Bristol',463405,51.4538022,-2.5972985],['Edinburgh',518500,55.9533456,-3.1883749],['Glasgow',626410,55.8609825,-4.2488787],['Leeds',789194,53.7974185,-1.5437941],['Liverpool',494814,53.407154,-2.991665]]
cities = pd.DataFrame(data,columns = ['City','Population','Latitude','Longitude'])

europe = #geojson file of Europe dowloaded from https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/countries

import folium.plugins
from folium.features import *

# adding the DivIcon element for the text annotation
class DivIcon(MacroElement):
    def __init__(self,html='',size=(30,30),anchor=(0,0),style=''):
        """Todo : docstring here"""
        super(DivIcon,self).__init__()
        self._name = 'DivIcon'
        self.size = size
        self.anchor = anchor
        self.html = html
        self.style = style

        self._template = Template(u"""
            {% macro header(this,kwargs) %}
              <style>
                .{{this.get_name()}} {
                    {{this.style}}
                    }
              </style>
            {% endmacro %}
            {% macro script(this,kwargs) %}
                var {{this.get_name()}} = L.divIcon({
                    className: '{{this.get_name()}}',iconSize: [{{ this.size[0] }},{{ this.size[1] }}],iconAnchor: [{{ this.anchor[0] }},{{ this.anchor[1] }}],html : "{{this.html}}",});
                {{this._parent.get_name()}}.setIcon({{this.get_name()}});
            {% endmacro %}
            """)

# creating the map
map = folium.Map(location=[53.7974185,zoom_start=4,tiles=None)
style1 = {'fillColor': '#4682b4','fill': True,'weight': 1,'opacity': 0.3,'fillOpacity': 1}
style2 = {'color': 'black','weight': -1,'opacity': 0.2}

folium.GeoJson(
    europe,name='Europe',overlay=False,control= False,style_function = lambda x: style2).add_to(map)
        
# Adding a circle for each selected city
for idx,city in cities.iterrows():
    folium.Circle(location=(city['Latitude'],city['Longitude']),popup=city['City'],radius=city['Population']/10000,fillColor= 'red',color= 'red',fill= True,fillOpacity= 0,opacity= 1,weight= 2
                 ).add_to(map)
    folium.Marker(location=(city['Latitude'],icon=DivIcon(
                     size=(75,25),anchor=(50,-3),html=city.City,style='font-size:13px; color:black; text-align: center')).add_to(map)

map

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?