Digitransit-ui is a mobile friendly User interface built to work with Digitransit APIs.
Application is built with React. React components can access data in two different ways:
Basically, division between alternatives is:
Installation instructions are available at GitHub
Unit testing is used.
Before a request reaches the React application, the Digitransit-ui server passes it through a URL middleware (server/middleware/legacyUrlMiddleware.js). The middleware keeps old links working and sanitizes query parameters. It is mounted for the root path and for the legacy language paths /fi/, /en/, /sv/, /ru/ and /slangi/.
These checks are always performed:
time parameter is removed.queryMaxAgeDays is set (14 days in the HSL and Waltti configurations), a time older than that is removed. The user is redirected to the same URL without it, so a stale link opens with the current time.If the configuration option redirectReittiopasParams is true (enabled in the HSL, Waltti, Matka and Kela configurations), the middleware also handles the URL forms of the old Reittiopas service:
/en/ is redirected to / with the query parameter locale=en. The language is also stored in the lang cookie. slangi is mapped to fi.from, to, from_in or to_in, the places are resolved on the server and the user is redirected to a new style URL.lang cookie and the locale query parameter disagree, the user is redirected to the same URL with locale set to the cookie value.Supported old parameters:
| Parameter | Meaning |
|---|---|
from, to |
Origin or destination. Either a free text place name, or the old format <text>*<name>*<x>*<y> (for example Pasila*Pasila*2551987*6676652), where x is the easting and y the northing in KKJ zone 2 (central meridian 24°E, EPSG:2392); the first part is ignored. |
from_in, to_in |
Free text place name, used when from or to is not set. A + is interpreted as a space. |
daymonthyear (d.m.yyyy), year, month, day, hour, minute |
Departure time. Used only if it is not older than queryMaxAgeDays. |
timetype=arrival |
The time is the arrival time. Converted to arriveBy=true. |
Free text place names are resolved using the Geocoding API; the first result is used. The user is redirected as follows:
| Result | Redirect |
|---|---|
| Both places resolved | Itinerary search page /reitti/<from>/<to>/, with time and arriveBy parameters when given |
| Only one place resolved | The front page (indexPath) with the resolved place filled in, and the other as empty (/%20/) |
| Geocoding failed or found nothing | The front page with empty places |
For example, https://reittiopas.hsl.fi/fi/?from=steissi&to=pasila redirects to an itinerary search from Helsinki railway station to Pasila: /reitti/<from>::<lat>,<lon>/<to>::<lat>,<lon>/.
Places are part of the UI path. The itinerary search page uses the path /reitti/<from>/<to>/, and the front page uses /<from>/<to>/ (for example /etusivu/<from>/<to>/ in the HSL configuration, where etusivu is the configured indexPath). The "Near you" view uses /lahellasi/<mode>/<place>.
A place is written as
<address>::<lat>,<lon>where address is URL encoded, for example Pasila%2C%20Helsinki::60.198118,24.934074. A stop or station can be given as <name>**<gtfsId>::<lat>,<lon>. Two special values are also used:
| Value | Meaning |
|---|---|
- |
The place is not set |
POS |
The user's current location (position) |
POS)POS can be used as the origin, the destination, or the place of the "Near you" view. It means "the device location", which is not known when the link is created. For example:
/reitti/POS/<to>/ is an itinerary search from the user's current location./reitti/<from>/POS/ is an itinerary search to the user's current location./lahellasi/BUS/POS shows departures of bus stops near the user.How POS is handled:
POS in the URL with the address and coordinates found (<address>::<lat>,<lon>) and proceeds normally. The address is acquired using reverse geocoding.POS is replaced with -, and the user can select the place manually. In the "Near you" view the user is asked to search for a place instead.POS, so that a saved link or a bookmark always uses the current location. If the user selects another place, POS is replaced with that place.POS is resolved in the browser. The server does not know the location, and the URL middleware does not resolve it.
The other place of an itinerary search can be set at the same time, so a link such as /reitti/POS/Pasila%2C%20Helsinki::60.198118,24.934074/ works as a "route from here to Pasila" link for any user.
| Asset | Url |
|---|---|
| Routing - API | https://digitransit.fi/en/developers/apis/1-routing-api/ |
| Realtime HSL - API | https://digitransit.fi/en/developers/apis/5-realtime-api/ |
| Map - API | https://digitransit.fi/en/developers/apis/4-map-api/ |
| Geocoding - API | https://digitransit.fi/en/developers/apis/3-geocoding-api/ |
| Dependecy | url |
|---|---|
| React | https://github.com/facebook/react |
| React-leaflet | https://github.com/PaulLeCam/react-leaflet |
| Found | https://github.com/4Catalyzer/found |
| Farce | https://github.com/4Catalyzer/farce |
| Relay | https://github.com/facebook/relay |
| Babel relay plugin | https://github.com/facebook/relay |
| Leaflet | https://github.com/Leaflet/Leaflet |
| MQTT.js | https://github.com/mqttjs/MQTT.js |
| Polyfill-service | https://github.com/Financial-Times/polyfill-service |
| PBF | https://github.com/mapbox/pbf |
| Webpack | https://github.com/webpack/webpack |
Follow GraphQL specification
https://graphql.org/https://graphql.org/
From time to time check HSL style guide
https://www.hsl.fi/tyyliopas
Follow EcmaScript, and browser development
https://esdiscuss.org/
https://discuss.babeljs.io/
http://www.ecma-international.org/news/index.html
http://caniuse.com/#info_news
| Asset | Url |
|---|---|
| source | https://github.com/HSLdevcom/digitransit-ui |
| DockerHub | https://hub.docker.com/r/hsldevcom/digitransit-ui/ |
| Dockerfile | https://github.com/HSLdevcom/digitransit-ui/blob/v3/Dockerfile |
The Docker image is called hsldevcom/digitransit-ui:v3-prod and it is available at DockerHub.
To run Docker container, run:
docker run -p 8080:8080 -it -e CONFIG=hsl -e API_URL=https://api.digitransit.fi -e MAP_URL=https://cdn.digitransit.fi -e NODE_OPTS=--max_old_space_size=1500 -e API_SUBSCRIPTION_QUERY_PARAMETER_NAME=digitransit-subscription-key -e API_SUBSCRIPTION_HEADER_NAME=digitransit-subscription-key -e API_SUBSCRIPTION_TOKEN=<your subscription key> hsldevcom/digitransit-ui:v3-prodTo access Docker container:
http://localhost:8080/For More information about how to use Docker see docker info.