-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add maplibre-gl-directions example
- Loading branch information
1 parent
82c00e6
commit 81b9af7
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link href="https://unpkg.com/maplibre-gl@4.5.0/dist/maplibre-gl.css" rel="stylesheet" /> | ||
<script src="https://unpkg.com/maplibre-gl@4.5.0/dist/maplibre-gl.js"></script> | ||
<style> | ||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
height: 100%; | ||
} | ||
#map { | ||
min-height: 500px; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
<script type="module"> | ||
import MapLibreGlDirections from "https://unpkg.com/@maplibre/maplibre-gl-directions@0.7.0/dist/maplibre-gl-directions.js"; | ||
|
||
// Don't forget to replace <YOUR_ACCESS_TOKEN> by your real access token! | ||
const accessToken = "<YOUR_ACCESS_TOKEN>"; | ||
const map = new maplibregl.Map({ | ||
container: "map", | ||
style: `https://api.jawg.io/styles/jawg-streets.json?access-token=${accessToken}`, | ||
zoom: 5, | ||
center: [3.47, 46.0], | ||
hash: true, | ||
}).addControl(new maplibregl.NavigationControl(), "top-right"); | ||
// This plugin is used for right to left languages | ||
maplibregl.setRTLTextPlugin("https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.2.3/mapbox-gl-rtl-text.min.js"); | ||
|
||
map.on("load", () => { | ||
const directions = new MapLibreGlDirections(map, { | ||
api: "https://api.jawg.io/routing/route/v1", | ||
profile: "car", | ||
requestOptions: { | ||
"access-token": accessToken, | ||
alternatives: "true", | ||
overview: "full", | ||
}, | ||
}); | ||
|
||
// Enable interactivity (if needed) | ||
directions.interactive = true; | ||
|
||
// Paris [lng, lat] | ||
const start = [2.3522, 48.8566]; | ||
// Marseille [lng, lat] | ||
const end = [5.3698, 43.2965]; | ||
|
||
// Set the waypoints programmatically | ||
directions.setWaypoints([start, end]); | ||
}); | ||
</script> | ||
</body> | ||
</html> |