Marker component for adding markers to MapLibre maps.
Examples
Basic marker:
<.marker
id="marker-1"
map_id="my-map"
lng_lat={[-74.5, 40]}
/>Styled marker with popup:
<.marker
id="marker-nyc"
map_id="my-map"
lng_lat={[-74.5, 40]}
color="red"
scale={1.2}
popup_text="New York City - The Big Apple"
/>Draggable marker with events:
<.marker
id="draggable-marker"
map_id="my-map"
lng_lat={@marker_position}
draggable
/>
def handle_event("marker:drag_end", %{"markerId" => id, "lngLat" => lngLat}, socket) do
{:noreply, assign(socket, marker_position: lngLat)}
end
Summary
Functions
Renders a marker on the map.
Functions
Renders a marker on the map.
Attributes
id(required) - Unique identifier for the markermap_id(required) - ID of the map to add the marker tolng_lat(required) - Marker position as[longitude, latitude]color- Marker color (hex or named color). Defaults to"#3FB1CE"scale- Marker scale. Defaults to1rotation- Marker rotation in degrees. Defaults to0draggable- Whether the marker can be dragged. Defaults tofalseanchor- Marker anchor point. One of:"center","top","bottom","left","right", etc.offset- Pixel offset as[x, y]pitch_alignment- How marker is aligned to pitch. One of:"map","viewport","auto"rotation_alignment- How marker is aligned to rotation. One of:"map","viewport","auto"
Events
The marker emits the following events:
marker:clicked- Fired when the marker is clickedmarker:drag_start- Fired when drag starts (if draggable)marker:dragging- Fired while draggingmarker:drag_end- Fired when drag ends
Slots
popup- Optional popup content to display when marker is clicked
Attributes
id(:string) (required)map_id(:string) (required)lng_lat(:list) (required)color(:string) - Defaults to"#3FB1CE".scale(:float) - Defaults to1.0.rotation(:integer) - Defaults to0.draggable(:boolean) - Defaults tofalse.anchor(:string) - Defaults tonil.offset(:list) - Defaults tonil.pitch_alignment(:string) - Defaults to"auto".rotation_alignment(:string) - Defaults to"auto".popup_text(:string) - Defaults tonil.popup_html(:string) - Defaults tonil.- Global attributes are accepted.