mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
c82a8f899f
The kinds were written out in nine places: the enum in @trek/shared, the service list and the colours in the model, the corridor's category keys, the map's road-trip categories, the popup's own table, two lookups in the rail, one in the map markers and one in the corridor panel. Each carried a comment asking the next person to keep the others in step, and it came apart anyway. A rest area was a parking sign in the popup, on the map pill and in the panel, and a coffee cup on the rail disc and the map marker, for the same stop. The parking sign wins: the colour has been documented since it was written as "the blue every parking sign in Europe is printed in". stopKinds.ts holds one row per kind and everything else reads from it. It sits beside the model rather than inside it because an icon is a React component and roadtripModel.ts is deliberately React-free so the arithmetic can be tested on its own; the colours and the service list stay there and are read from here. Two flags rather than one, because they are not the same question: a hotel is something the corridor can find, but sleeping somewhere ends the day rather than interrupting the drive. Seven tests pin the table against the two lists that cannot import it, so the next kind added in one place and forgotten in another fails a test instead of quietly counting as a destination.
56 lines
2.4 KiB
TypeScript
56 lines
2.4 KiB
TypeScript
import { createElement } from 'react'
|
|
import { ParkingSquare } from 'lucide-react'
|
|
import { renderIconMarkup } from '../../utils/iconMarkup'
|
|
import { isServiceStopType, serviceColor } from './roadtripModel'
|
|
import { STOP_KIND_BY_KEY } from './stopKinds'
|
|
|
|
/**
|
|
* Smaller than a place marker on purpose.
|
|
*
|
|
* A petrol station is not a destination — it is something the drive passes through — and
|
|
* a marker the same size as the places the trip is for made a day look like it had twice
|
|
* as many stops as it has. Selected grows a little, the same way a place marker does, so
|
|
* clicking one still confirms itself.
|
|
*/
|
|
export const SERVICE_MARKER_SIZE = 24
|
|
export const SERVICE_MARKER_SIZE_SELECTED = 30
|
|
const BORDER = 2
|
|
|
|
/** The full box a service marker occupies, border included — what an anchor centres on. */
|
|
export function serviceMarkerOuter(selected: boolean): number {
|
|
return (selected ? SERVICE_MARKER_SIZE_SELECTED : SERVICE_MARKER_SIZE) + BORDER * 2
|
|
}
|
|
|
|
/**
|
|
* The marker for a stop that interrupts the drive, or null for an ordinary place.
|
|
*
|
|
* One flat disc in the kind's own colour with a white icon — never the place's photo or
|
|
* its brand logo. A fuel stop used to come back from the place search carrying the
|
|
* operator's logo, so the map showed an Esso roundel where every other road-trip surface
|
|
* showed a pump: unreadable at marker size, different for every brand, and nothing at all
|
|
* for the ones with no logo on file.
|
|
*
|
|
* Built as markup rather than as a component because both renderers need a string: one
|
|
* feeds it to a Leaflet `divIcon`, the other to an element it attaches itself.
|
|
*/
|
|
export function serviceMarkerHtml(stopType: string | null | undefined, selected: boolean): string | null {
|
|
if (!isServiceStopType(stopType)) return null
|
|
const size = selected ? SERVICE_MARKER_SIZE_SELECTED : SERVICE_MARKER_SIZE
|
|
const Icon = STOP_KIND_BY_KEY[stopType ?? '']?.Icon ?? ParkingSquare
|
|
const svg = renderIconMarkup(createElement(Icon, {
|
|
size: Math.round(size * 0.56),
|
|
color: '#fff',
|
|
strokeWidth: 2.4,
|
|
}))
|
|
const ring = selected
|
|
? '0 0 0 3px rgba(17,24,39,0.25), 0 4px 12px rgba(0,0,0,0.3)'
|
|
: '0 2px 6px rgba(0,0,0,0.25)'
|
|
return `<div style="
|
|
width:${size}px;height:${size}px;border-radius:50%;
|
|
background:${serviceColor(stopType)};
|
|
border:${BORDER}px solid #fff;box-shadow:${ring};
|
|
display:flex;align-items:center;justify-content:center;
|
|
box-sizing:content-box;cursor:pointer;
|
|
">${svg}</div>`
|
|
}
|