A project to simulate guidance routes using Mapbox GL JS from Mapbox Directions API responses.
var simulate = require('guidance-sim').simulate;
var configuration = require('./configuration.json');
var map = new mapboxgl.Map({
// desired map options
});
map.on('style.load', function () {
simulate(map, configuration);
});
mapObject Mapbox GL map objectconfigObject Configuration parameters, which include the following:
| parameter | required | type | default value | notes |
|---|---|---|---|---|
style |
Yes | String | mapbox://styles/mapbox/streets-v8 |
Style ID provided by Mapbox Studio |
route |
Yes | Object | --- | Mapbox Directions v4 or v5 API response |
spacing |
No | String | constant |
|
zoom |
Yes | Number | 17 |
|
pitch |
Yes | Number | 45 |
Pitch when not maneuvering |
timestamp |
Yes | String | 00h00m00s |
Route simulation playback start time |
speed |
Yes | String | 1x |
Route simulation playback speed |
maneuvers |
Yes | Object | --- | Specifies desired buffer (miles), zoom, and pitch for each maneuver |
The maneuvers configuration parameter provides the simulator alternative map parameters when approaching and exiting a maneuver. The following configuration will ease sinusoidally from a pitch of 40° to 35° and zoom of 17 to 17.5 beginning 0.10 miles away from any turns, and ease back to the default values over 0.10 miles afterwards:
{
'zoom': 17,
'pitch': 40,
'maneuvers': [
{
"type": [
"turn right",
"turn left"
],
"buffer": 0.10,
"zoom": 17.5,
"pitch": 35
}
]
}
npm start
# --> http://localhost:9966/
npm run configureThis script generates a starter configuration file for running a simulation. You will be prompted to provide inputs for parameters. Default parameters, presented in magenta text, will be automatically configured if you press `[ENTER]`` without specifying a value.
If there are errors, the script will print the first error it encountered. If there are no errors, a configuration file should be created at the specified filepath (i.e., first input provided).
A maneuver array will be automatically added to your configuration file. Please see the explanation above for maneuver object specifications.
For Directions v5 API responses, maneuvers have an additional modifiers field. If a maneuver type is specified but no modifiers, it is assumed that the rule should be applied to all modifier values. The exception to this is if a modifier is specified for the same type in another maneuver object. In this scenario, the more specific configuration takes precendence.
npm run validateThis script validates the configuration file. You will be prompted to provide the filepath of the file you'd like to validate. The default directory is the main directory.
If there are errors, the script will print the first error it encounters. If there are no errors, the script will print the JSON-formatted configuration file contents back into the terminal.
This function runs the Emitter.stepsTaken function from guidance-replay using the start time determined by the user in the configuration file.
var Emitter = require('guidance-replay').Emitter;
var route = require('guidance-replay').route;
var stepsTaken = require('guidance-sim').stepsTaken;
var configuration = require('./configuration.json');
var emitter = new Emitter(route(configuration.route), 1000);
var seek = 10000 // desired seek time in milliseconds
stepsTaken(emitter, seek);
emitterObject An event emitter object coming off theEmitterfunction inguidance-replayscrubNumber Desired start time in milliseconds.
This function clears the current interval and reinitializes a new interval using a new speed value.
var setSpeed = require('guidance-sim').setSpeed;
var map = new mapboxgl.Map({
// desired map options
});
map.on('style.load', function () {
var response = simulate(map, configuration);
response.on('update', function(data) {
var newSpeed = 500;
response.interval = setSpeed(response, response.interval, newSpeed, data.options.frequency);
})
});
responseObject An EventEmitter objectintervalNumber An interval IDspeedNumber The duration in milliseconds over which to ease the map to the new locationoptionsObject Map options from initialization; seesimulate.jsL62:71 for more information
npm test
guidance-sim's People
Forkers
alperdincer shrikantd swizardlv 16697553 heshamghandour tobydigz testbigorg donrv barrycug aratcliffe darthdaver adamratcliffe-tomtom aleonnetguidance-sim's Issues
how can get simulation finish event?
Is there any good way to reset map to before simulation?
Thanks.
Update configuration file validator
Update the configuration file generator to reflect the following changes:
- v4 Directions API routes can now jibe with
"spacing": "acceldecel"mode
Deploying to Heroku and other platforms
Hi, I had two questions regarding this repo. I am trying to deploy the code to Heroku and other deployment platforms and I keep getting this error below:
LiveReload running on 35729
info Server running at http://172.19.106.102:9966/ (connect)
4617ms 3.3MB (browserify)
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed
The port error is happening on each platform. Browserfy seems to have an issue when deploying to a server. It works perfectly locally but would like to see how I can have it running in a development server like heroku.
The other question I had was around starting and stopping the simulator after it started and then restart based on a click function.
Is it possible to change destination after the application is started?
Regular website hosting
Sorry, this might be a dummy question. but is there somehow a way to host it and be able to call by <script ... src="./guidance-sim.js"> ?
Back/Forward functionality
How difficult is it to add a back/forward functionality? Either by distance or to a certain point
Add maneuver object set-up to `configure.sh`
Update configure.sh to set-up the maneuver object according to the configuration route, instead of inserting a dummy object as it currently does.
Add docs files for `util.js` and `setTime.js`
Add a separate file that documents the functions available in:
Update configuration file generator
Update the configuration file generator to reflect the following changes:
- v4 Directions API routes can now jibe with
"spacing": "acceldecel"mode
I may also want to eventually make the saved route response optional and add an option to provide an origin and destination through URL params.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
OpenClaw
Personal AI Assistant
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
