gleaflet/marker
Types
A marker that can be placed on a Leaflet map.
Contains the internal marker reference along with its metadata including latitude, longitude, name, and optional popup content.
Fields
internal- The internal marker representation (FFI use only)lat- Latitude coordinate of the markerlon- Longitude coordinate of the markername- Display name for the markerpopup- Optional popup text that appears when the marker is clicked
pub type LeafletMarker {
LeafletMarker(
internal: LeafletMarkerInternal,
lat: Float,
lon: Float,
name: String,
icon: option.Option(icon.LeafletIcon),
popup: option.Option(String),
)
}
Constructors
-
LeafletMarker( internal: LeafletMarkerInternal, lat: Float, lon: Float, name: String, icon: option.Option(icon.LeafletIcon), popup: option.Option(String), )
Internal representation of a Leaflet marker. This type is used to interface with the JavaScript FFI and should not be created directly.
pub type LeafletMarkerInternal
A marker builder that can be configured with optional properties.
Use the builder pattern to create markers with optional popup and icon.
Start with new_marker and chain with_popup and with_icon functions,
then call build to create the final marker.
Fields
lat- Latitude coordinate of the markerlon- Longitude coordinate of the markername- Display name for the markericon- Optional icon for the markerpopup- Optional popup text that appears when the marker is clicked
pub type MarkerBuilder {
MarkerBuilder(
lat: Float,
lon: Float,
name: String,
icon: option.Option(icon.LeafletIcon),
popup: option.Option(String),
)
}
Constructors
-
MarkerBuilder( lat: Float, lon: Float, name: String, icon: option.Option(icon.LeafletIcon), popup: option.Option(String), )
Values
pub fn add_marker_to_map(
map map: map.LeafletMap,
marker marker: LeafletMarker,
) -> map.LeafletMap
Adds a marker to the map.
Handles both markers with and without popup content. If the marker has a popup, it will be attached to the marker before adding to the map.
Parameters
map- The map instance to add the marker tomarker- The marker to add
Example
let marker = marker.new_marker(40.7128, -74.0060, "New York")
|> marker.with_popup("Welcome to NYC!")
|> marker.build()
let map =
map.new_map("my-map-div")
|> marker.add_marker_to_map(marker)
pub fn build(builder: MarkerBuilder) -> LeafletMarker
Builds the final marker from the builder configuration.
This creates the internal marker representation and returns the final
LeafletMarker that can be added to maps.
Parameters
builder- The marker builder to build
Example
let marker = marker.new_marker(40.7128, -74.0060, "New York")
|> marker.with_popup("Welcome to NYC!")
|> marker.build()
pub fn new_marker(
lat lat: Float,
lon lon: Float,
name name: String,
) -> MarkerBuilder
Creates a new marker builder with the required coordinates and name.
This is the starting point for the builder pattern. Use with_popup and
with_icon to add optional properties, then call build to create the marker.
Parameters
lat- Latitude coordinate for the markerlon- Longitude coordinate for the markername- Display name for the marker
Example
let marker = marker.new_marker(40.7128, -74.0060, "New York")
|> marker.with_popup("The Big Apple")
|> marker.build()
pub fn remove_marker_from_map(
map map: map.LeafletMap,
marker marker: LeafletMarker,
) -> Nil
Removes a marker from the map.
Parameters
map- The map instance to remove the marker frommarker- The marker to remove
Example
let marker = marker.new_marker(40.7128, -74.0060, "New York")
|> marker.build()
let map_with_marker =
map.new_map("my-map-div")
|> marker.add_marker_to_map(marker)
// Later, remove the marker
let map_without_marker = marker.remove_marker_from_map(map_with_marker, marker)
pub fn with_icon(
builder: MarkerBuilder,
icon: icon.LeafletIcon,
) -> MarkerBuilder
Adds an icon to the marker builder.
Parameters
builder- The marker builder to add the icon toicon- Icon to use for the marker
Example
let custom_icon = icon.LeafletIcon(
icon_url: "/marker.png",
shadow_url: "/shadow.png",
icon_size: #(25, 41),
shadow_size: #(41, 41),
icon_anchor: #(12, 41),
shadow_anchor: #(12, 41),
popup_anchor: #(1, -34),
)
let marker = marker.new_marker(40.7128, -74.0060, "New York")
|> marker.with_icon(custom_icon)
|> marker.build()
pub fn with_popup(
builder: MarkerBuilder,
popup: String,
) -> MarkerBuilder
Adds a popup to the marker builder.
Parameters
builder- The marker builder to add the popup topopup- Popup text that appears when the marker is clicked
Example
let marker = marker.new_marker(40.7128, -74.0060, "New York")
|> marker.with_popup("Welcome to NYC!")
|> marker.build()