{% import "partials/icons.html" as ic %}
{% import "partials/fields.html" as f %}
{# The scenario as places, above the timeline that says when.
The arrangement canvas is about order; it has no way to say *where*. Spawns,
the goal and the lanelets conditions watch are ids scattered across lane
heads and cards -- numbers that mean nothing until someone opens the map in
another window. Here they are one drawing: every place outlined on the map
the scenario actually runs on, each with a pin saying whose it is.
A searched lanelet is drawn as **one bound pattern** rather than as its
matches. A search names a set and the sweeper runs the scenario once per
member, so outlining all of them draws the search instead of the scenario --
and none of those runs looks like that picture. The arrows step through the
runs a sweep would perform, one concrete scenario at a time.
The pins are positioned by `editor.js` from the viewer's own view, because
only the viewer knows where a lanelet ended up on screen; everything they
say is rendered here, so the drawing and the list below cannot disagree. #}
{%- set KIND_GLYPH = {'spawn': 'target', 'goal': 'flag', 'watched': 'eye'} -%}
{%- set refresh = '/draft/' ~ draft.id ~ '/map-view?pattern=' ~ view.pattern -%}
{# One colour per actor, resolved once: `entity_hue` sorts the actor list to
find a position, and a pin and its chip would each pay for that. #}
{%- set HUES = {} -%}
{%- for entity in document.ordered_entities() -%}
{%- set _ = HUES.update({entity.id: f.entity_hue(entity.id, document)|trim}) -%}
{%- endfor -%}
{# This element carries the panel's own refresh: it is re-rendered by the swap
it asks for, so the pattern someone stepped to is baked into the next URL and
survives an edit made anywhere else on the page. #}
Places
Every lanelet this scenario names, on the map it runs on
{% if view.pattern_count %}
{# One of the runs a sweep would perform, chosen by hand. #}
Pattern {{ view.pattern + 1 }} of {{ view.pattern_count }}
{% elif view.searching or view.areas_unmatched %}
{# A search binds one of its matches; an area outlines all of its own.
Both wait on the same thing, the map being parsed. #}
{% endif %}
{# The *resolved* map, not the typed field: a scenario that names a map
repository leaves `map.lanelet2_path` empty and reads its map out of
the cache, so asking the field whether there is a map to draw on made
every git-sourced map draw nothing. #}
{% if view.has_map %}
{# `data-viewer-key` parks the parsed map across a re-render, exactly as
the picker's does: this panel re-renders on every edit, and refetching
a city each time is what that key exists to avoid. No `picks_into`:
this map sets nothing, it draws what the document already says. #}
{{ f.map_frame('scenario-map', draft, view.highlight_ids|join(',')) }}
{# Rendered here, positioned there: the labels are the server's, the
coordinates are the viewer's. #}
{% for point in view.points if point.placed %}
{%- set hue = HUES.get(point.entity_id) or 'var(--accent)' -%}