Closed aboeglin closed 7 years ago
Hi! I think you need to provide you own subclass of the routing Base class.
You only need to implement one method: fetch
Within fetch
:
start
events, like here.Route
class expects.Route
class, like here.I hope this helps. Let me know, if you have any further questions.
Of course, pull requests are always appreciated! :)
Best, Christian
Thanks, I'll read through all this. And another question, if I would just use navigation.setRoute() with the correct format, would it work ? Is there a way to shortcut the routingService ? So that on rerouting I could just set the new route directly ?
I have all the routing data already on the client side for other needs and I'd like to just pipe ffwdme in somehow. I know my fetch method could take care of getting the data and convert it, but I thought there could be a more straight forward way.
Well, maybe I described it a little bit too complicated. It is basically just this:
ffwdme.routing.MyOwnRouting = ffwdme.routing.Base.extend({
fetch: function() {
ffwdme.trigger(this.eventPrefix() + ':start', { routing: this });
var yourRawRoute; // ... wherever this comes from
var routeStruct; // your routing data in a compatible format
var route = new ffwdme.Route().parse(routeStruct);
this.success(yourRawRoute, route);
// if something goes wrong
// this.error(someError);
}
});
Then initialize the lib like this:
ffwdme.initialize({
routing: 'MyOwnRouting'
});
I would recommend to do it this way in order to stay within the lifecycle events of the framework.
In this demo code routeStruct
must be of this format.
I see, I'll give it a try in the coming days and report back. Thanks for the support and quick answers !
I think I have the parsing part sorted out at the moment. Also, it seems you used turnAngle and turnType instead of turn_angle and turn_type. Are these used internally or is it just metadata to help figure out what to show in the UI when handling ffwdme events through the navInfo ?
Would it be possible to add extra info then ?
Hi,
it depends no the UI components you want to use. I think only distance
, duration
and path
are required, the rest is optional and also often depends on the routing adapter. (e.g. Graphhopper delivers the informatin in another Format.
You can add meta data with no problem, just add additional fields. They will just get passed with the other information, so you can use them in the UI.
Another question, I have it all set up and running. But in the prototype I work on at the moment I handle routes with waypoints in between. Say A -> B -> C -> D. At the moment, is there a way to handle this through ffwdme ? I suppose not as the directions array of the routeStruct only has one level, but I just wanted to be sure. So I should just return an array of directions which contains the directions of [...AB, ...BC, ...CD], is that correct ? And then I could handle the arrival at these locations myself in the onroute handler.
And a last question about the path property in a direction of the routeStruct. Should it contain only two locations ( start/end ), or can it have more than 2 ? In that case, would it improve the navigation ? I ask this because I encountered an issue when I start a route on an avenue for instance, and that route forces the driver to do a u-turn a bit further, sometimes the navigation jumps on the step after the u-turn ( I suppose it resolves on being on the other side of the street in the process ). But in general I feel that it should only try to get to the nextDirection of the NavInfo. So the question was to know if having more points in the path ( if that is allowed, as the example only shows 2, I assumed it was start/end ), could help the algorithm to sample the correct direction.
Also I wanted to add a big thanks for you help and I hope the discussion will help others. It's also a valuable resource to improve the documentation I believe.
Regarding your first problem: Maybe this issues will help you.
Another option would be to use the existing events and chain them. If you want to have a route A-B-C, you could just set route A-B in ffwdme, listen to the navigation:onroute event and once the destination is reached, you set the route B-C in ffwdme
I think this is how I would do it, especially, if you have the routes at hand on the clientside.
Regarding your second question:
The path
attribute of an entry in the directions
array of the route struct can (and should) contain a lot more than just two coordinates.
One entry in the directions
array is one turn instruction.
It should contain all coordinates used to draw the path as a polygon on a map, from one turn instruction to another. The only rule is, that the last coordinate from one entry should be the first coordinate from the next.
I hope this helps!
Hi,
I would love to use this library with data provided by mapbox api. But I have already the routing data and need to feed ffwdme.js with my data directly without going through a routingService. Is there a way to directly feed in the routing data without having to create a custom router service ( eg sub classing routing/base ) ? If yes, would it be possible to get some documentation on the shape the routing data is supposed to have ?
If anyone can give me a suggested workflow, I'd be happy to provide a PR with documentation for it.
Not to forget, thanks for your work !
Have a good Sunday !