- Mapbox GL JS - Library to render map on browser using Web GL
- Turf.js - Library to calculate great-circles distance
- Arc.js - Library to calculate arc points using great-circles distance
- Jquery - JavaScript library to handle HTML interaction
- Jest - Unit test library
- Flask - Python server framework
- Heroku - Free cloud hosting
- Docker - Linux container for development
Heroku demo: Click here
- The map is rendered using
Mapbox GL JS
. - The map displays arc lines connecting every capital to Helsinki using
greate-circle distance
. - The map with style highlights for better data visualization. Read
Instructions.pdf
for more details. - The lines are colored based on distances.
- The popup with route's distance is shown when the line is hovered on.
- The feature "All flights lead to any city" is implemented by
clicking
into theair plane
markers(representing capitals). All lines that connect to that clicked city.
-
The capital data is stored in the file
capitals.json
from this source. It is served to the front-end by a simple Flask server inindex.py
. -
The front-end code is stored in
./src
directory. Front-end code has 5 main parts:- Fetching and transform data to correct format is done in
src/scripts/data-processor.js
- Controlling mapbox GL is done in
src/scripts/map-wrapper.js
- Handling stylings, theme is done in
src/scripts/stylings.js
- Handling HTML DOM element is done in
src/scripts/dom-handler
- Gluing everything together is in
src/scripts/index.js
- Fetching and transform data to correct format is done in
-
Docker and docker-compose is used for development. Running
webpack-dev-server
in one container andflask
server in another.
mapbox/
└─── docker-files/ # Docker files for front-end and back-end
└─── static/ # Folder to store the built css, js to be served by Flask
└─── templates/ # Html served by Flask
└─── index.py # Python server
└─── capitals.json # JSON capital data
└─── .babelrc # Config for JavaScript ES6 transpiler
└─── .eslintrc # Config for JavaScript linter
└─── webpack.config.js # Config for hot reload development server, package builder
└─── package.json # Package manager config for Javascript project
└─── requirements.txt # Package list for Python
└─── ProcFile # Heroku scripts
└─── run # Script to execute unit test, lint inside Docker container
└─── Instructions.pdf # INTRUCTION ON HOW TO USE THE PRODUCT
│
└─── src/scripts/ # Main scripts
│
└─── index.js # Entry point of the app
└─── data-processor.js # Fetch data and transform data to GEOJSON format
└─── map-wrapper.js # Encapsulate mapbox-gl-js instance and controll the map
│
└─── stylings.js # Handle styling, theme changes
└─── dom-handler.js # Handle HTML DOM events
└─── constants.js # Constants such as API key...
└─── utils.js # Helper functions
└─── __tests__/ # Unit tests
Choose either of the listed methods below(Preferably the first method)
-
USING docker and docker-compose: Running development servers (with hot reload)
- Installing docker (Linux, MacOs,Window)
- Start front-end and back-end development server by the command:
docker-compose up
- Open browser with the address
http://127.0.0.1:8080/
to see the result. Make sure that port8080
is available - Add execution permission for the script
run
:
chmod +x run
- To run unit test, use the command:
./run test
- To run unit test, user the command:
./run lint
- To build package for production deployment, in which the built files
main.js
,runtime.js
,vendor.js
are built into/static
directory.
./run build
-
Installing in your own machine
- Install
node
andnpm
. Check here. - Install
python
andpip
. Check here - Install front-end dependencies:
npm install
- Install back-end dependencies:
pip install -r ./requirements.txt
- Run back-end development server:
python index.py
- Run front-end development server on another terminal tab:
npm run dev
- Open browser with the address
http://127.0.0.1:8080/
to see the result. Make sure that port8080
is available - Run unit tests:
npm test
- Run lint:
npm run lint
- Build production:
npm run build
- Install