Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Mapable - Web Application #330

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions JavaScript/Mapable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Mapable**

Mapable is map based application built using html, css and javascript along with mapbox API. One can find real time traffic details over the route. it can also find the best route between source point and destination point via cycling, walking or driving.

Here's a screenshot of the application:

![Screenshot](https://user-images.githubusercontent.com/54570007/138435338-8ba24b11-eca8-4ee2-8860-4952834706f3.png)

[Author: ]: https://github.com/atom19-i
27 changes: 27 additions & 0 deletions JavaScript/Mapable/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='https://api.mapbox.com/mapbox-gl-js/v2.5.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.5.1/mapbox-gl.css' rel='stylesheet' />
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.1.0/mapbox-gl-directions.js"></script>
<link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.1.0/mapbox-gl-directions.css" type="text/css">
<title>Mapable</title>
<style>
body{
margin:0 ;
}
#map{
height: 100vh ;
width: 100vw ;
}
</style>
<!-- defer -> so it loads after the body -->
<script src="script.js" defer></script>
</head>
<body>
<div id='map'></div>
</body>
</html>
34 changes: 34 additions & 0 deletions JavaScript/Mapable/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
mapboxgl.accessToken =
'pk.eyJ1IjoiYXRvbWljZXJyb3JzIiwiYSI6ImNrdXd3ZGs2NjIxZHUydWxucnB6eXg2MDAifQ.deRMw8xzRpHMT_ScmjZpSw';

navigator.geolocation.getCurrentPosition(successLocation,
errorLocation, {
enableHighAccuracy: true
})


function successLocation(position){
// in mapbox, longitude is taken before latitude
setupMap([position.coords.longitude, position.coords.latitude])
}

function errorLocation(){
setupMap([-2.24, 53.48])
}

function setupMap(center){
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: center,
zoom: 15
})

map.addControl(new mapboxgl.NavigationControl());

var directions = new MapboxDirections({
accessToken: mapboxgl.accessToken
});

map.addControl(directions, 'top-left');
}