From d621d9a8f6a739e02df4fa561ef8bc1c3fbe356d Mon Sep 17 00:00:00 2001 From: mosessamofficial-sys Date: Wed, 25 Feb 2026 13:07:21 +0530 Subject: [PATCH 1/2] Add documentation for Control class (issue #2150) --- docs/user_guide/ui_elements.rst | 1 + docs/user_guide/ui_elements/control.md | 54 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 docs/user_guide/ui_elements/control.md diff --git a/docs/user_guide/ui_elements.rst b/docs/user_guide/ui_elements.rst index 55e02e809c..9389a18d95 100644 --- a/docs/user_guide/ui_elements.rst +++ b/docs/user_guide/ui_elements.rst @@ -6,5 +6,6 @@ UI elements ui_elements/layer_control + ui_elements/control ui_elements/popups ui_elements/icons diff --git a/docs/user_guide/ui_elements/control.md b/docs/user_guide/ui_elements/control.md new file mode 100644 index 0000000000..1cf7493a8b --- /dev/null +++ b/docs/user_guide/ui_elements/control.md @@ -0,0 +1,54 @@ +```{code-cell} ipython3 +--- +nbsphinx: hidden +--- +import folium +from folium.features import Control +``` + +# Controls + +Leaflet controls are UI elements anchored to the corners of a map (zoom, scale, +custom buttons, etc.). Folium exposes a generic `Control` class that can render +any `L.Control.` class. This is useful when you want to wire up a Leaflet +plugin directly in user code without creating a new `folium.plugins` class. + +## Built-in controls + +```{code-cell} ipython3 +m = folium.Map(location=[45, 0], zoom_start=4, zoom_control=False) + +Control("Zoom", position="topleft").add_to(m) +Control("Scale", position="bottomleft").add_to(m) + +m +``` + +## Leaflet plugin controls + +If a Leaflet plugin exposes a `L.Control.` class, you can wire it up +directly and attach its JS/CSS assets to the map. + +```python +import folium +from folium.features import Control + +m = folium.Map(location=[45, 0], zoom_start=4) + +control = Control( + "MyPlugin", + position="topright", + # Any plugin options become JS options. + foo="bar", +) + +# Add the plugin's JS/CSS assets. +control.add_js_link("my-plugin", "https://example.com/leaflet.my-plugin.min.js") +control.add_css_link("my-plugin", "https://example.com/leaflet.my-plugin.css") + +control.add_to(m) +m +``` + +For reusable plugins, consider creating a dedicated `folium.plugins` class. For +one-off integrations, `Control` keeps the wiring minimal. From a455912df7b1ca815dc54b35400bcf2a180c403e Mon Sep 17 00:00:00 2001 From: mosessamofficial-sys Date: Wed, 25 Feb 2026 15:03:46 +0530 Subject: [PATCH 2/2] Fix DivIcon text documentation formatting --- docs/user_guide/ui_elements/icons.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/user_guide/ui_elements/icons.md b/docs/user_guide/ui_elements/icons.md index f5024772c1..d7033eab27 100644 --- a/docs/user_guide/ui_elements/icons.md +++ b/docs/user_guide/ui_elements/icons.md @@ -54,3 +54,21 @@ folium.Marker( m ``` + + +## Adding text using DivIcon + +You can display custom text on the map using a DivIcon. + +```{code-cell} ipython3 +m = folium.Map(location=[0, 0], zoom_start=2) + +folium.Marker( + [0, 0], + icon=folium.DivIcon(html='
Hello
') +).add_to(m) + +m + +``` +