Expand description
The source type contract: what a crate implements to add a source type
whose sources the renderer draws. mln_builtins implements it for the
style specification’s source types.
A source type has two halves, which
RegistryBuilder::add_source_type::<T>()
registers together. It fails for a name that another type took, and for
a type whose halves name different kinds of data.
- The style half, a marker type that implements
mln_style’sStyleSourceType: the type’s name and its kind of data (SourceTypeInfo), and the options it reads from style JSON. It may be another crate’s, as the specification’s types aremln_style’s, so that a tool that only parses styles needs no engine. - The engine half,
SourceType, whoseStylenames the style half: how the map loads what the style doesn’t hold itself, such as a TileJSON or GeoJSON data, into the source’s description, what a source reports about itself and offline downloads fetch, and what it supplies the renderer.
§What a source type writes
- How its description loads, if it has one:
SourceType::loadsays what loads for a source’s options, which the map’s loader fetches and hands toSourceType::describeorSourceType::describe_image. The style holds the description without knowing its type, in the source’sSourceData::description; the type reads it back withSourceData::description::<Self::Description>(). - Its kind of data, the
Datathat its sources supply: tiles of geometry, which the engine lays out into the buckets of the layers that draw them, or of raster images or raster-dem elevations, which it decodes. A new kind of data is a change to the engine, not a source type. - Its supply, made once as a source joins the
renderer’s style: tiles that a
DataOriginloads (Supply::tiles), or, for raster data, one image at four coordinates that the engine reads from each version of the source (Supply::image), as the image source type supplies. - Its origin.
DataOrigin::updatetakes in the source as the style has it and returns what its tilesCover.DataOrigin::startstarts each new tile and returns the origin’s state of it, itsTile, which the engine keeps with the tile and drops as the tile goes, which lets go of what it holds. Through the tile’sLoadContextthe origin begins a load, whoseRepliersends what the load gets back from any thread toDataOrigin::receive, and delivers what it brought: an item of the source’s kind, nothing for an empty tile, or missing for a tile the source doesn’t have. An origin that loads cheaply first, or retries, or keeps what it loaded fresh, also writesset_necessity,retryandfailed, as the tileset’s does.
§When the hooks run
The engine runs SourceType::supply and every hook of the origin one
at a time on the renderer’s thread, never one from within another, so an
origin and its tiles’ states needn’t be Send. In each of the
renderer’s updates, it first hands each tile the replies that arrived
for its latest load (receive), then, per
source, runs update with the source as the style
has it, the same version until the style changes it, so the origin tells
a new version from the last it took in and then clears or loads its
tiles again (OriginUpdate). With the cover update returns, the
engine works out the view’s tiles: it starts those
it makes, and sets the necessity of each it
keeps, as it first keeps it in the update and as it lets it go into its
cache. The engine runs retry on each required
tile of the cover before each still image, and
failed when what a tile took in fails to lay out
or decode.
A load’s work runs wherever the origin puts it: on the renderer’s pool
(OriginUpdate::pool), which runs on the renderer’s thread in the
browser, on a file source’s threads, or in a host’s callback. Its
Replier and its replies are Send, and a replier sends as many
replies as its load has. What the tiles take in lays out or decodes on
the tile workers, through the worker codec where they run apart, or, for
geometry of a source that updates synchronously, lays out in the update
that delivers it; an origin’s own types and values never cross the
codec.
§What the engine owns
The engine owns how MapLibre loads tiles; the origin owns where their
data comes from. The engine decides which tiles the view needs, in which
order their requests start (LoadContext::order), and which it keeps
in its cache and evicts: a tile with nothing to show whose origin said
its load failed and waits for a retry
isn’t loading, so the cache lets go of it, and a cached tile whose data
its origin said may no longer be shown (TileTimes::usable_until)
goes rather than come back. While a tile has nothing to show, it draws
the tile’s children or parent that can draw; it makes a missing parent
only once the tile has loaded, or has
tried what it can while optional, so a
parent never loads for a tile that loads at once. It makes a tile in a
new world copy show the same tile’s contents in another, which
WorldCopy::take_into makes the new tile’s answer, and hands a reply to
the origin only while its load is the tile’s latest. It lays out and
decodes what tiles take in, knows when a tile has done what it can, and
starts a failed tile over when its retry loads anew. How data is
requested, cached, revalidated, kept fresh and retried is the origin’s.
§Necessity
A tile is required while the view needs it, and optional while it is
only a fallback or a prefetch the view can do without, or waits in the
cache. Necessity is a hint: an origin with a cheap way to get data, such
as a cache, may try only that while the tile is optional, and say when
it did (LoadContext::tried_optional), so that the engine makes and
loads a parent to stand in; it asks for more as the tile becomes
required, and stops as it becomes optional, as the tileset’s origin does
with its network requests. An origin without one loads every tile as it
starts and ignores necessity: a parent draws for its loading tiles only
if the cover already has it.
Structs§
- Cover
- What a source’s tiles cover, and how the views they draw choose them: their size in pixels, the zoom levels that have tiles of their own, beyond which they are drawn scaled up, the bounds outside which there are none, and how a view picks and lays out its tiles.
- Load
Context - A tile, as a
DataOrigin’s hook sees it: what the engine knows of it, and what the origin can do to it. - MapSettings
- What the map says of its tiles, which an origin reads as it updates
(
OriginUpdate::map). - Origin
Update - A
DataOrigin’s update: the source as the style has it, what the map says of its tiles, and the tiles, which the origin can clear or load again. - Replier
- Sends the replies of one of a tile’s loads to the tile, from any thread.
- Source
Image - An image at coordinates: what an image source shows.
- Source
Summary - What a source reports about itself, whichever its type. A member that
the type doesn’t have is
None. - Supply
- What a source supplies the renderer: tiles of the kind
K, which a data origin loads, or one image at four coordinates. - Tile
Times - What a tile’s origin says of the times of its data: when it was modified, when it expires, and until when it may be shown at all, which the cache keeps to.
- World
Copy - The same tile in another world copy, from whose contents a new tile
starts (
DataOrigin::start): the origin’s state of it, and what taking it settles the new tile on.
Enums§
- DemTiles
- The tiles of a raster-dem source. A load delivers a tile’s encoded image,
which the engine decodes with the elevation encoding its origin set
(
OriginUpdate::set_encoding). A layer type that draws elevations draws them as its input. - Fetch
- A resource that a source loads its description from, by its URL.
- Geometry
Tiles - The tiles of a geometry source, whose features the engine lays out into
the buckets of the layers that draw them. A load delivers a tile’s
TileData. - Load
- How a source’s description loads, as its type says from its data.
- Offline
Resources - What an offline download of a source fetches.
- Raster
Tiles - The tiles of a raster source. A load delivers a tile’s encoded image,
which the engine decodes. A layer type that draws raster images draws
them, or the one image of an image source (
Supply::image), as its input. - Tile
Necessity - How much the view needs a tile: a required tile is one the view needs; an optional one is only a fallback or a prefetch the view can do without, or waits in the cache. An origin may only take low-cost actions to get an optional tile’s data, such as looking in a cache.
- Tile
Operation
Traits§
- Data
Origin - Where a source’s tiles get their data: what each tile has of the source’s data, and how it loads.
- Source
Type - A source type’s engine half: how its sources load, what they report and what they supply the renderer.
- Tile
Kind - A kind of tile data, and what a tile’s load delivers of it, its
Item. The kinds are the engine’s:GeometryTiles,RasterTilesandDemTiles.
Type Aliases§
- Described
- What describing a source found: its description,
Nonefor data that describes nothing, or why the source failed to load. - Options
Of - The options of a source of the type
T. - Respond
- Where a job hands its result: called at most once, from any thread, while the job runs or later. Dropping it uncalled drops the result.