gpt4 book ai didi

python - Folium:如何更改半圆插件中的填充颜色?

转载 作者:行者123 更新时间:2023-12-01 07:30:29 25 4
gpt4 key购买 nike

我正在使用 Folium 的半圆插件 ( https://github.com/syberworld/Folium-SemiCircle )。它有默认的蓝色:

leaflet image

我尝试使用一些传单方法,例如line_color、color、fill_color,但它们似乎没有实现。

这是代码:

import folium
from folium import plugins
m = folium.Map(
width='100%', height='100%',
location=[39.217, 9.136],
zoom_start=14,
tiles='CartoDB positron'
)

def add_semicircle(location,azimute, m, radius=2000, arc=30, popup=None):
x = plugins.SemiCircle(
location=location, # Location of center
radius= radius, # Radius in meters
direction = azimute,
line_color = 'red',
opacity = 0,
icon_color='red',
arc = arc
)
x.add_child(folium.Popup(popup))
x.add_to(m)

add_semicircle([39.217, 9.136],270, m,arc=30)

display(m)

有什么办法可以改变这些颜色吗?

最佳答案

我对 folium semicircle 插件进行了更改,以便它可以接受缺少的选项。我提出了合并请求。以下是 semicircle.py 新类的代码(以防未更新):

# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)

import json

from branca.element import Figure, JavascriptLink

from folium.map import Marker
from folium.utilities import validate_location

from jinja2 import Template

class SemiCircle(Marker):
"""
Creates a Semicircle plugin to append into a map with
Map.add_plugin.
Use (direction and arc) or (startAngle and stopAngle)
Parameters
----------
location: tuple of length 2, default None
The latitude and longitude of the marker.
If None, then the middle of the map is used.
radius: int, default 0
Radius of semicircle
direction: int, default 0
Heading of direction angle value between 0 and 360 degrees
arc: int, default 0
Heading of arc angle value between 0 and 360 degrees.
startAngle: int, default 0
Heading of the start angle value between 0 and 360 degrees
stopAngle: int, default 0
Heading of the stop angle value between 0 and 360 degrees.
"""
_template = Template(u"""
{% macro script(this, kwargs) %}
if ({{this.direction}} || {{this.arc}}) {
var {{this.get_name()}} = L.semiCircle(
[{{this.location[0]}},{{this.location[1]}}],
{radius:{{this.radius}},
fill: {{this.fill}},
fillColor:'{{this.fill_color}}',
fillOpacity: {{this.fill_opacity}},
color: '{{this.color}}',
opacity: {{this.opacity}}
}).setDirection({{this.direction}},{{this.arc}})
.addTo({{this._parent.get_name()}});
} else if ({{this.startAngle}} || {{this.stopAngle}}) {
var {{this.get_name()}} = L.semiCircle(
[{{this.location[0]}},{{this.location[1]}}],
{radius:{{this.radius}},
fill: {{this.fill}},
fillColor:'{{this.fill_color}}',
fillOpacity: {{this.fill_opacity}},
color: '{{this.color}}',
opacity: {{this.opacity}},
startAngle:{{this.startAngle}},
stopAngle:{{this.stopAngle}}
})
.addTo({{this._parent.get_name()}});
}
{% endmacro %}
""")

def __init__(self,
location,
radius=0,
fill = True,
fill_color='#3388ff',
fill_opacity = 0.5,
color = '#3388ff',
opacity = 1,
direction=0,
arc=0,
startAngle=0,
stopAngle=0, **kwargs):

super(SemiCircle, self).__init__( validate_location(location), **kwargs)
self._name = 'SemiCircle'
self.radius = radius
if fill == True:
self.fill = 'true'
else: self.fill = 'false'
self.fill_color = fill_color
self.fill_opacity = fill_opacity
self.color = color
self.opacity = opacity
self.direction = direction
self.arc = arc
self.startAngle = startAngle
self.stopAngle = stopAngle
self.fill_color = fill_color
self.kwargs = json.dumps(kwargs)

def render(self, **kwargs):
super(SemiCircle, self).render(**kwargs)

figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('http://jieter.github.io/Leaflet-semicircle/Semicircle.js'),
name='semicirclejs')

关于python - Folium:如何更改半圆插件中的填充颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57227249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com