From d621d9a8f6a739e02df4fa561ef8bc1c3fbe356d Mon Sep 17 00:00:00 2001 From: mosessamofficial-sys Date: Wed, 25 Feb 2026 13:07:21 +0530 Subject: [PATCH 1/4] 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 b68ab3f3ad57e3c42e87af3a0f41ce329bab6804 Mon Sep 17 00:00:00 2001 From: mosessamofficial-sys Date: Thu, 26 Feb 2026 10:52:44 +0530 Subject: [PATCH 2/4] Added real world example --- docs/user_guide/ui_elements/control.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/user_guide/ui_elements/control.md b/docs/user_guide/ui_elements/control.md index 1cf7493a8b..b83b05b6c7 100644 --- a/docs/user_guide/ui_elements/control.md +++ b/docs/user_guide/ui_elements/control.md @@ -36,15 +36,22 @@ from folium.features import Control m = folium.Map(location=[45, 0], zoom_start=4) control = Control( - "MyPlugin", + "Fullscreen", position="topright", # Any plugin options become JS options. - foo="bar", + title="View Fullscreen", + titleCancel="Exit Fullscreen", ) # 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_js_link( + "leaflet-fullscreen", + "https://unpkg.com/leaflet.fullscreen@1.6.0/Control.FullScreen.js", +) +control.add_css_link( + "leaflet-fullscreen", + "https://unpkg.com/leaflet.fullscreen@1.6.0/Control.FullScreen.css", +) control.add_to(m) m From 8c883dc7ad030224b72d8f5899ea534e94e586d0 Mon Sep 17 00:00:00 2001 From: mosessamofficial-sys Date: Thu, 26 Feb 2026 11:28:01 +0530 Subject: [PATCH 3/4] resolved issue --- docs/user_guide/ui_elements/control.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user_guide/ui_elements/control.md b/docs/user_guide/ui_elements/control.md index b83b05b6c7..72e4ffd45d 100644 --- a/docs/user_guide/ui_elements/control.md +++ b/docs/user_guide/ui_elements/control.md @@ -36,7 +36,7 @@ from folium.features import Control m = folium.Map(location=[45, 0], zoom_start=4) control = Control( - "Fullscreen", + "fullscreen", position="topright", # Any plugin options become JS options. title="View Fullscreen", @@ -46,7 +46,7 @@ control = Control( # Add the plugin's JS/CSS assets. control.add_js_link( "leaflet-fullscreen", - "https://unpkg.com/leaflet.fullscreen@1.6.0/Control.FullScreen.js", + "https://unpkg.com/leaflet-fullscreen@1.6.0/dist/leaflet.fullscreen.umd.js", ) control.add_css_link( "leaflet-fullscreen", From 3c2f94d529bfb9b62b4413ad9707337edbeb09fa Mon Sep 17 00:00:00 2001 From: mosessamofficial-sys Date: Thu, 26 Feb 2026 11:35:35 +0530 Subject: [PATCH 4/4] resolved documentation issue --- docs/user_guide/ui_elements/control.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user_guide/ui_elements/control.md b/docs/user_guide/ui_elements/control.md index 72e4ffd45d..d578c91949 100644 --- a/docs/user_guide/ui_elements/control.md +++ b/docs/user_guide/ui_elements/control.md @@ -29,7 +29,7 @@ m 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 +```{code-cell} ipython3 import folium from folium.features import Control