Namespace for the data sources a map can draw from.
A source says where the data comes from; a layer says how it looks. They are separate components because the relationship is one-to-many. One source routinely feeds a fill, an outline and a label layer, and re-declaring the data three times would mean fetching it three times.
<HoloMap.Source.GeoJSON id="parcels" data={@parcels} />
<HoloMap.Layer.Fill id="parcels-fill" source="parcels" paint={%{fill_color: "#3b82f6"}} />
<HoloMap.Layer.Line id="parcels-line" source="parcels" paint={%{line_color: "#1e40af"}} />Layers reference a source by its id, and may be declared before or after
it. A layer whose source is not on the map yet waits for it, and is added in
its declared place as soon as the source is.
Available sources
HoloMap.Source.GeoJSON: inline features or a URL, with clusteringHoloMap.Source.Vector: vector tilesHoloMap.Source.Raster: raster tilesHoloMap.Source.RasterDEM: elevation tiles, for terrain and hillshadeHoloMap.Source.Image: a single image pinned to four corners
Updating a source
How a source is updated depends on what changed. MapLibre changes some keys on the source itself, and no layer on it is disturbed:
- A GeoJSON source's
datagoes throughsetData, which swaps the features and leaves the rest as it was. - A GeoJSON source's
cluster,cluster_radiusandcluster_max_zoomgo throughsetClusterOptions, which builds the clusters again, beforesetDatawhendatachanged too. - A vector, raster or raster-dem source's
tilesandurlgo throughsetTilesandsetUrl, and MapLibre requests the tiles again, from the new URL or the TileJSON it names. The tiles on screen stay until the new ones arrive, and terrain drawn from the source stays on it. - An image source's
urlandcoordinatesgo throughupdateImage.
Any other change is structural, and so is taking tiles, url,
cluster_radius or cluster_max_zoom away, which MapLibre's setters cannot
do. MapLibre refuses to remove a source that still has layers attached, so
the reconciler detaches the layers it owns, swaps the source, and puts them
back where they were in the stack, with the terrain.
Frequently-changing data therefore belongs in a GeoJSON source's data
prop, and a changing tile set in tiles or url.