Renders map images on the server.
render/1 fetches the tiles that cover a view from a tile source, stitches them into
one image, draws markers and the source's attribution strip over it, and returns the
encoded PNG or JPEG. The view is either a centre and zoom, or fitted to bounds and
markers. StaticMaps.Plug serves the same renders from signed URLs.
Summary
Functions
Renders a map and returns the encoded image.
Functions
@spec render(keyword()) :: {:ok, binary()} | {:error, Exception.t()}
Renders a map and returns the encoded image.
Options
:center—{lat, lng}in degrees. Required unless:boundsor:markersare given, in which case it is fitted when left out.:zoom— a non-negative integer that the source serves. Required unless:boundsor:markersare given, in which case it is fitted when left out. A 512-pixel source serves render zooms one above its tile zooms; seeStaticMaps.Source.:bounds—{{south, west}, {north, east}}in degrees, to fit the view to;west > eastcrosses the antimeridian.:markers— a list of{lat, lng}or{lat, lng, opts}, drawn in order and fitted into the view; seeStaticMaps.Markerforopts. Defaults to[].:padding— logical pixels kept clear around:boundsand:markerswhen the view is fitted; defaults to20.:source— a module implementingStaticMaps.Source, or{module, opts}, or a list of them: the first is the primary source and the rest are fallback sources, tried in order when it fails. A fallback that does not serve the zoom is skipped. Defaults toStaticMaps.Source.OSM.:size—{width, height}in logical pixels, before:scale, at most{2048, 2048}; defaults to{600, 400}:scale—1or2; defaults to1:format—:pngor:jpeg; defaults to:png:background—"#rrggbb","#rgb"or{r, g, b}, painted wherever no tile covers the image; defaults to"#e0e0e0":attribution— where the attribution strip goes:truefor the bottom right,[position: :bottom_right | :bottom_left], orfalseto leave it off. Defaults totrue. A fitted view keeps the strip's height clear.:on_tile_error— what happens when every source has a tile that cannot be fetched or decoded.:failreturns the error;:fillreturns the image from the first source that was tried, with its failed tiles painted:background. Defaults to:fail.
Errors
%ArgumentError{}for invalid options%StaticMaps.TileError{}when the only source tried has tiles that fail%StaticMaps.UnavailableError{}otherwise, when every source failed or was skipped%RuntimeError{}when libvips fails, such as when no font is installed to draw the attribution with
Errors are returned as {:error, exception} rather than raised.