StaticMaps.Marker (staticmaps v0.1.0)

Copy Markdown View Source

A point marked on the map.

The default marker is a pin 24 × 36 logical pixels, with its tip on the coordinate, so it extends 12 pixels either side of the point and 36 above it. A custom icon has its own size, and its anchor is the pixel that sits on the coordinate. Fitting the view counts the whole marker, not just the point, so a pin near the edge is never cut off.

Options

  • :color — the default pin's colour, "#rgb", "#rrggbb" or {r, g, b}
  • :label — up to three characters written in the default pin's head
  • :icon — SVG or image bytes to draw instead of the default pin
  • :anchor — {x, y} in the icon's pixels that sits on the coordinate; defaults to the middle of the icon's bottom edge

Summary

Types

Pixels a marker reaches from its coordinate: {left, top, right, bottom}.

A custom icon: its bytes, whether they are SVG, which is drawn sharp at any scale, or a raster image, which is scaled up for scale: 2.

t()

Functions

How far marker reaches from its coordinate, in logical pixels.

Builds a marker from its options, or says which option is wrong.

The SVG of a default pin, 24 × 36 with its tip at the bottom centre.

Types

extent()

Pixels a marker reaches from its coordinate: {left, top, right, bottom}.

icon()

@type icon() :: %{bytes: binary(), kind: :svg | :raster}

A custom icon: its bytes, whether they are SVG, which is drawn sharp at any scale, or a raster image, which is scaled up for scale: 2.

t()

@type t() :: %StaticMaps.Marker{
  anchor: {non_neg_integer(), non_neg_integer()},
  color: [0..255],
  icon: icon() | nil,
  label: String.t() | nil,
  lat: number(),
  lng: number(),
  size: {pos_integer(), pos_integer()}
}

Functions

extent(marker)

@spec extent(t()) :: extent()

How far marker reaches from its coordinate, in logical pixels.

iex> StaticMaps.Marker.extent(%StaticMaps.Marker{lat: 0, lng: 0})
{12, 36, 12, 0}

new(lat, lng, opts)

@spec new(number(), number(), keyword()) :: {:ok, t()} | {:error, String.t()}

Builds a marker from its options, or says which option is wrong.

pin_svg(marker)

@spec pin_svg(t()) :: String.t()

The SVG of a default pin, 24 × 36 with its tip at the bottom centre.

Text in it is escaped, so a label cannot inject markup.