RailRouter SG is a progressive web app that lets you explore MRT and LRT rail routes in Singapore.
It was built to scratch my curiosity itch for comparing the real route lines VS the lines shown on Google Maps, which I personally find too straight and skews the perception of how trains actually travel in the real world.
Available features:
- Real rail route lines, for all train routes.
- Show station names in Chinese and Tamil, besides English.
- Show station building structures, both underground and aboveground.
- Show location of exits (a.k.a. entrances) for (almost) all stations.
- Scheduled trains animating along the tracks, from the published GTFS timetable.
Show train arrival times for some stations.- Possibly, works offline.
This is the first version, using Google Maps.
npm i- install dependenciesnpm start- starts the server on http://localhost:1987npm start-https- same, over HTTPSnpm run build- builds the production assets for deploymentnpm test- runs the unit tests
The port is pinned to 1987, the year Singapore's MRT opened, rather than Parcel's default.
The train button on the map animates every train on the published timetable;
tap it again to tilt the map between the 2D and 3D trains, and close the panel
to hide them. /#trains opens the layer directly for sharing or bookmarking.
npm run gtfsdownloads LTA DataMall's GTFS Schedule (Train) feed and rebuildssrc/gtfs-trains.json. It needs an account key inLTA_ACCOUNT_KEYor inscripts/config.jsonas{ "accountKey": "..." }.GTFS_OFFLINE=1rebuilds from the ZIP already cached indata/instead of downloading..github/workflows/update-gtfs.ymlreruns it twice a month and commits the regenerated JSON, so only the built timetable lives in git. The 3.3 MB source ZIP stays in the git-ignoreddata/. The build is deterministic — no timestamps — so an unchanged feed produces a byte-identical file and the workflow skips the commit.
src/gtfs-trains.json is a packed timetable, not raw GTFS: zig-zag varints over
base64 for time deltas, a delta-of-delta chain for track coordinates, and trip
polylines simplified to a 3 m tolerance with every stop vertex pinned. Codec
encode/decode lives in src/gtfs-codec.mjs and is shared by both the builder
and the app, so the two sides cannot drift; src/gtfs-codec.test.mjs covers the
round trips. The file is 530 KB raw but ~106 KB gzipped, and it is always served
compressed — that is the number to watch, not the raw size.
The trains themselves (src/live-trains.js) are drawn by one instanced WebGL
layer: the shader paints a rounded car per instance, so the CPU only writes a
small float buffer per frame and there is no GeoJSON source to parse or tile.
Movement comes from each path's cumulative distances and the trip's
arrival/departure profile, so trains dwell at stations and run between them at
the timetable's speed. Add ?trainsdebug to the URL for per-frame timing.
From my other repo: cheeaun/sgraildata.
- Go to https://codepen.io/cheeaun/full/pogQjgV
- Paste all the train codes. (
/data/raw/sg-stations-codes.txtfromsgraildatarepo) - Click "Generate Images" button to download ZIP file of SVG images.
- Extract files from the ZIP file.
- Go to https://www.facetstudios.com/sprite-generator
- Drag/Upload all SVG files to the site.
- Uncheck "Export for retina". Check "Generate JSON".
- Click "Download Files" button.
- Extract files from ZIP file.
- Move & rename sprite image to
src/stations.png. Optimize the image with TinyPNG. - Move & rename sprite JSON to
scripts/sprite.json. - Run
node scripts/gen-stations-sprite.jswhich will generatesrc/stations.json.
Uses MapLibre GL JS with OpenFreeMap vector tiles — no API key. src/basemap-style.json is generated from OpenFreeMap's Bright style by npm run gen-style (scripts/gen-basemap-style.mjs).
Tamil station names use MapLibre's font-faces feature with a self-hosted Noto Sans Tamil font (src/fonts/), so the browser shapes and rasterizes each grapheme cluster natively. The font is licensed under the SIL Open Font License (src/fonts/OFL.txt).
- Data: © LTA © Data.gov.sg © SMRT © SBS
- Everything else: MIT



