我正在使用Folium的半圆插件(https://github.com/syberworld/Folium-SemiCircle)。它具有默认的蓝色:
我尝试使用一些传单方法,例如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)
有什么办法可以改变这些颜色?
答案 0 :(得分:1)
我对folium半圆形插件进行了更改,因此它可以接受缺少的此选项。我提出了合并请求。如果未更新,这是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')