HoloMap.Layer (HoloMap v0.4.0)

Copy Markdown View Source

A MapLibre layer of any type.

<HoloMap.Layer
  id="parcels-fill"
  type="fill"
  source="parcels"
  paint={%{fill_color: "#3b82f6", fill_opacity: 0.4}}
/>

Prefer the type-specific components: HoloMap.Layer.Fill, HoloMap.Layer.Line, HoloMap.Layer.Circle, HoloMap.Layer.Symbol, HoloMap.Layer.Raster, HoloMap.Layer.Heatmap, HoloMap.Layer.Hillshade, HoloMap.Layer.ColorRelief, HoloMap.Layer.FillExtrusion and HoloMap.Layer.Background. They document the paint properties that apply to them and reject a mismatched type at compile time. Reach for this one when the type is computed at runtime. A layer drawn by WebGL code of your own, such as a three.js scene, is a HoloMap.Layer.Custom.

Props

PropTypeNotes
idstringRequired. The layer id, and its identity across re-renders
typestringRequired here, fixed in the type-specific components
sourcestringThe id of a source component
source_layerstringRequired for vector sources
paintmapPaint properties. Atom keys are dasherized: fill_color becomes "fill-color"
layoutmapLayout properties, dasherized the same way
filterlistA MapLibre filter expression
min_zoom / max_zoomnumberZoom range
before_idstringInsert beneath this layer. Ignored while that layer is absent
visiblebooleanConvenience for layout.visibility
metadatamapArbitrary data carried on the layer
expand_cluster_on_clickbooleanA click on a cluster zooms in to where it breaks apart; see below

Ordering

Layers stack in the order the components appear in the template. That holds for a layer rendered conditionally, one re-added because its type, source or source_layer changed, and the layers of a rebuilt source: each goes back to its place rather than on top. before_id overrides that when a layer has to sit beneath one it is not written next to, such as a highlight layer under a label layer that belongs to the base style, for example. It can name a layer declared further down, or one rendered later, and takes effect once that layer is on the map. Changing before_id moves the layer.

Events

on_click, on_dbl_click, on_context_menu, on_mouse_enter, on_mouse_leave, on_mouse_over, on_mouse_out, on_mouse_move, on_mouse_down, on_mouse_up, on_touch_start, on_touch_end, on_touch_cancel. In MapLibre GL JS 6, on_mouse_over fires as on_mouse_enter does, and on_mouse_out as on_mouse_leave.

Handlers receive layer, lng_lat, point and features, which holds the features under the pointer, each with id, source, source_layer, properties and geometry:

def action(:parcel_clicked, params, component) do
  case params.features do
    [%{properties: %{parcel_id: id}} | _rest] -> put_state(component, :selected, id)
    [] -> component
  end
end

Expanding clusters

On a layer that draws the clusters of a clustered HoloMap.Source.GeoJSON, expand_cluster_on_click makes a click on a cluster ease the camera to the cluster's point, at the zoom where it breaks apart, as MapLibre's getClusterExpansionZoom gives it. The browser does it all, with no action and no round trip:

<HoloMap.Layer.Circle id="clusters" source="stops"
                      filter={["has", "point_count"]}
                      expand_cluster_on_click />
  • A click whose top feature on the layer is not a cluster, one with no cluster_id property, does nothing more, so the layer may draw single points too.
  • on_click still hears the click, with the features as they were clicked. It is dispatched first; the camera starts to move once the source's worker has worked out the zoom, a moment later.
  • The move is MapLibre's easeTo with its default duration and easing, and it is not configurable here. It is reported to the map's on_move_end and the other move events, as a user's move is. For a move of your own, such as a shorter one, leave this off and call HoloMap.API.expand_cluster/4 from on_click, which takes the options of HoloMap.API.ease_to/2.
  • A source that is not clustered has no expansion zoom: the camera stays put, with a console warning.

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

__is_hologram_component__()

@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

__props__()

@spec __props__() :: [{atom(), atom(), keyword()}]

Returns the list of property definitions for the compiled component.