Adds an icon sprite to the map's style, next to the style's own.
<HoloMap.Sprite id="brand" url="https://cdn.example.com/sprites/brand" />
<HoloMap.Layer.Symbol
id="shops"
source="shops"
layout={%{icon_image: "brand:shop", icon_allow_overlap: true}}
/>A sprite is a sheet of icons in one image, with a JSON file that names each
icon and says where it sits in the image. HoloMap.Image registers one icon
per component; a sprite brings a whole set at once, the way a style ships
its own.
Naming the icons
A layer names an icon of this sprite as "<id>:<icon>": "brand:shop" is
the icon called shop in the sprite whose id is "brand". The prefix
keeps the sprite's names apart from the style's own icons and from the
images HoloMap.Image registers. A name that matches nothing draws nothing,
and on_style_image_missing on HoloMap.Map reports it.
The URL
url names the sprite without its extension. MapLibre requests
url <> ".json" and url <> ".png", or url <> "@2x.json" and
url <> "@2x.png" on a screen with more than one device pixel per CSS
pixel, so serve all four. MapLibre takes only an absolute URL. A URL
relative to the page, such as "/sprites/brand", is resolved against it by
the browser runtime.
Props
| Prop | Type | Notes |
|---|---|---|
id | string | Required. The prefix layers name the icons with |
url | string | Required. Where the sprite is, without its extension |
Lifetime
The sprite is added once the style has loaded, and taken off the map when
the component stops rendering. A new url replaces the sprite: its icons
are gone until the new ones arrive. MapLibre loads them in the background
and fires styledata once they have, which on_style_data hears. A sprite
that fails to load is reported through on_error.
A change to HoloMap.Map's style keeps the sprite. MapLibre diffs the new
style with the sprite in it, after the new style's own, and loads nothing
again unless the new style's own sprite differs from the old one's: MapLibre
then loads every sprite on the map again, this one included, which the
browser usually answers from its cache. A style MapLibre builds from scratch
has the sprite added again once it has loaded. After a WebGL context loss
MapLibre builds the style again with the sprite in it.
An id the style uses
A style can bring sprites of its own, and a style given one sprite URL has
one called "default". A component whose id the style's sprite uses adds
nothing: the style's sprite is the one layers draw from, the component
neither changes nor removes it, and the browser runtime logs a warning
naming it. Give the sprite an id the style does not use. MapLibre also
refuses a sprite whose URL the style already loads under another id, and
reports it through on_error.
Summary
Functions
Returns true to indicate that the callee module is a component module (has "use Hologram.Component" directive).
Returns the list of property definitions for the compiled component.
Functions
@spec __is_hologram_component__() :: boolean()
Returns true to indicate that the callee module is a component module (has "use Hologram.Component" directive).
Examples
iex> __is_hologram_component__()
true
Returns the list of property definitions for the compiled component.