Search in sources :

Example 1 with RoutingServerConfigEntry

use of net.osmand.server.api.services.OsmAndMapsService.RoutingServerConfigEntry in project OsmAnd-tools by osmandapp.

the class RoutingController method routingParams.

@RequestMapping(path = "/routing-modes", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<?> routingParams() {
    Map<String, RoutingMode> routers = new LinkedHashMap<String, RoutingMode>();
    RoutingParameter nativeRouting = new RoutingParameter("nativerouting", "Development", "[Dev] C++ routing", true);
    RoutingParameter nativeTrack = new RoutingParameter("nativeapproximation", "Development", "[Dev] C++ route track", true);
    RoutingParameter calcMode = new RoutingParameter("calcmode", "[Dev] Route mode", "Algorithm to calculate route", null, RoutingParameterType.SYMBOLIC.name().toLowerCase());
    calcMode.section = "Development";
    calcMode.value = "";
    calcMode.valueDescriptions = new String[] { "Optimal", "Basic", "Slow" };
    calcMode.values = new String[] { RouteCalculationMode.COMPLEX.name(), RouteCalculationMode.BASE.name(), RouteCalculationMode.NORMAL.name() };
    for (Map.Entry<String, GeneralRouter> e : RoutingConfiguration.getDefault().getAllRouters().entrySet()) {
        if (!e.getKey().equals("geocoding") && !e.getKey().equals("public_transport")) {
            RoutingMode rm = new RoutingMode();
            rm.key = e.getKey();
            rm.name = Algorithms.capitalizeFirstLetter(rm.key).replace('_', ' ');
            routers.put(rm.key, rm);
            List<RoutingParameter> rps = new ArrayList<RoutingParameter>();
            for (Entry<String, GeneralRouter.RoutingParameter> epm : e.getValue().getParameters().entrySet()) {
                net.osmand.router.GeneralRouter.RoutingParameter pm = epm.getValue();
                RoutingParameter rp = new RoutingParameter(pm.getId(), pm.getName(), pm.getDescription(), pm.getGroup(), pm.getType().name().toLowerCase());
                if (pm.getId().startsWith("avoid")) {
                    rp.section = "Avoid";
                } else if (pm.getId().startsWith("allow") || pm.getId().startsWith("prefer")) {
                    rp.section = "Allow";
                } else if (pm.getGroup() != null) {
                    rp.section = Algorithms.capitalizeFirstLetter(pm.getGroup().replace('_', ' '));
                }
                if (pm.getType() == RoutingParameterType.BOOLEAN) {
                    rp.value = pm.getDefaultBoolean();
                } else {
                    if (pm.getType() == RoutingParameterType.NUMERIC) {
                        rp.value = 0;
                    } else {
                        rp.value = "";
                    }
                    rp.valueDescriptions = pm.getPossibleValueDescriptions();
                    rp.values = pm.getPossibleValues();
                }
                int lastIndex = -1;
                for (int i = 0; i < rps.size(); i++) {
                    if (Algorithms.objectEquals(rp.section, rps.get(i).section)) {
                        lastIndex = i;
                    }
                }
                if (lastIndex != -1 && !Algorithms.isEmpty(rp.section)) {
                    rps.add(lastIndex + 1, rp);
                } else {
                    rps.add(rp);
                }
            }
            for (RoutingParameter rp : rps) {
                rm.params.put(rp.key, rp);
            }
            rm.params.put(nativeRouting.key, nativeRouting);
            rm.params.put(nativeTrack.key, nativeTrack);
            rm.params.put(calcMode.key, calcMode);
        }
    }
    for (RoutingServerConfigEntry rs : osmAndMapsService.getRoutingConfig().config.values()) {
        RoutingMode rm = new RoutingMode();
        rm.key = rs.name;
        rm.name = Algorithms.capitalizeFirstLetter(rs.name).replace('_', ' ');
        routers.put(rm.key, rm);
        rm.params.put(nativeRouting.key, nativeRouting);
        rm.params.put(nativeTrack.key, nativeTrack);
    }
    return ResponseEntity.ok(gson.toJson(routers));
}
Also used : ArrayList(java.util.ArrayList) GeneralRouter(net.osmand.router.GeneralRouter) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) RoutingServerConfigEntry(net.osmand.server.api.services.OsmAndMapsService.RoutingServerConfigEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 GeneralRouter (net.osmand.router.GeneralRouter)1 RoutingServerConfigEntry (net.osmand.server.api.services.OsmAndMapsService.RoutingServerConfigEntry)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1