Skip to content

Commit 5f78c43

Browse files
author
Martin Journois
committed
An effort on docstrings in plugins
1 parent 6b0da9e commit 5f78c43

File tree

9 files changed

+76
-3
lines changed

9 files changed

+76
-3
lines changed

folium/plugins/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Folium plugins
4+
--------------
25
6+
Add different objetcs/effects on a folium map.
7+
"""
38
from .marker_cluster import MarkerCluster
49
from .scroll_zoom_toggler import ScrollZoomToggler
510
from .terminator import Terminator

folium/plugins/boat_marker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Boat marker
4+
-----------
25
6+
Creates a marker shaped like a boat. Optionally you can append a wind direction.
7+
"""
38
import json
49

510
from .plugin import Plugin
611

712
class BoatMarker(Plugin):
8-
"""Adds a MarkerCluster layer on the map."""
13+
"""Adds a BoatMarker layer on the map."""
914
def __init__(self, position=None, heading=0, wind_heading=None, wind_speed=0, **kwargs):
1015
"""Creates a BoatMarker plugin to append into a map with
1116
Map.add_plugin.

folium/plugins/geo_json.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
GeoJson plugin
4+
--------------
25
6+
Add a geojson feature collection on a folium map.
7+
"""
38
import json
49

510
from .plugin import Plugin

folium/plugins/layer.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Layer plugin
4+
------------
25
6+
Add layers and layer control to the map.
7+
"""
38
from .plugin import Plugin
49

510
class Layer(Plugin):
611
"""Adds a layer to the map."""
712
def __init__(self, url=None, layer_name = None, min_zoom=1, max_zoom=18, attribution=''):
13+
"""Crates a layer object to be added on a folium map.
14+
15+
Parameters
16+
----------
17+
url : str
18+
The url of the layer service, in the classical leaflet form.
19+
example: url='//otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'
20+
layer_name : str
21+
Tha name of the layer that will be displayed in the layer control.
22+
If None, a random hexadecimal string will be created.
23+
min_zoom : int, default 1
24+
The minimal zoom allowed for this layer
25+
max_zoom : int, default 18
26+
The maximal zoom allowed for this layer
27+
attribution : str, default ''
28+
Tha atribution string for the layer.
29+
"""
830
super(Layer, self).__init__()
931
self.plugin_name = 'Layer'
1032
self.tile_url = url
@@ -16,6 +38,7 @@ def __init__(self, url=None, layer_name = None, min_zoom=1, max_zoom=18, attribu
1638
self.object_name = layer_name
1739

1840
def render_js(self, nb):
41+
"""Generates the JS part of the plugin."""
1942
return """
2043
var layer_"""+self.object_id+""" = L.tileLayer('"""+self.tile_url+"""', {
2144
maxZoom: """+str(self.max_zoom)+""",
@@ -27,14 +50,23 @@ def render_js(self, nb):
2750

2851
class LayerControl(Plugin):
2952
"""Adds a layer control to the map."""
30-
def __init__(self):
53+
def __init__(self, base_layer_name="Base Layer"):
54+
"""Creates a LayerControl object to be added on a folium map.
55+
56+
Parameters
57+
----------
58+
base_layer_name : str, default "Base Layer"
59+
The name of the base layer that you want to see on the control.
60+
"""
3161
super(LayerControl, self).__init__()
3262
self.plugin_name = 'LayerControl'
63+
self.base_layer_name = base_layer_name
3364

3465
def render_js(self, nb):
66+
"""Generates the JS part of the plugin."""
3567
return """
3668
var baseLayer = {
37-
"Base Layer": base_tile,"""+\
69+
"%s": base_tile,"""% self.base_layer_name+\
3870
",".join(['"%s" : layer_%s ' % (x.object_name,x.object_id) for x in self.map.plugins['Layer']])+\
3971
"""};
4072

folium/plugins/marker_cluster.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Marker Cluster plugin
4+
---------------------
25
6+
Creates a MarkerCluster plugin to add on a folium map.
7+
"""
38
import json
49

510
from .plugin import Plugin

folium/plugins/plugin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Plugin
4+
------
25
6+
A generic class for creating plugins.
7+
Basic plugin object that does nothing.
8+
Other plugins may inherit from this one.
9+
"""
310
from uuid import uuid4
411

512
class Plugin(object):

folium/plugins/scroll_zoom_toggler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
ScrollZoomToggler plugin
4+
------------------------
25
6+
Adds a button to enable/disable zoom scrolling.
7+
"""
38
from .template_plugin import TemplatePlugin
49

510
class ScrollZoomToggler(TemplatePlugin):

folium/plugins/template_plugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Template Plugin
24
5+
A generic class to create plugins based on jinja2 templates.
6+
"""
37
from .plugin import Plugin
48
from jinja2 import Template
59
from uuid import uuid4

folium/plugins/terminator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Terminator plugin
4+
-----------------
25
6+
Leaflet.Terminator is a simple plug-in to the Leaflet library to overlay day and night regions on maps.
7+
"""
38
try:
49
from urllib.request import urlopen as _urlopen
510
except:

0 commit comments

Comments
 (0)