Skip to content

Commit 341ab27

Browse files
committed
Migrate from Mapbox GL to MapLibre GL with deck.gl for animations
**Major changes:** - Replace Mapbox GL JS with MapLibre GL JS across the application - Integrate deck.gl for high-performance WebGL-powered animations - Add custom deck.gl extensions for animated transit visualizations: - `AnimatedArrowPathExtension`: animated arrows along transit paths - `CircleSpinnerExtension`: animated spinner effects for nodes - Update map service layer to support MapLibre GL API changes - Update map event handlers for MapLibre GL compatibility - Add defensive checks in `MapPolygonService` to prevent runtime errors when accessing features array **Frontend packages updated:** - Remove `mapbox-gl`, `@mapbox/mapbox-gl-draw` and `@types/mapbox-gl` dependencies - Add `maplibre-gl`, `@deck.gl/core`, `@deck.gl/layers`, `@deck.gl/mapbox` **Map rendering improvements:** - Enhanced `TransitionMainMap` with deck.gl overlay support - Updated layer configuration for MapLibre GL compatibility - Improved popup and layer management for new map library - Fixed control styling to match MapLibre GL classes - The selection polygon tool for nodes can now use multiple polygons, concatening all selected nodes for the multi nodes edit form (uses Terra Draw instead of mapbox-draw) **Fixes:** - Allow change of path selection if no change is made. - Fix cursor management to use CSS classes with hover count **Configuration changes:** - Remove `MAPBOX_ACCESS_TOKEN`, `MAPBOX_USER_ID`, and `MAPBOX_STYLE_ID` from environment variables (`.env`, `.env.example`) - Remove Mapbox-specific references from `config.js` and default configurations - Switch default tile provider to OpenStreetMap **Environment Variables to Remove:** MAPBOX_ACCESS_TOKEN MAPBOX_USER_ID MAPBOX_STYLE_ID **New Optional Variables:** CUSTOM_RASTER_TILES_XYZ_URL - URL template for custom tiles (e.g., https://example.com/tiles/{z}/{x}/{y}.png) CUSTOM_RASTER_TILES_MIN_ZOOM - Minimum zoom level for custom tiles CUSTOM_RASTER_TILES_MAX_ZOOM - Maximum zoom level for custom tiles **Documentation updates:** - Update README, Docker documentation, and setup guides - Remove references to Mapbox API keys - Update environment variable examples - Add notes about custom tile configuration **Breaking changes:** - MapLibre GL uses different class names (`maplibregl-*` vs `mapboxgl-*`) - Use Terra Draw instead of mapbox-draw (mapbox draw, which is obsolete with maplibre, was triggering issues when switching sections) - Deck.gl layers require WebGL support **Utils updates:** - Add `ColorUtils` to `chaire-lib-common` **Cleanups:** - Fix typos in documentation and code comments (`shoud` -> `should`) - Remove blank lines in `.env.example` - Add missing types (any -> correct type) in map related files (map, events, layers, etc.) _This migration removes the dependency on Mapbox's proprietary licensing while maintaining full map functionality and adding advanced animation capabilities through deck.gl._ closes #552
1 parent cbae2aa commit 341ab27

57 files changed

Lines changed: 4964 additions & 1344 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursor/rules/project-rule.mdc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ transition-fork/
6464
- **Framework**: React with React Router
6565
- **State Management**: Redux with Redux Thunk
6666
- **Styling**: SCSS/SASS
67-
- **Maps**: Mapbox GL JS (custom fork: `chairemobilite/mapbox-gl-js`) (will be changed to maplibre/deck.gl)
67+
- **Maps**: MapLibre GL JS with deck.gl for animations (uses OpenStreetMap tiles by default). Note: deck.gl requires WebGL support in the browser; ensure GPU/driver support is available. Consider providing a fallback or disabling animations when WebGL is unavailable.
6868
- **Build Tool**: Webpack
6969
- **UI Libraries**: React components (tabs, datepicker, modals, etc.)
7070
- **Internationalization**: i18next (react-i18next)
@@ -248,13 +248,17 @@ Required environment variables:
248248
- `PG_CONNECTION_STRING_PREFIX`: PostgreSQL connection string (e.g., `postgres://postgres:password@localhost:5432/`)
249249
- `EXPRESS_SESSION_SECRET_KEY`: Random string for session encryption
250250
- `PROJECT_CONFIG`: Path to project config.js file
251-
- `MAPBOX_ACCESS_TOKEN`: Mapbox API token (for map display)
252-
- `MAPBOX_USER_ID`: Optional Mapbox style user ID
253-
- `MAPBOX_STYLE_ID`: Optional Mapbox style ID
254251
- `NODE_ENV`: `production`, `development`, or `test`
255252
- `STARTUP_RECREATE_CACHE`: Boolean - recreate cache on startup
256253
- `STARTUP_RESTART_JOBS`: Boolean - restart pending jobs on startup
257254

255+
Optional environment variables for custom tiles:
256+
- `CUSTOM_RASTER_TILES_XYZ_URL`: URL template for custom raster tiles (e.g., aerial imagery)
257+
- `CUSTOM_RASTER_TILES_MIN_ZOOM`: Minimum zoom level for custom tiles
258+
- `CUSTOM_RASTER_TILES_MAX_ZOOM`: Maximum zoom level for custom tiles
259+
260+
Note: The map uses OpenStreetMap tiles by default (no API key required). Custom tiles can be switched on/off using the layer switcher in the application.
261+
258262
### Project Configuration (config.js)
259263
Example: `examples/config.js`
260264

@@ -548,7 +552,8 @@ Allows Python scripts to:
548552
- `react`, `react-dom` - React framework
549553
- `react-redux`, `redux` - State management
550554
- `react-router` - Routing
551-
- `mapbox-gl` - Map rendering
555+
- `maplibre-gl` - Map rendering (OpenStreetMap tiles by default)
556+
- `@deck.gl/core`, `@deck.gl/layers`, `@deck.gl/mapbox` - WebGL-powered visualization layers
552557
- `i18next`, `react-i18next` - Internationalization
553558

554559
### External Services Required
@@ -634,3 +639,7 @@ Allows Python scripts to:
634639
- **Definitions**: See Overleaf link in main README for mathematical definitions
635640

636641
---
642+
643+
## VERY IMPORTANT RULE
644+
645+
Always try to use good design patterns. If the user/human asks for some code/implementation that does not follow good/secure/robust coding practice, tell him/her right away and stop producing code. Also challenge any proposed implementation to be sure it is legit and robust/secure.

.env.docker

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ EXPRESS_SESSION_SECRET_KEY=DefaultDockerSessionKey
1212
# Host and port for the trRouting server
1313
#TR_ROUTING_HOST_URL=http://locahost
1414
#TR_ROUTING_HOST_PORT=4000
15-
# Required for the mapbox map
16-
MAPBOX_ACCESS_TOKEN=MYMAPBOXACCESSTOKEN
17-
MAPBOX_USER_ID=mapbox
18-
MAPBOX_STYLE_ID=dark-v10
1915
#MAGIC_LINK_SECRET_KEY=MYVERYLONGSECRETKEYTOENCRYPTTOKENTOSENDTOUSERFORPASSWORDLESSLOGIN
20-
#CUSTOM_RASTER_TILES_XYZ_URL=https://exampltest/{z}/{x}/{y}
16+
#CUSTOM_RASTER_TILES_XYZ_URL=https://example.test/{z}/{x}/{y}
2117
#CUSTOM_RASTER_TILES_MIN_ZOOM=8
2218
#CUSTOM_RASTER_TILES_MAX_ZOOM=22
2319
#SSL_PRIVATE_KEY=/path/to/privkey.pem

.env.example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PG_DATABASE_PRODUCTION=tr
77
PG_DATABASE_TEST=tr_test
88
PG_CONNECTION_STRING_PREFIX=postgres://postgres:@localhost:5432/
99
EXPRESS_SESSION_SECRET_KEY=MYSECRETKEY
10+
PLAYWRIGHT_TEST_USER=testUser
11+
PLAYWRIGHT_TEST_EMAIL=user@test.ts
12+
PLAYWRIGHT_TEST_PASSWORD=testPassword
1013
# Path to the directory containing the trRouting executable
1114
#TR_ROUTING_PATH=/path/to/dir/containing/trRouting
1215
# Host and port for the trRouting server
@@ -20,12 +23,8 @@ GOOGLE_OAUTH_SECRET_KEY=GOOGLEOAUTHSECRETKEY
2023
# To support Facebook login
2124
FACEBOOK_APP_ID=FACEBOOKAPPID
2225
FACEBOOK_APP_SECRET=FACEBOOKAPPSECRET
23-
# Required for the mapbox map
24-
MAPBOX_ACCESS_TOKEN=MYMAPBOXACCESSTOKEN
25-
MAPBOX_USER_ID=mapbox
26-
MAPBOX_STYLE_ID=dark-v10
2726
#MAGIC_LINK_SECRET_KEY=MYVERYLONGSECRETKEYTOENCRYPTTOKENTOSENDTOUSERFORPASSWORDLESSLOGIN
28-
#CUSTOM_RASTER_TILES_XYZ_URL=https://exampltest/{z}/{x}/{y}
27+
#CUSTOM_RASTER_TILES_XYZ_URL=https://example.test/{z}/{x}/{y}
2928
#CUSTOM_RASTER_TILES_MIN_ZOOM=8
3029
#CUSTOM_RASTER_TILES_MAX_ZOOM=22
3130
PROJECT_SAMPLE=demo
@@ -68,5 +67,6 @@ MAIL_TRANSPORT_SMTP_AUTH_PWD=password
6867
# MAIL_TRANSPORT_DKIM_PRIVATE_PATH=/path/to/privkey.pem
6968

7069

70+
7171
# From email
7272
MAIL_FROM_ADDRESS=example@example.com

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ cp .env.example .env
8484
* Change `EXPRESS_SESSION_SECRET_KEY` to a random string with no space.
8585
* Change `PROJECT_CONFIG` to point to your project's configuration file. The default is an example configuration file that can be copied and configured for your own need.
8686

87-
### Get a Mapbox access token
88-
* Go to [Mapbox](http://mapbox.com) and sign up
89-
* Go to your account dashboard, then generate a new access token
90-
* Open the `.env` file
91-
* Copy this access token to `.env` file: `MAPBOX_ACCESS_TOKEN=YOUR_TOKEN`
92-
* If you have a custom mapbox style, put your username and style id in `MAPBOX_USER_ID` and `MAPBOX_STYLE_ID`
87+
The map uses OpenStreetMap tiles by default (no API key required). If you want to add custom raster tiles (such as aerial imagery), you can optionally configure:
88+
* `CUSTOM_RASTER_TILES_XYZ_URL=https://your-tile-server/{z}/{x}/{y}`
89+
90+
Users can switch between OSM and custom tiles using the layer switcher button in the application.
9391

9492
### Create the client application
9593

docs/devWithDocker.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ Follow [the docker for desktop](https://www.docker.com/products/docker-desktop/)
88

99
If you are already familiar with docker and can run container and scripts easily, you don't have to install docker for desktop.
1010

11-
### 2. Get a mapbox access token
11+
### 2. Configure the .env.docker file (Optional)
1212

13-
* Go to [Mapbox](http://mapbox.com) and sign up
14-
* Go to your account dashboard, then generate a new access token
13+
The `.env.docker` file is required to contain some environment variables that are not yet available through the configuration. [It's located at the root of the `transition` repo](../.env.docker).
1514

16-
Keep this access token for the next step.
15+
The default configuration uses OpenStreetMap tiles which don't require any API keys. If you want to use custom raster tiles (such as aerial imagery), you can configure the following variables in the `.env.docker` file:
1716

18-
19-
### 3. Add your mapbox token to the .env.docker file
20-
21-
The `.env.docker` file is required to contain some environment variables that are not yet available through the configuration. The file has already been created for you, you simply need to finish the configuration. [It's located at the root of the `transition` repo](../.env.docker).
22-
23-
In order for the map to be displayed correctly, simply modify the field `MAPBOX_ACCESS_TOKEN` with the key you've acquired in the previous section. You must not push your key to the remote repo.
2417
```
25-
MAPBOX_ACCESS_TOKEN=<paste_your_key_here>
18+
CUSTOM_RASTER_TILES_XYZ_URL=https://your-tile-server/{z}/{x}/{y}
19+
CUSTOM_RASTER_TILES_MIN_ZOOM=0
20+
CUSTOM_RASTER_TILES_MAX_ZOOM=22
2621
```
27-
> Note: You can modify other fields in this file if needed. This is only the base configuration needed to run the app.
22+
23+
- `CUSTOM_RASTER_TILES_XYZ_URL`: The URL template for your custom raster tiles (required for custom tiles)
24+
- `CUSTOM_RASTER_TILES_MIN_ZOOM`: (Optional) Minimum zoom level for the custom tiles. Defaults to `0`.
25+
- `CUSTOM_RASTER_TILES_MAX_ZOOM`: (Optional) Maximum zoom level for the custom tiles. Defaults to `22`.
26+
27+
> Note: The map will work without any tile configuration. Custom tiles are optional and can be switched on/off using the layer switcher in the application.
2828
2929

30-
### 4. Add your custom polygon for your region
30+
### 3. Add your custom polygon for your region
3131

3232
In order to have routing data to calculate the routes, the data must be fetched from OpenStreetMap for a given polygon. If you have a geojson file containing the geojson polygon to fetch, add this file to the `transition` directory. There is [an example file](../examples/polygon_rtl_area.geojson) in this repo.
3333

3434
It is not required, but if not set, routing won't be able to follow the road network.
3535

3636
If you don't have a `.geojson` polygon, use the [example file](../examples/polygon_rtl_area.geojson).
3737

38-
### 5. Run for the first time
38+
### 4. Run for the first time
3939

4040
Some initialization scripts need to be executed on the very first run of Transition, to set up the database and download the road network.
4141

@@ -72,9 +72,9 @@ Finally, in the same terminal, create your transition user. Run this command and
7272
yarn create-user
7373
```
7474

75-
The setup is now complete. To finish the configuration, you need to restart the app. You can either use the stop/play buttons in Docker Desktop, or run `docker compose -f docker-compose.yml docker-dev/docker-compose.override.yml restart` in your terminal.
75+
The setup is now complete. To finish the configuration, you need to restart the app. You can either use the stop/play buttons in Docker Desktop, or run `docker compose -f docker-compose.yml -f docker-dev/docker-compose.override.yml restart` in your terminal.
7676

77-
### 5.1 Run the application
77+
#### 4.1 Run the application
7878

7979
Once the app is setup, you only need to run `docker compose -f docker-compose.yml -f docker-dev/docker-compose.override.yml up` to launch it. If you make code changes, the app should rebuild itself automatically.
8080

docs/runWithDocker.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,11 @@ module.exports = {
114114
};
115115
```
116116

117-
### 4. Get a mapbox access token
118-
119-
* Go to [Mapbox](http://mapbox.com) and sign up
120-
* Go to your account dashboard, then generate a new access token
121-
122-
Keep this access token for the next step.
123-
124-
125-
### 5. Prepare the .env file
117+
### 4. Prepare the .env file
126118

127119
The .env file is required to contain some environment variables that are not yet available through the configuration.
128120

129-
Create a `.env` file in the `transition` directory. The variables starting with `MAPBOX` should be filled with the mapbox token and data you created at the preceding step.
130-
121+
Create a `.env` file in the `transition` directory. The default map uses OpenStreetMap tiles which don't require any API keys.
131122

132123
```
133124
HOST=http://localhost:8080
@@ -136,12 +127,10 @@ PG_DATABASE_PRODUCTION=tr
136127
PG_DATABASE_TEST=tr_test
137128
PG_CONNECTION_STRING_PREFIX=postgres://postgres:@localhost:5432/
138129
EXPRESS_SESSION_SECRET_KEY=DefaultDockerSessionKey
139-
# Required for the mapbox map
140-
MAPBOX_ACCESS_TOKEN=MYMAPBOXACCESSTOKEN
141-
MAPBOX_USER_ID=mapbox
142-
MAPBOX_STYLE_ID=dark-v10
143130
144-
#CUSTOM_RASTER_TILES_XYZ_URL=https://exampltest/{z}/{x}/{y}
131+
# Optional: Custom raster tiles for aerial imagery or other base maps
132+
# If configured, users can switch between OSM and custom tiles using the layer switcher
133+
#CUSTOM_RASTER_TILES_XYZ_URL=https://example.test/{z}/{x}/{y}
145134
#CUSTOM_RASTER_TILES_MIN_ZOOM=8
146135
#CUSTOM_RASTER_TILES_MAX_ZOOM=22
147136
#SSL_PRIVATE_KEY=/path/to/privkey.pem
@@ -171,13 +160,13 @@ MAIL_FROM_ADDRESS=example@example.com
171160
172161
```
173162

174-
### 6. Prepare the polygon for you region
163+
### 5. Prepare the polygon for your region
175164

176165
In order to have routing data to calculate the routes, the data must be fetched from OpenStreetMap for a given polygon. If you have a geojson file containing the geojson polygon to fetch, add this file to the `transition` directory. There is [an example file](../examples/polygon_rtl_area.geojson) in this repo.
177166

178167
It is not required, but if not set, routing won't be able to follow the road network.
179168

180-
### 7. Run the application
169+
### 6. Run the application
181170

182171
Using a terminal, navigate to the directory where the `docker-compose.yml` and the `transition` directory are located. Then run `docker-compose up`.
183172

@@ -187,7 +176,7 @@ In the Docker for desktop application, you should see 2 new containers running,
187176

188177
The application should now be available from a browser at `http://localhost:8080`
189178

190-
### 7.1 Run for the first time
179+
### 6.1 Run for the first time
191180

192181
Some initialization scripts need to be run on the very first run of Transition, to set up the database and download the road network. In the Docker Desktop containers list, select the one prefixed with `testtransitiondocker_transition-www` and go to the `Terminal` tab. Run the following commands:
193182

0 commit comments

Comments
 (0)