Building a site on Xue
How to put Xue’s viewer on a page of your own, over your own data, with
your own layers and controls on top, without forking. The shell is not a
package: you pin this repository and build web/ with a Vite config of
your own. Hong is built this way.
What you can rely on
| Surface | Status |
|---|---|
The data formats (docs/) | Versioned, with the compatibility rules in docs/README.md |
window.xueViewer, window.xuePalettes | The embed contract: frontend.md, “Embedding” |
| The build-time variables below | Kept; one may be added |
| URL parameters | May change with any commit |
DOM ids and classes, CSS, the map’s layer and source ids, module paths under web/src/ | Not an interface |
xuebuild (Python) | Not a library: no stable module API, not on PyPI |
Everything in the last three rows changes without notice, so a site pins a commit and re-checks what it touches when it moves the pin.
Layout and build
Node.js ≥ 22, and a Rust toolchain with wasm-pack: the decoder is built
from the pinned source, there is no prebuilt one.
web/vite.config.mjs, a plain object because it is run by the submodule’s
Vite, which your directory cannot import:
- Only
index.htmlis an input, so the build ships the viewer and none of the shell’s other pages (showcase list, comparison, typhoon, metrics, API console), and none of Xue’s per-language or per-case copies. Without them the shell keeps the language out of the address (a link’s?lang=, else the stored choice, else the browser’s) and a case on the page as?case=<id>(Language paths). localhost:5173exactly: the shell’s Protomaps key serveslocalhostbut not127.0.0.1, and Xue’s public bucket admits that origin (Data).- To type-check the overlay, point
typeRootsandpathsof itstsconfig.jsonatvendor/xue/node_modules(maplibre-gl,@types).
Build-time variables
Read from .env in envDir and inlined by Vite, so a change is a rebuild.
Unset means the default.
| Variable | Effect | Default |
|---|---|---|
VITE_DATA_BASE_URL | The data root: pointers, manifests, stores, showcase.json. Ends with / | /data/, at the site root |
VITE_SOURCES | Comma-separated source ids the model switch and the dataset paths (/<id>) offer | every source |
VITE_POINT_PRODUCTS | Comma-separated point products the shell asks the root for (tc, sounding, airport, synop, fire, aq, alerts), or none | every product |
VITE_PROTOMAPS_KEY | The Protomaps key bound to your origin | the shell’s, which serves only its own origins |
VITE_BASEMAP_TILES | Vector tile template of a basemap mirror, absolute | Protomaps’ API |
VITE_BASEMAP_ASSETS | Root holding Protomaps’ fonts/ and sprites/, absolute | protomaps.github.io/basemaps-assets |
VITE_BASEMAP_HIDE | labels (every name, and the peaks), boundaries, or both | nothing hidden |
VITE_TERRAIN_TILE_URL | Tile template of a Mapterhorn mirror | tiles.mapterhorn.com |
VITE_RIVER_COLOR | field: colour a case’s river reaches from the selected scalar field (frontend) | the catalog’s river.color, or the ratio to usual flow |
Data
The data root is static files. Its origin must:
- answer byte ranges with
206, suffix ranges included (bytes=-N, how the reader asks for a shard index); - answer a missing object with
404or403, never a fallback page: the shell asks for pointers a root may not publish; - when it is another origin than the page, admit the page’s origin by CORS
for
GETwith aRangeheader; - serve the mutable objects (the
latest*.jsonpointers,showcase.json) revalidated. Everything else is addressed with?v=<crc32>and may be cached forever, so nothing is ever overwritten under an unchanged?v=and a mutable object is written last.
Xue’s public bucket admits browser reads from an allow-list of origins and
from http://localhost:5173. A page deployed on another origin cannot
read it and serves a root of its own; code that is not a browser reads it
freely (README, “Using the data”).
Runs of a source Xue knows. Run the pipeline into your root:
setup.md, publishing.md. Name
the sources in VITE_SOURCES and the point products in
VITE_POINT_PRODUCTS.
A dataset of your own. Publish it as showcase cases
(showcase/README.md):
- A catalog row may name a dataset the shell has no entry for: a
modelIdslug ([a-z][a-z0-9]*, not a built-in id), amodellabel no other dataset uses, aproduct. The shell admits it as case-only, absent from the model switch and the dataset paths, and draws its bundles generically; give them colours withwindow.xuePalettes. - The stores must satisfy
zarr-profile.mdandbundle.md(shapes indocs/schemas/). The writer inxuebuildproduces them; install it from the pin (with uv:[tool.uv.sources] xuebuild = { path = "vendor/xue", editable = true }) and expect its modules to move. - A time axis holds offsets up to 65534 in units of at most an hour
(
bundle.md), about seven and a half years. A longer record is several cases, joined by the catalog’spartsor by your module callingopenCaseon the last frame. - A root with cases only has no live pointer for a bare visit to open. Send
a visit without
?case=to one before the shell’s module runs (below).
Your module
It runs beside the shell’s and reaches it through window.xueViewer
(the contract). Declare the part of the interface
you use rather than importing the shell’s module:
- Draw on
xue.mapwith layer and source ids under a prefix of your own; add, never edit or remove, the shell’s. - Read your own files from the same data root
(
import.meta.env.VITE_DATA_BASE_URL). - What must exist before the shell’s module runs goes into an inline
script, a second tag from the plugin with
injectTo: "head-prepend":window.xuePalettes, the redirect of a bare visit to a case, and a copy of any query parameter of your own, since the shell rewrites the query string to its view state. - The shell’s elements are yours to hide with CSS but not to remove: its
script reaches them. Ink for anything over the map follows
body[data-ground].
The page’s identity
The shell names its own site in three places, and a build on another host corrects each:
index.html’s static head (title, description, canonical andhreflanglinks, social card, JSON-LD,noscript): rewrite the HTML intransformIndexHtml, which may return{ html, tags }.public/(llms.txt,robots.txt,_headers,.well-known/,og-image.jpg, the icons), copied into the build as is: replace or delete them in the plugin’scloseBundle.- The head the shell rewrites as the view changes (
pagemeta.ts, againstsite.ts): observedocument.headfrom your module and put your origin and name back.
Moving the pin
- Rebuild the decoder (
make wasm) with every move: it comes from the same commit as the shell. - Shell before data. A shell refuses a manifest or metadata version above
the ones it implements, so move the pin and deploy before publishing
data written by a newer
xuebuild. Data already published stays readable: nothing is rebuilt for a newer shell. - Re-check the selectors you hide or mount into, and type-check your module.
Licences
The code is MIT or Apache-2.0. Published data keeps its sources’ terms (README). The basemap and the relief are third-party services with their own terms and attribution.