Recomended Way to Extend Graphhopper


What would be the recommended way to extend GraphHopper? I.e. add a new FlagEncoder with a custom Weighting class.

I’ve been looking at replicating the structure from OpenRailRouting, but I think that is too much for just adding a new profile.

I am currently using the custom FlagEncoder and Weighting with:

public class RoutingExample {
    public static void main(String[] args) {
        GraphHopper hopper = new CustomHopper().forServer();
        FlagEncoder encoder = new CustomFlagEncoder();
        GHRequest req = new GHRequest(47.811195, 13.033229, 48.210033, 16.363449).
        GHResponse rsp = hopper.route(req);

and with the graphhopper-core and graphhopper-reader-osm maven repositories in the pom file. But I would like to also use the server as an API with the new routing profile. I was thinking to either include Graphhopper as a git submodule or add the appropriate maven repositories (graphhopper-web maybe?)

What would you recommend? Is there an example for this? I am happy to create a simple hello world template as a starting point if there is nothing yet in this direction.


For example you can just implement it in a spring boot application where you get an api call to some endpoint and so you can call graphhopper the way you want it (for example with custom weighting and the flagEncoder you want to use.


Is there a way to use the Graphhopper Web API with a custom routing profile instead of rolling my own? I am not to fresh on Maven, but can I use the graphhopper-web or graphhopper-web-bundle repository maybe?


As an example see our map matching module:


I managed to create a minimal working example: minimal-graphhopper I hope it is a useful starting point. Would you add something to that or have some things that could be improved in the structure of the code?

Also, I assume that needs to be updated since as far as I understood I needed to update DefaultFlagEncoderFactory instead of adding the new FlagEncoder to EncodingManager.parseEncoderString.

The API works now fine, but I experience two issues when running the routing in the browser:

  1. If I select two points, the routing works. But if I first press on one of the encoders I get No area description found and I cannot select points until I reload the page back to localhost:8989. Am I missing something?

  2. Is there a simple way in my minimal example for the new FlagEncoder to have its own symbol (or reuses another symbol) in the browser?