mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
4c0583845a
Selecting a place no longer spiderfies a city-sized cluster: the reveal only fans open bubbles of up to 12 stops, or stacks whose stops all share one coordinate, so a zoomed-out trip with hundreds of places stays usable (#2990). The selected pin now carries a white border inside a pulsing blue ring on both renderers (static under reduced motion), and the map measures the place card instead of assuming a fixed 320px, so the selection pans the pin above even a tall card on portrait tablets and eases it back out when the card grows over it later (#2991). Closes #2990 Closes #2991
56 lines
2.6 KiB
TypeScript
56 lines
2.6 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'
|
|
import { SELECTED_MARKER } from '../Map/markerLook'
|
|
|
|
/**
|
|
* 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,
|
|
}))
|
|
// Selected, it carries the same ring as a selected place pin, so the two read alike.
|
|
const ring = selected ? SELECTED_MARKER.ring : '0 2px 6px rgba(0,0,0,0.25)'
|
|
return `<div class="${selected ? SELECTED_MARKER.className : ''}" 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>`
|
|
}
|