gleaflet/icon
Types
An icon builder that can be configured with optional properties.
Use the builder pattern to create icons with optional shadow and anchor properties.
Start with new_icon and chain with_shadow, with_icon_size, with_icon_anchor,
with_shadow_anchor, and with_popup_anchor functions, then call build to create the final icon.
Fields
icon_url- URL of the icon image (required)shadow_url- Optional URL of the shadow imageicon_size- Optional size of the icon (width, height)shadow_size- Optional size of the shadow (width, height)icon_anchor- Optional point of the icon which corresponds to marker’s locationshadow_anchor- Optional point of the shadow which corresponds to marker’s locationpopup_anchor- Optional point from which popup should open relative to icon anchor
pub type IconBuilder {
IconBuilder(
icon_url: String,
shadow_url: option.Option(String),
icon_size: option.Option(#(Int, Int)),
shadow_size: option.Option(#(Int, Int)),
icon_anchor: option.Option(#(Int, Int)),
shadow_anchor: option.Option(#(Int, Int)),
popup_anchor: option.Option(#(Int, Int)),
)
}
Constructors
-
IconBuilder( icon_url: String, shadow_url: option.Option(String), icon_size: option.Option(#(Int, Int)), shadow_size: option.Option(#(Int, Int)), icon_anchor: option.Option(#(Int, Int)), shadow_anchor: option.Option(#(Int, Int)), popup_anchor: option.Option(#(Int, Int)), )
LeafletIcon is a struct that represents a Leaflet icon.
pub type LeafletIcon {
LeafletIcon(
icon_url: String,
shadow_url: String,
icon_size: #(Int, Int),
shadow_size: #(Int, Int),
icon_anchor: #(Int, Int),
shadow_anchor: #(Int, Int),
popup_anchor: #(Int, Int),
)
}
Constructors
-
LeafletIcon( icon_url: String, shadow_url: String, icon_size: #(Int, Int), shadow_size: #(Int, Int), icon_anchor: #(Int, Int), shadow_anchor: #(Int, Int), popup_anchor: #(Int, Int), )
Values
pub fn build(builder: IconBuilder) -> LeafletIcon
Builds the final icon from the builder configuration.
This creates the final LeafletIcon with sensible defaults for any unset properties.
Default values:
- shadow_url: “” (empty string, no shadow)
- icon_size: #(25, 41) (typical Leaflet marker size)
- shadow_size: #(41, 41) (typical Leaflet shadow size)
- icon_anchor: #(12, 41) (bottom center of typical marker)
- shadow_anchor: #(12, 41) (bottom center of typical shadow)
- popup_anchor: #(0, -34) (above the marker)
Parameters
builder- The icon builder to build
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_icon_size(#(25, 41))
|> icon.with_icon_anchor(#(12, 41))
|> icon.build()
pub fn new_icon(icon_url: String) -> IconBuilder
Creates a new icon builder with the required icon URL.
This is the starting point for the builder pattern. Use the various with_*
functions to add optional properties, then call build to create the icon.
Parameters
icon_url- URL of the icon image
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_icon_size(#(25, 41))
|> icon.with_icon_anchor(#(12, 41))
|> icon.build()
pub fn with_icon_anchor(
builder: IconBuilder,
icon_anchor: #(Int, Int),
) -> IconBuilder
Sets the icon anchor for the icon builder.
The icon anchor is the point of the icon which will correspond to marker’s location.
Parameters
builder- The icon builder to add the icon anchor toicon_anchor- Anchor point as (x, y) tuple
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_icon_size(#(25, 41))
|> icon.with_icon_anchor(#(12, 41))
|> icon.build()
pub fn with_icon_size(
builder: IconBuilder,
icon_size: #(Int, Int),
) -> IconBuilder
Sets the icon size for the icon builder.
Parameters
builder- The icon builder to add the icon size toicon_size- Size of the icon as (width, height) tuple
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_icon_size(#(25, 41))
|> icon.build()
pub fn with_popup_anchor(
builder: IconBuilder,
popup_anchor: #(Int, Int),
) -> IconBuilder
Sets the popup anchor for the icon builder.
The popup anchor is the point from which the popup should open relative to the icon anchor.
Parameters
builder- The icon builder to add the popup anchor topopup_anchor- Popup anchor point as (x, y) tuple
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_popup_anchor(#(0, -34))
|> icon.build()
pub fn with_shadow(
builder: IconBuilder,
shadow_url: String,
) -> IconBuilder
Sets the shadow URL for the icon builder.
Parameters
builder- The icon builder to add the shadow URL toshadow_url- URL of the shadow image
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_shadow("/shadow.png")
|> icon.build()
pub fn with_shadow_anchor(
builder: IconBuilder,
shadow_anchor: #(Int, Int),
) -> IconBuilder
Sets the shadow anchor for the icon builder.
The shadow anchor is the point of the shadow which will correspond to marker’s location.
Parameters
builder- The icon builder to add the shadow anchor toshadow_anchor- Shadow anchor point as (x, y) tuple
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_shadow("/shadow.png")
|> icon.with_shadow_anchor(#(12, 41))
|> icon.build()
pub fn with_shadow_size(
builder: IconBuilder,
shadow_size: #(Int, Int),
) -> IconBuilder
Sets the shadow size for the icon builder.
Parameters
builder- The icon builder to add the shadow size toshadow_size- Size of the shadow as (width, height) tuple
Example
let icon = icon.new_icon("/marker.png")
|> icon.with_shadow("/shadow.png")
|> icon.with_shadow_size(#(41, 41))
|> icon.build()