HoloMap.Layer (HoloMap v0.1.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.FillExtrusion. 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.

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 if that layer is absent
visiblebooleanConvenience for layout.visibility
metadatamapArbitrary data carried on the layer

Ordering

Layers stack in the order MapLibre received them, which is the order the components appear in the template. 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.

Events

on_click, on_dbl_click, on_context_menu, on_mouse_enter, on_mouse_leave, on_mouse_move, on_mouse_down, on_mouse_up, on_touch_start, on_touch_end.

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

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.