image
StableAn image of your own on the map for symbol layers to draw: an icon from a URL, one icon in any colour with sdf, or a pulsing dot.
color
Vehicles in alert
Sample vehicles, not real ones: teal is moving, orange idle and grey stopped. Visitors who ask for less motion see the pulse still.
- @color
- #c92a2a
- @period
- 1500
- @alerts
- TRK-3
<div id="image-example">
<.example_frame error={@map_error} error_id="example-image-map-error">
<.map
id="example-image-map"
center={[-0.3575, 39.4635]}
zoom={12.6}
style={basemap(@theme)}
events={["map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- Each <.image> puts an image on the map under its id, for layers to
name in icon-image. The SVG takes a size; sdf makes it one shape
that a layer paints with icon-color. --%>
<.image
id="example-image-vehicle"
map_id="example-image-map"
url="/images/vehicle.svg"
width={24}
height={24}
sdf
pixel_ratio={2}
/>
<.image
id="example-image-alert"
map_id="example-image-map"
animation={:pulse}
color={@color}
period={@period}
size={64}
pixel_ratio={2}
/>
<.geojson_layer
id="example-image-vehicles"
map_id="example-image-map"
type="symbol"
data={fleet(@alerts)}
layout={
%{
"icon-image" => "example-image-vehicle",
"icon-rotate" => ["get", "heading"],
"icon-rotation-alignment" => "map",
"icon-allow-overlap" => true
}
}
paint={
%{"icon-color" => icon_color(), "icon-halo-color" => halo(@theme), "icon-halo-width" => 1.5}
}
/>
<%!-- The pulse under the vehicles in alert: before_id draws it below them. --%>
<.geojson_layer
id="example-image-alerts"
map_id="example-image-map"
type="symbol"
data={fleet(@alerts)}
filter={["get", "alert"]}
before_id="example-image-vehicles"
layout={%{"icon-image" => "example-image-alert", "icon-allow-overlap" => true}}
/>
<div class="space-y-4 border-t border-line px-4 py-4">
<div class="grid gap-x-8 gap-y-4 lg:grid-cols-[auto_1fr]">
<.example_group id="example-image-colors" label="color" code>
<.example_button
:for={{name, hex} <- colors()}
id={"example-image-color-#{name}"}
code
pressed={@color == hex}
phx-click="pulse_color"
phx-value-color={hex}
>
<.example_swatch color={hex} />{hex}
</.example_button>
</.example_group>
<.example_group id="example-image-alert-toggles" label={gettext("Vehicles in alert")}>
<.example_button
:for={vehicle <- vehicles()}
id={"example-image-alert-#{vehicle.id}"}
code
pressed={vehicle.id in @alerts}
phx-click="alert"
phx-value-id={vehicle.id}
>
{vehicle.id}
</.example_button>
</.example_group>
</div>
<.form
for={@options}
id="example-image-options"
phx-change="options"
class="w-full sm:max-w-xs"
>
<.example_range field={@options[:period]} label="period" min="500" max="3000" step="250" />
</.form>
<.example_note id="example-image-data">
{gettext(
"Sample vehicles, not real ones: teal is moving, orange idle and grey stopped. Visitors who ask for less motion see the pulse still."
)}
</.example_note>
</div>
<.example_readout values={[color: @color, period: @period, alerts: shown(@alerts)]} />
</div>
Generated from the component's definition in the library, so it always matches the version this demo runs.
| Attribute | Type | Default | Description |
|---|---|---|---|
| id required | string | — |
The image's name on the map, which layers give in icon-image; also the id of the component's element. Read at mount.
|
| map_id required | string | — | ID of the map to put the image on. Read at mount. |
| url | string |
nil
|
The URL of the image: PNG, JPEG, WebP, or SVG with width and height. A url or an animation is required, and not both. positive integers, both or neither. Needed for an SVG.
|
| width | integer |
nil
|
Not documented by the library. |
| height | integer |
nil
|
Not documented by the library. |
| sdf | boolean |
false
|
true for an image a layer paints with icon-color; false by default.
|
| animation | atom |
nil
|
:pulse
|
| color | string |
nil
|
The pulse's colour, in hexadecimal; "#3FB1CE" by default.
|
| size | integer |
nil
|
The pulse's side, in CSS pixels: an integer from 1 to 512; 64 by default. |
| period | any |
nil
|
milliseconds, a number over 0 |
| pixel_ratio | any |
1
|
a number over 0 |
| events | any |
[]
|
a list of event names, or :all
|