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 marker
  • lon - Longitude coordinate of the marker
  • name - Display name for the marker
  • popup - 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

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

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 to
  • marker - The marker to add

Example

let marker = gleaflet.new_marker(40.7128, -74.0060, "New York", Some("Welcome to NYC!"))
let map =
  gleaflet.new_map("my-map-div")
  |> marker.add_marker_to_map(marker)
pub fn new_marker(
  lat lat: Float,
  lon lon: Float,
  name name: String,
  icon icon: option.Option(icon.LeafletIcon),
  popup popup: option.Option(String),
) -> LeafletMarker

Creates a new marker with the specified properties.

Parameters

  • lat - Latitude coordinate for the marker
  • lon - Longitude coordinate for the marker
  • name - Display name for the marker
  • popup - Optional popup text that appears when the marker is clicked

Example

let marker = gleaflet.new_marker(40.7128, -74.0060, "New York", Some("The Big Apple"))
let marker_without_popup = gleaflet.new_marker(51.5074, -0.1278, "London", None)
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 from
  • marker - The marker to remove

Example

let marker = gleaflet.new_marker(40.7128, -74.0060, "New York", None)
let map_with_marker =
  map.new_map("my-map-div")
  |> marker.add_marker_to_map(marker)

// Later, remove the marker
let map_without_marker = gleaflet.remove_marker_from_map(map_with_marker, marker)
Search Document