HoloMap.Source (HoloMap v0.1.0)

Copy Markdown View Source

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. Declare the source before the layers that use it. The reconciler applies definitions in document order, and a layer whose source is not there yet is dropped by MapLibre.

Available sources

Updating a source

How a source is updated depends on what changed:

  • A GeoJSON source whose data changed is updated in place with setData. No layer is disturbed and nothing flickers.
  • An image source whose url or coordinates changed uses updateImage.
  • Any other change is structural. 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 in their declared order.

Frequently-changing data therefore belongs in a GeoJSON source's data prop, which is the one path with no teardown.