Skip to content

Implements a more precise way to add new intermediate points in web UI - #791

Merged
karussell merged 4 commits into
graphhopper:masterfrom
easbar:web_ui_intermediate_points
Sep 13, 2016
Merged

karussell merged 4 commits into
graphhopper:masterfrom
easbar:web_ui_intermediate_points

Conversation

@easbar

@easbar easbar commented Sep 10, 2016 •

Copy link
Copy Markdown
Member

Previously, the order of intermediate points was simply equal to the order in which the points were added. This PR changes this behavior such that a newly added point is inserted between the closest two existing waypoints.
Edit: I just realized there is still a problem with alternative routes ... (fixed in second commit)

@karussell

Copy link
Copy Markdown
Member

Thanks! Will try it out in the next days

Comment thread web/src/main/webapp/js/main-template.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is a bit nitpicking but as we 'emulate' GeoJSON we would need underscore - does this make sense :) ?

I.e.
snapped_waypoints: path.snapped_waypoints

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure I fixed this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@karussell

Copy link
Copy Markdown
Member

Thanks again - works perfectly :) !

Would you mind to fix the minor mentioned thing and (if possible) add a quick test for it here?

@karussell karussell added this to the 0.8 milestone Sep 12, 2016
@easbar
easbar force-pushed the web_ui_intermediate_points branch from e7b1634 to 0fab398 Compare September 13, 2016 11:43
@easbar

easbar commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

Would you mind to fix the minor mentioned thing and (if possible) add a quick test for it here?

I would like to add a test, but this does not seem very easy at the moment. We could run a kind of integration test in the web browser (maybe using phantomJS). Alternatively, we could extract the function that finds the correct index for the waypoint and test it, but in this case we would still have to mock some of the dependencies, like the mapLayer and some more Leaflet stuff (L.latLng etc.). As far as I can tell for both solutions we are missing some infrastructure right now.

I also thought about if some of the functionality needed here should be available within graphhopper, so we could reduce the amount of logic in the UI layer. For example when calculating a route for given via-points, is it possible to keep track which parts of the resulting route lie between which via-points ? What I mean is this:

Request: A --> B --> C (route from A to C via B)
Response: A --> x_1 --> x_2 --> ... --> B --> x_45 -->x_46 --> ...-->x_99 --> C (exact coordinates of total route)

Is there a way to obtain the via-points that are the start and end of a given route segment, e.g. is it possible to call something like response.intermediatePoints(x_45) and retrieve (B, C) ? As far as I could tell the graphhopper response only returns the whole route (x_1, x_2, ...., x_99) and the via-points (A, B, C) separately, but no information which coordinates lie between which via-points.

@karussell

Copy link
Copy Markdown
Member

I would like to add a test, but this does not seem very easy at the moment

Ok, no problem. I just thought somehow assuming 3 points and then add another and asserting the correct index is somehow possible.

We could run a kind of integration test in the web browser (maybe using phantomJS).

I would prefer to keep one tool for now (Jasmine) but we should investigate alternatives.

we would still have to mock some of the dependencies, like the mapLayer and some more Leaflet stuff

That would be okay for now

I also thought about if some of the functionality needed here should be available
within graphhopper, so we could reduce the amount of logic in the UI layer

Interesting thought. We already can calculate distances to 'edges' but this is not published as API.

As far as I could tell the graphhopper response only returns the whole route (x_1, x_2, ...., x_99)
and the via-points (A, B, C) separately, but no information which coordinates lie between which via-points.

There are two possibilities with which one could achieve this

  • the sign of the instruction indicates if this is a via point and then one could merge the point indices of the interval array
  • or using snapped_waypoints

We could make it easier with a simple array where values correspond to the point indices for every via-point, something like waypoints_intervals

@easbar

easbar commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

we would still have to mock some of the dependencies, like the mapLayer and some more Leaflet stuff

That would be okay for now

I will try this for now.

@karussell

Copy link
Copy Markdown
Member

Thanks a bunch!

@easbar
easbar force-pushed the web_ui_intermediate_points branch from 90f366c to fd98c15 Compare September 13, 2016 16:01
@@ -0,0 +1,74 @@
// because leaflet-src.js requires window, document etc. we need to provide these variables...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty ugly. Maybe you have a better idea ? We could keep the tests separate from leaflet entirely by reimplementing/copy&pasting the functionality of L.latLng, but I do not think this is much nicer. We could also put this workaround into a separate file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, but looks okay to me. We are kind of mocking away these dependencies which could lead to trouble but for now this should be sufficient. In long term we should try to move more parts into a better structured code ;( (more seperate from UI)

@easbar

easbar commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

I separated the method for finding the correct index and wrote two tests for it. Maybe you can have a look again now. Let me know if you do not like the naming etc. !

@easbar

easbar commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

We could run a kind of integration test in the web browser (maybe using phantomJS).

I would prefer to keep one tool for now (Jasmine) but we should investigate alternatives.

I was thinking about a tool that allows us to simulate clicks on the map and for example check whether the url changes in a correct way, not sure if this can be done only with Jasmine.

@easbar

easbar commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

We could make it easier with a simple array where values correspond to the point indices for every via-point, something like waypoints_intervals

If this was available we would at least not have to find the next way point by iterating over the route.

@karussell

karussell commented Sep 13, 2016 •

Copy link
Copy Markdown
Member

I separated the method for finding the correct index and wrote two tests for it. Maybe you can have a look again now. Let me know if you do not like the naming etc. !

Thanks a bunch, this is what I meant and looks good :) !

I was thinking about a tool that allows us to simulate clicks on the map and for example check whether the url changes in a correct way

ah, yes. Something like selenium? I see this more like the integration testing which is currently not existant and possibly also important. The unit testing part should be more or less decoupled from the UI and doable with jasmine (I know the architecture is currently bad to have this properly separated)

If this was available we would at least not have to find the next way point by iterating over the route.

Ok, maybe create an issue for this so it does not get lost?

@karussell
karussell merged commit 712787c into graphhopper:master Sep 13, 2016
@karussell

Copy link
Copy Markdown
Member

Merged and already live :) ! Thanks again!

@oblonski

Copy link
Copy Markdown
Member

Cool. Thanks a lot. It looks great.

@boldtrn

boldtrn commented Sep 14, 2016 •

Copy link
Copy Markdown
Member

@ammagamma Nice feature, works pretty good. When start and end is the same point, the order of points is not correctly calculated anyomre, maybe you can checkt?

@karussell

Copy link
Copy Markdown
Member

@boldtrn do you have an example as I cannot reproduce this.

@easbar

easbar commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

@boldtrn thanks for testing, this is indeed a problem, which occurs whenever a waypoint is crossed multiple times. I will look for a better solution.

@easbar

easbar commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

ah, yes. Something like selenium? I see this more like the integration testing which is currently not existant and possibly also important.

Yes thats what I meant

@easbar

easbar commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

#795

@easbar
easbar deleted the web_ui_intermediate_points branch February 3, 2017 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants