Map block: Google and Apple Maps buttons, a zoomable picture, links land at the map's top

Migration 091 adds google_maps_url and apple_maps_url to
venue_locations, shown as buttons at the right of each location's
row. The picture zooms (1x to 4x) and scrolls in its box. A link to a
location now scrolls to the top of the map block, not the mark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-11-11 03:04:14 -06:00
parent 8a79206998
commit 6a0271efd9
6 changed files with 128 additions and 12 deletions

View file

@ -9,9 +9,14 @@
they stay on their places at any width. A location is lit up
(in the accent, the rest dimmed) while its row or mark is hovered
or focused, and when the address points at it: #map-<venue>-<key>,
the link a schedule entry's place makes (mapAnchor). That id is
the mark's own, so Layout's jump to the anchor scrolls it into
view and focuses it.
the link a schedule entry's place makes (mapAnchor). Those ids
sit at the block's top, so Layout's jump to the anchor brings the
whole map into view, not the mark at the top of the screen.
The picture zooms (the buttons over it), scrolling inside its box
when it's bigger than it; the marks are in percent, so they keep
their places. A location's Google and Apple Maps links (091) are
buttons at the right of its row.
MapPicture is the picture and its marks alone; the event's
presentation (EventPresent.tsx) draws it too, with no links.
@ -23,7 +28,8 @@
when there's a map on the page to go to.
═══════════════════════════════════════════════════════════════ */
import { createContext, useState, type CSSProperties } from 'react'
import { createContext, useState, type CSSProperties, type ReactNode } from 'react'
import { AppleLogo, ArrowsIn, GoogleLogo, MagnifyingGlassMinus, MagnifyingGlassPlus } from '@phosphor-icons/react'
import { Link, useLocation, type To } from 'react-router-dom'
import { mediaUrl } from '../lib/media.ts'
@ -35,6 +41,9 @@ export const PageMaps = createContext<Set<string>>(new Set())
export const mapAnchor = (venueId: string, key: string) => `map-${venueId}-${key}`
/* The picture's zoom steps, 1 the column's width. */
const ZOOMS = [1, 1.5, 2, 3, 4]
const isBox = (location: VenueLocation) => location.w != null && location.h != null
export const isMarked = (location: VenueLocation) => location.x != null && location.y != null
@ -143,7 +152,6 @@ export function MapPicture({
return link ? (
<Link
key={location.key}
id={mapAnchor(venue.id, location.key)}
to={link(location.key)}
aria-label={location.name}
{...light?.(location.key)}
@ -165,6 +173,7 @@ export function MapPicture({
export default function MapBlock({ venue, accent }: { venue: Venue; accent: string }) {
const { hash, search } = useLocation()
const [hovered, setHovered] = useState<string | null>(null)
const [zoom, setZoom] = useState(0)
const fromHash = venue.locations.find((location) => hash === `#${mapAnchor(venue.id, location.key)}`)?.key ?? null
const active = hovered ?? fromHash
const picture = !useReadingMode() && Boolean(venue.map_image)
@ -178,8 +187,34 @@ export default function MapBlock({ venue, accent }: { venue: Venue; accent: stri
})
return (
<figure className="grid gap-6 md:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]">
{picture && <MapPicture venue={venue} accent={accent} active={active} link={to} light={light} className="self-start" />}
<figure className="relative grid gap-6 md:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]">
{/* Where a link to a location lands: the map's top. */}
{venue.locations.map((location) => (
<span key={location.key} id={mapAnchor(venue.id, location.key)} className="absolute top-0 left-0" />
))}
{picture && (
<div className="relative self-start">
<div className="max-h-[80vh] overflow-auto border border-brand/15">
<div style={{ width: `${ZOOMS[zoom] * 100}%` }}>
<MapPicture venue={venue} accent={accent} active={active} link={to} light={light} />
</div>
</div>
<div className="absolute top-2 right-2 flex gap-1">
<ZoomButton label="Zoom in" disabled={zoom === ZOOMS.length - 1} onClick={() => setZoom(zoom + 1)}>
<MagnifyingGlassPlus weight="bold" className="h-5 w-5" />
</ZoomButton>
<ZoomButton label="Zoom out" disabled={zoom === 0} onClick={() => setZoom(zoom - 1)}>
<MagnifyingGlassMinus weight="bold" className="h-5 w-5" />
</ZoomButton>
{zoom > 0 && (
<ZoomButton label="Fit the map" onClick={() => setZoom(0)}>
<ArrowsIn weight="bold" className="h-5 w-5" />
</ZoomButton>
)}
</div>
</div>
)}
<figcaption className={picture ? '' : 'md:col-span-2'}>
<p className="font-display font-bold text-ink">{venue.name}</p>
@ -201,14 +236,15 @@ export default function MapBlock({ venue, accent }: { venue: Venue; accent: stri
const rowClass = 'flex items-start gap-3 px-2 py-1.5 text-body'
const rowStyle = on ? { background: withAlpha(accent, 12) } : undefined
return (
<li key={location.key}>
<li key={location.key} className="flex items-start gap-2">
{isMarked(location) ? (
<Link to={to(location.key)} {...light(location.key)} className={rowClass} style={rowStyle}>
<Link to={to(location.key)} {...light(location.key)} className={`${rowClass} flex-1`} style={rowStyle}>
{row}
</Link>
) : (
<div className={rowClass}>{row}</div>
<div className={`${rowClass} flex-1`}>{row}</div>
)}
<MapLinks location={location} accent={accent} />
</li>
)
})}
@ -217,3 +253,57 @@ export default function MapBlock({ venue, accent }: { venue: Venue; accent: stri
</figure>
)
}
/* A zoom button over the map picture. */
function ZoomButton({
label,
disabled,
onClick,
children,
}: {
label: string
disabled?: boolean
onClick: () => void
children: ReactNode
}) {
return (
<button
type="button"
aria-label={label}
title={label}
disabled={disabled}
onClick={onClick}
className="btn flex h-9 w-9 items-center justify-center bg-raised text-ink shadow transition-colors hover:text-link disabled:opacity-40"
>
{children}
</button>
)
}
/* A location's Google and Apple Maps links (091), as buttons that
open them in a new tab. */
function MapLinks({ location, accent }: { location: VenueLocation; accent: string }) {
const links = [
{ href: location.google_maps_url, label: 'Google Maps', Icon: GoogleLogo },
{ href: location.apple_maps_url, label: 'Apple Maps', Icon: AppleLogo },
].filter((link) => link.href)
if (links.length === 0) return null
return (
<span className="flex shrink-0 gap-1 py-1.5">
{links.map(({ href, label, Icon }) => (
<a
key={label}
href={href!}
target="_blank"
rel="noreferrer"
aria-label={`${location.name} in ${label} (opens in a new tab)`}
title={label}
className="btn flex h-8 w-8 items-center justify-center border transition-colors hover:bg-tint"
style={{ borderColor: withAlpha(accent, 33), color: accentText(accent) }}
>
<Icon weight="bold" className="h-4 w-4" aria-hidden="true" />
</a>
))}
</span>
)
}

View file

@ -66,6 +66,16 @@ export const venues = {
full: true,
help: "Click the map for a pin, or drag out a box for an area. Default: listed, not marked.",
},
{
path: "google_maps_url",
label: "Google Maps link",
help: "eg. https://maps.app.goo.gl/... Shown as a button beside it. Default: none",
},
{
path: "apple_maps_url",
label: "Apple Maps link",
help: "eg. https://maps.apple.com/?... Shown as a button beside it. Default: none",
},
],
},
],

View file

@ -82,6 +82,9 @@ export type VenueLocation = {
y?: number | null
w?: number | null
h?: number | null
/** The place in Google and Apple Maps (091). */
google_maps_url?: string | null
apple_maps_url?: string | null
}
/** An event an item names (088): an events block's card, or the