| add_control | R Documentation |
This function adds a custom control to a Mapbox GL or MapLibre GL map. It allows you to create custom HTML element controls and add them to the map.
add_control(
map,
html,
position = "top-right",
className = NULL,
id = NULL,
...
)
map |
A map object created by the |
html |
Character string containing the HTML content for the control. |
position |
The position of the control. Can be one of "top-left", "top-right", "bottom-left", or "bottom-right". Default is "top-right". |
className |
Optional CSS class name for the control container. |
id |
Optional unique identifier for the control. If not provided, defaults to "custom".
This ID can be used with |
... |
Additional arguments passed to the JavaScript side. |
The modified map object with the custom control added.
## Not run:
library(mapgl)
# Basic custom control
maplibre() |>
add_control(
html = "<div style='background-color: white; padding: 5px;'>
<p>Custom HTML</p>
<img src='path/to/image.png' alt='image'/>
</div>",
position = "top-left"
)
# Custom control with specific ID for selective removal
maplibre() |>
add_control(
html = "<div style='background: blue; color: white; padding: 10px;'>
My Control
</div>",
position = "top-right",
id = "my_custom_control"
)
# Later, remove only this specific control
maplibre_proxy("map") |>
clear_controls("my_custom_control")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.