This project developed by a CentraleSupΓ©lec's student aims at creating a map for CentraleSupΓ©lec's 3 campuses.
It is a simple static Web Page integrating OpenStreetMap's API and CentraleSupΓ©lec's building details into a full screen map, optimized for mobile phones too.
CentraleSupelec map example
In a production environnement, it is crucial to have HTTPS encryption or else the copy button in a feature's popup won't work. (read more about this here https://stackoverflow.com/questions/51805395/navigator-clipboard-is-undefined)
The Web App runs in a docker container using the nginxinc/nginx-unprivileged:alpine image (for security issues it is best not to run a docker as root and alpine is a very lightweight linux disto perfect for production). The containered form is needed, even if the app is static, because it makes GET calls to the is denied by CORS policy if it's served locally (Cross-Origin Resource Sharing is a standard mechanism that allows JavaScript XMLHttpRequest (XHR) calls executed in a web page to interact with resources from non-origin domains)
If you are only interesed in running the app locally without changing the source code, to see how it feels, run the following commands:
npm run prod
npm run stop-prod
, to stop it
If you want to run the app locally and make changes to the code, run npm run dev
to start the web-server and npm run stop-dev
to stop it
This project can natively display the maps of CentraleSupΓ©lec's 3 campuses, furthermore it can be adapted and used to create a map for any campus or other structures, more details on the potential of Leaflet library here.
To add elements to the map, follow the tutorial video tutorial.webm
(open it with a web browser).
To add your campuses :
- please refer to & edit
src/data/campuses.js
for all needed informations ; - you will need svg files of your floors, as in
src/assets/svg
, with the same naming convention ; - please refer to & edit
src/views/buildingsInfo.js
to add last informations needed. - don't forget to build !
- Create or edit svg plans of each floors in
src/assets/svg
(respect naming convention) - seeresources/floorPlans/README.md
- Remove data in
src/data
withdraw/draw.py
- seedraw/README.md
- Position them on the map by changing the coordinates of the points in the file
src/views/buildingsInfo.js
- If there are additional floors or floor number changes, adapt the file
src/utils/goToCampus.js
- Draw new rooms on plans with URI
<url>?draw=true
- Add them to
src/data
with thedraw/draw.py
application - consultdraw/README.md
.
Two tutorials have been prepared:
- tutorial.webm : to draw with
draw/draw.py
andHOST_URL/?draw=true
- tutorial2.webm : to remove rooms with
draw/draw.py
Note that there are two ways of modifying an element:
- Either delete it and redesign it.
- Either modify the database files directly by hand: 4 FILES NEED TO BE MODIFIED : json
src/data/cs_<campus>_<floor>.json
, josnsrc/data/cs_<campus>_search.json
, jsonsrc/data/cs_searchByURL.json
and csv ``src/data/cs_features_data.csv`.
This project is provided with MIT license and uses 3 open-source JS libraries and 1 Leaflet plugin having the following licenses:
- Leaflet BSD 2-Clause license
- jQuery MIT license
- FuseJS Apache 2.0 license
- Leaflet.GeoJSONAutocomplete MIT license
For more details refer to LICENSE.dependencies.md file
Some features that are yet to be implemented :
- Implement scrooling in the search box
- Improve FuseJS algorithm
- Fix the floor color bug on Eiffel & Bouygues making floors gray instead of yellow
- Adapt icons sizes & room names with zoom level (check this
This static website is build using HTML, CSS and Vanilla JavaScript with 3 JS libraries:
- Leaflet, a JS library enabling you to call map APIs like OSM, Mapbox, Google Maps, ... and customize them
- JQuery a JS library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax.
- Fuse a JS library to implement fusy search
Remark : (Another alternative to Leaflet is OpenLayers which more complex and richer but for our current use, Leaflet is simple, easy and get's the job done, more info on the comparaison between these 2 here).
The map provider chosen is the only open-source option : OpenStreetMap, more precisely the french version.
When working on a GIS (Geographic Information System), several types of data can be used, such as CSVs, GeoJSONs ... We will be utilizing the GeoJSON format (more details here). It consists of a JSON file following the structure below :
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "",
"coordinates": [],
},
"properties": {}
}
]
}
Each map feature is an element of the "features" array, having a specific geometry (type : Point, Polygon, ... ; coordinates : defined according to the previous type, see this RFC for more details) and a set of properties defined by the developper to customize the map feature when displayed with Leaflet.
Data has been chosen as follows:
- one JSON to search all the elements by URL request
- one JSON per area to search all elements in that location with the search bar (ps, metz, rennes)
- one JSON per floor per area that loads the elements of the floor corresponding to that location => have a light http request and not load all floors at once for a specific location or everything at once which cause browser lagging
These are all stored in simple basic json files for performance and simplicity (no database allowed at the start of the project). If we could get a database (MongoDB preferably) we could store the data in a more structured way and make it easier to add/remove new data ...
The repo is organized as following :
campusmap
βββ draw/ -> Draw App directory, see draw/README.md for more details
βββ node_modules/ -> node modules for webpack, ignored by git
βββ resources/ -> Resources folder for the whole project
β βββ data/ -> see resources/data/README.md for more details
β βββ floorPlans/ -> Floor plans for the 3 campuses, see resources/floorPlans/README.md for more details
β βββ icons/ -> Icons for the map features
βββ src/ -> Source code project
β βββ assets/ -> Assets folder
| | βββ icons/ -> A copy of ../../ressources/icons
β | βββ svg/ -> A modified version of ../../ressources/floorPlans
| βββcomponents/ -> Map components
| | βββ autocompleteSearchBox.js -> Autocomplete search box
| | βββ campusSelector.js -> Campus selector
| | βββ markers.js -> Features markers
β βββ data/* -> Data generated by /draw/draw.py
| βββ lib/ -> Libraries used in the web app
| | βββ fuse/ -> FuseJS library
| | βββ jquery/ -> JQuery library
| | βββ leaflet/ -> Leaflet library
| βββ styles/ -> Stylesheets used in web app
| | βββ image/ -> Images for the search box
| | βββ campusSelection.css -> Stylesheet for the component y
| | βββ floorButtons.css -> //
| | βββ footer.css -> //
| | βββ map.css -> //
| | βββ searchBox.css -> //
β βββ utils/ -> Utils functions
| | βββ addaData.js -> Add data to the map
| | βββ downloadDrawData.js -> Define how drawn data is downloaded
| | βββ findByUrl.js -> Find a feature by its URL
| | βββ goToCampus.js -> Go to a campus
| | βββ locationCookie.js -> Location cookie
β | βββ tools.js -> Tools
β βββ views/ -> Views elemnents
| | βββ buildingPosition.js -> Define building position
| | βββ draw.js -> Define Leaflet Draw component
| | βββ featureDisplay.js -> Display the features on the map
β | βββ map.js -> Display the map
| βββ index.css -> Main stylesheet
| βββ index.html -> Main HTML file
| βββ index.js -> Main JS file
βββ .gitignore -> gitignore file
βββ create_dist.sh -> Script to create the distribution folder
βββ docker-compose.dev.yaml -> Docker-compose config for development server
βββ docker-compose.prod.yaml -> Docker-compose config for production server
βββ Dockerfile -> Dockerfile for the K8s image
βββ LICENSE.md -> Licenses for the project
βββ LICENSE.dependencies.md -> Licenses for the project
βββ package-lock.json -> Package lock file
βββ package.json -> NPM packages
βββ README.md -> Project information
βββ webpack.config.js -> Webpack config
To edit the documentation website, you can serve a local mkdocs instance : docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material