mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 05:56:53 +00:00
eae8480728
* feat(studio): widen the document, and stop a save from losing it The schema gains what the elements coming after it need: an icon element, a badge that can be restyled rather than only placed, a date and a pair of coordinates on a text binding, and the map's route, pin and road settings. Widening it turned up two ways a book could fail to come back. The mood badge writes its code into the document, and the schema said that code was exactly two characters, from a first draft where it was a country. The real codes are words, so every save was rejected and the read that followed parsed to an empty document: seventeen spreads in, nothing out. Widened to what the badge actually writes, and normalizeBookDocument now drops the elements it cannot read rather than the whole book, so one bad element costs a picture frame instead of a year of work. The other was the body limit. The parser allowed 100kb for everything, and a book with a routed map measures past that, so the save came back 413 and the editor sat on "not saved" with no way forward. Book writes get their own parser at 8mb; everything else keeps the limit it had. * feat(studio): a date, a pair of coordinates and an icon library Three things that had to be drawn by hand before. A journal entry knows when it happened and where, and neither could be put on a page: you read the date off the entry and typed it into a text box, where it then stayed while the entry moved. Both are chips now, next to the title and the story, and both follow their entry the way the others do. The formatting lives in one place so the chip, the template and the resolver cannot drift by a character — coordinates in degrees or decimals, the date in the reader's language. The icons are the whole Lucide set, searchable, placed as a real element with its own colour and stroke rather than as a character in a font. The stroke is deliberately not called strokeWidth: three separate places rescale a field of that name by page width, and an icon whose line thins as the book grows is not what anyone asked for. And the badges finally have their settings. A mood or weather badge could be placed and then only moved: the icon's colour was fixed, the icon could not be turned off, and there was no way to keep the icon and drop the words. All three are switches now, with the colour following the badge unless you say otherwise. * fix(studio): let a placed entry field follow its journal entry again The inspector says a bound field follows the journal entry and that editing it here breaks the link. The first half was not true: nothing ever re-read the entry, so renaming a title in Journey left the old words on the page for good, and the same went for every other bound field. The resolver runs where the journey is loaded and re-reads the fields that still point at an entry. What it will not do is as important as what it does. A field somebody has typed over stays typed over, an entry that is gone leaves its element alone rather than blanking it, and an entry that answers with nothing never wipes what is already on the page. Formatted fields — the date, the coordinates — are only re-read when the format itself changed, which is what keeps this from quietly rewriting books that already exist: an entry whose date was placed as a heading and then set in capitals keeps its capitals. Checked against the real database before it shipped, where the first version overwrote three of them. * feat(studio): start a new book empty, with six layouts to choose from A new journey opened onto a book that had already been laid out, which is the wrong first move: it decides the shape of somebody's book before they have seen it, and undoing it means deleting pages one at a time. A new book starts empty now, and the auto layout runs when it is asked to. The layouts themselves went from two to six, so choosing one is a real choice: what was there covered a photo-heavy spread and a text-heavy one and nothing in between. * fix(studio): hyphenate the export the way the editor does, and set the bleed Two things the press sees and the editor did not. A paragraph broke in different places in the PDF than on screen. The print document is written from scratch and never carried a language, so the browser hyphenated the editor's German and the export's nothing-in- particular. It takes the page's own language now. The wait for the sheet to be ready also covers the images inside SVG, with a ceiling, so a map that is slow to draw does not print half-finished. And the bleed and the safe margin are typeable. Both were baked into every page preset at what a photo-book vendor usually asks for, 3mm and 5mm, with no control anywhere. That is fine until a printer asks for 5 and 10, at which point the book cannot be made here at all: the export carries the wrong bleed and the crop marks sit in the wrong place, which nobody finds until the guillotine has run. * feat(studio): rebuild the inspector The panel on the right had grown by accretion: every element type had added its own controls in whatever shape suited it that day, so the same idea — a colour, a size, a toggle — looked different depending on what you had selected, and long panels were a wall of unlabelled fields. It is one set of controls now, used by every element: foldable sections, a line that holds a label and its control, radio choices, checkboxes, the app's own toggle, and a number field that holds a draft so typing "500" is not read as "5", clamped and written back under the cursor. Duplicated controls were merged rather than deleted; nothing an element could do before it cannot do now. The head carries the element's identity and its actions, so what you have selected is readable without counting fields, and the sections have room to breathe: what was there was correct and unreadable. * feat(studio): a route map worth printing The map in a book was a straight grey line between grey dots on a tile that was chosen for a screen. At print size those tiles are read at roughly four times the resolution they were fetched for, which is why it looked soft next to everything around it. The imagery comes from sources that hold up on paper: NASA's shaded relief and EOX's cloudless Sentinel-2, both licensed for it, picked at a zoom that matches the printer rather than the screen. Tiles are fetched at twice the density where the source offers it, and the seam between them scales with the tile instead of sitting at a fixed fraction of a millimetre, which under editor zoom fell below one device pixel and showed as white threads. The route is drawn rather than plotted. A leg that was never recorded bows, by an amount that grows with its length and turns away from the pole, and it dashes, because an inferred line should not claim to be a track — a recorded track never bows. Both strokes are laid down in two passes, casing then core, so the line stays legible over dark sea and bright desert alike. Legs can follow roads instead, routed leg by leg with the geometry thinned before it is stored, which is the setting a road trip wants and the one a flight cannot have. Stops carry their own first photograph, cut to a circle by a stencil that exists — the first one was written into a defs block that only appears on a map clipped to a coastline, so on an ordinary map it clipped nothing and the photographs sat square on the page. A stop with no photograph of its own is numbered rather than handed one from elsewhere in the journey: a marker at one place showing a picture taken at another is a caption that lies. Whatever the frame, the whole route is inside it. The window takes the frame's aspect, so the fit and the imagery agree instead of one containing what the other covers, and a map dragged narrow no longer cuts off its end. Each linked trip can carry its own map, and a map notices a photograph added to a stop afterwards rather than having to be placed again. * i18n(journey): the new Studio strings, in all 23 locales * test(journey): pin the coverage the map work brought with it The journey domain measures higher than its floor after this round, so the floor follows it up. Only journey moved; the generator's suggestion would have taken memories' functions down a point, and a ratchet that can fall is not a ratchet. * test(studio): cover the thinning that keeps a road route saveable The one path in roadRoute nothing exercised, and the one that matters most: a router answers a long drive with thousands of points at a precision no press can resolve, and all of it goes into the document. Keeping a leg whole is what pushed a real book past the body limit. Both ends have to survive so the line still meets its stops, and the spacing has to stay even, because cutting a run out of the middle would straighten exactly the bends somebody wanted to see.
182 lines
8.0 KiB
TypeScript
182 lines
8.0 KiB
TypeScript
import type { BookFrame } from '@trek/shared'
|
|
import { attributionFor } from './mapTiles'
|
|
|
|
/**
|
|
* Which map sources this instance can actually offer.
|
|
*
|
|
* TREK already knows: an admin has configured a tile template, and possibly a
|
|
* Mapbox token and style, for the planner and Atlas. Studio reads the same
|
|
* settings rather than asking again — a second place to paste a token is a
|
|
* second place for it to be wrong.
|
|
*
|
|
* A source with nothing behind it is not offered. Showing "Mapbox" to someone
|
|
* with no token produces an element that renders grey, and no message anywhere
|
|
* explains why.
|
|
*/
|
|
|
|
export interface MapSourceOption {
|
|
/**
|
|
* What this option is called in the panel.
|
|
*
|
|
* Not the same thing as `source`: relief and the instance's own tiles are
|
|
* both raster grids and the renderer draws them identically, so they share a
|
|
* `source` and differ only in where the pictures come from. Widening the
|
|
* contract's enum to tell them apart would mean a document an older build
|
|
* cannot read, for a distinction only the panel cares about.
|
|
*/
|
|
id: 'vector' | 'tiles' | 'static' | 'relief' | 'satellite'
|
|
/** What goes into the document. */
|
|
source: 'vector' | 'tiles' | 'static'
|
|
/** i18n key for the name. */
|
|
labelKey: string
|
|
/** The tile template or static URL to freeze into the element. */
|
|
url: string
|
|
attribution: string
|
|
}
|
|
|
|
/** Which option a placed element came from, matched back by what it stored. */
|
|
export function sourceIdOf(el: { source: string; tileUrl: string }, options: MapSourceOption[]): string {
|
|
const exact = options.find(o => o.source === el.source && o.url === el.tileUrl)
|
|
return exact?.id ?? el.source
|
|
}
|
|
|
|
/**
|
|
* NASA's shaded relief, and why it is the one worth printing.
|
|
*
|
|
* ── What it looks like ───────────────────────────────────────────────────
|
|
*
|
|
* Land in its own colours with the terrain shaded into it, sea rendered dark
|
|
* with the depth showing through, and no roads, no borders and no labels. It
|
|
* is the look printed travel books have used for decades, and it is the one
|
|
* the street map underneath a planner can never be: a street map is a working
|
|
* document, and enlarged onto a page it reads as a screenshot.
|
|
*
|
|
* ── Why this source rather than a better-known one ───────────────────────
|
|
*
|
|
* Because a book gets printed, and possibly sold. Mapbox's own documentation
|
|
* says to contact them before printing an exported map; Esri's imagery is
|
|
* licensed for use with ArcGIS and not for commercial work; the OSM tile
|
|
* server's policy forbids bulk fetching, which is what covering a page at
|
|
* print resolution is. This is US government imagery: the service's own
|
|
* capabilities document answers both questions in two lines, `<ows:Fees>none`
|
|
* and `<ows:AccessConstraints>none`, and no account or token exists to get
|
|
* wrong.
|
|
*
|
|
* ── Its one limit, stated rather than discovered ─────────────────────────
|
|
*
|
|
* Level 8, about 600 metres to the pixel. A journey across a country or a
|
|
* continent is exactly what it is for; a weekend inside one city is not, and
|
|
* for that the instance's own tiles are still the better answer.
|
|
*
|
|
* Note the path is `{z}/{y}/{x}` — WMTS names its axes row then column, the
|
|
* reverse of the slippy convention. The substitution is by name, so the order
|
|
* in the template is all that matters.
|
|
*/
|
|
const RELIEF_TILES = 'https://gibs.earthdata.nasa.gov/wmts/epsg3857/best'
|
|
+ '/BlueMarble_ShadedRelief_Bathymetry/default/GoogleMapsCompatible_Level8'
|
|
+ '/{z}/{y}/{x}.jpeg'
|
|
|
|
/**
|
|
* Real satellite imagery, and the answer to what relief cannot do.
|
|
*
|
|
* Relief stops at about 600 metres to the pixel, which is a continent's worth
|
|
* of detail: it draws Europe beautifully and a fortnight in the Netherlands as
|
|
* a green smudge. This is the same picture at ten metres — cloud-free Sentinel-2,
|
|
* composited by EOX from a year of passes, so there is no weather in the way and
|
|
* no seams between scenes.
|
|
*
|
|
* ── Why the 2016 layer specifically ──────────────────────────────────────
|
|
*
|
|
* EOX publish a layer per year, and only this one is usable in a book somebody
|
|
* might sell: the service's own capabilities document releases it under CC BY
|
|
* 4.0, while 2018 onwards are CC BY-NC-SA, which rules out a printed product.
|
|
* The imagery being a decade old costs nothing here — a coastline, a mountain
|
|
* range and a desert do not move, and the map is a backdrop for a route rather
|
|
* than a survey.
|
|
*
|
|
* Attribution is not optional under that licence, which is why it travels into
|
|
* the document with the source.
|
|
*/
|
|
const SATELLITE_TILES = 'https://tiles.maps.eox.at/wmts/1.0.0'
|
|
+ '/s2cloudless_3857/default/g/{z}/{y}/{x}.jpg'
|
|
|
|
/**
|
|
* What a book may be made of.
|
|
*
|
|
* ── Why the planner's own tiles are not on this list ─────────────────────
|
|
*
|
|
* They are a street map, and a street map enlarged onto a page reads as a
|
|
* screenshot of a working document rather than as an illustration — which is
|
|
* the whole difference between the reference books and what this drew before.
|
|
* Worse, covering a page at print resolution means fetching a few hundred tiles
|
|
* at once, and the OSM tile server's usage policy names exactly that as
|
|
* something not to do. Mapbox is off the list for a different reason: its own
|
|
* documentation says to contact them before printing an exported map, so it
|
|
* cannot be offered as a thing to put in a book somebody might sell.
|
|
*
|
|
* What is left is the three that are honestly printable: outlines drawn from
|
|
* boundaries this server already ships, NASA's relief, and Sentinel-2.
|
|
*
|
|
* ── But a book that already uses one keeps working ───────────────────────
|
|
*
|
|
* Removing an option must not remove a page. An element placed with the
|
|
* instance's tiles or with Mapbox still renders exactly as it did, and its own
|
|
* source is added back to the list below so the panel can show it as the chosen
|
|
* one — otherwise the map would draw correctly while the panel claimed it was
|
|
* something else, and one stray click would silently convert it.
|
|
*/
|
|
export function useMapSources(
|
|
frame: BookFrame,
|
|
points: { lat: number; lng: number }[],
|
|
/** What the element being inspected already uses, so it stays reachable. */
|
|
current?: { source: string; tileUrl: string },
|
|
): MapSourceOption[] {
|
|
// Through the same normaliser the planner's map uses: a template saved
|
|
// before OSM dropped its shards still names a host that no longer exists.
|
|
const out: MapSourceOption[] = [
|
|
{ id: 'vector', source: 'vector', labelKey: 'journey.studio.mapSourceVector', url: '', attribution: '' },
|
|
{
|
|
id: 'relief',
|
|
source: 'tiles',
|
|
labelKey: 'journey.studio.mapSourceRelief',
|
|
url: RELIEF_TILES,
|
|
attribution: attributionFor(RELIEF_TILES),
|
|
},
|
|
{
|
|
id: 'satellite',
|
|
source: 'tiles',
|
|
labelKey: 'journey.studio.mapSourceSatellite',
|
|
url: SATELLITE_TILES,
|
|
attribution: attributionFor(SATELLITE_TILES),
|
|
},
|
|
]
|
|
|
|
/*
|
|
* The one the element is already on, when it is not one of the three above.
|
|
* Listed last, so the recommended sources read as the answer and this reads
|
|
* as what happens to be in place.
|
|
*/
|
|
if (current && !out.some(o => o.source === current.source && o.url === current.tileUrl)) {
|
|
if (current.source === 'tiles' && current.tileUrl) {
|
|
out.push({
|
|
id: 'tiles',
|
|
source: 'tiles',
|
|
labelKey: 'journey.studio.mapSourceTiles',
|
|
url: current.tileUrl,
|
|
attribution: attributionFor(current.tileUrl),
|
|
})
|
|
}
|
|
if (current.source === 'static' && current.tileUrl) {
|
|
out.push({
|
|
id: 'static',
|
|
source: 'static',
|
|
labelKey: 'journey.studio.mapSourceStatic',
|
|
url: current.tileUrl,
|
|
attribution: attributionFor(current.tileUrl),
|
|
})
|
|
}
|
|
}
|
|
|
|
return out
|
|
}
|