Search in sources :

Example 11 with RoutingConfiguration

use of net.osmand.router.RoutingConfiguration in project Osmand by osmandapp.

the class CurrentPositionHelper method initCtx.

private void initCtx(OsmandApplication app, List<BinaryMapReaderResource> checkReaders, @NonNull ApplicationMode appMode) {
    am = appMode;
    String p;
    if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
        p = GeneralRouterProfile.BICYCLE.name().toLowerCase();
    } else if (am.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
        p = GeneralRouterProfile.PEDESTRIAN.name().toLowerCase();
    } else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        p = GeneralRouterProfile.CAR.name().toLowerCase();
    } else {
        p = "geocoding";
    }
    BinaryMapIndexReader[] rs = new BinaryMapIndexReader[checkReaders.size()];
    if (rs.length > 0) {
        int i = 0;
        for (BinaryMapReaderResource rep : checkReaders) {
            rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
        }
        RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p, 10, new HashMap<String, String>());
        ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, rs);
        RoutingConfiguration defCfg = app.getDefaultRoutingConfig().build("geocoding", 10, new HashMap<String, String>());
        defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs);
    } else {
        ctx = null;
        defCtx = null;
    }
    usedReaders = checkReaders;
}
Also used : BinaryMapReaderResource(net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource) RoutingConfiguration(net.osmand.router.RoutingConfiguration) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd)

Example 12 with RoutingConfiguration

use of net.osmand.router.RoutingConfiguration in project Osmand by osmandapp.

the class RouteProvider method initOsmAndRoutingConfig.

private RoutingConfiguration initOsmAndRoutingConfig(Builder config, final RouteCalculationParams params, OsmandSettings settings, GeneralRouter generalRouter) throws IOException, FileNotFoundException {
    GeneralRouterProfile p;
    if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
        p = GeneralRouterProfile.BICYCLE;
    } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
        p = GeneralRouterProfile.PEDESTRIAN;
    } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        p = GeneralRouterProfile.CAR;
    } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BOAT)) {
        p = GeneralRouterProfile.BOAT;
    } else {
        return null;
    }
    Map<String, String> paramsR = new LinkedHashMap<String, String>();
    for (Map.Entry<String, RoutingParameter> e : generalRouter.getParameters().entrySet()) {
        String key = e.getKey();
        RoutingParameter pr = e.getValue();
        String vl;
        if (key.equals(GeneralRouter.USE_SHORTEST_WAY)) {
            Boolean bool = !settings.FAST_ROUTE_MODE.getModeValue(params.mode);
            vl = bool ? "true" : null;
        } else if (pr.getType() == RoutingParameterType.BOOLEAN) {
            CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(key, pr.getDefaultBoolean());
            Boolean bool = pref.getModeValue(params.mode);
            vl = bool ? "true" : null;
        } else {
            vl = settings.getCustomRoutingProperty(key, "").getModeValue(params.mode);
        }
        if (vl != null && vl.length() > 0) {
            paramsR.put(key, vl);
        }
    }
    if (params.inSnapToRoadMode) {
        paramsR.put(GeneralRouter.ALLOW_PRIVATE, "true");
    }
    float mb = (1 << 20);
    Runtime rt = Runtime.getRuntime();
    // make visible
    int memoryLimit = (int) (0.95 * ((rt.maxMemory() - rt.totalMemory()) + rt.freeMemory()) / mb);
    log.warn("Use " + memoryLimit + " MB Free " + rt.freeMemory() / mb + " of " + rt.totalMemory() / mb + " max " + rt.maxMemory() / mb);
    RoutingConfiguration cf = config.build(p.name().toLowerCase(), params.start.hasBearing() ? params.start.getBearing() / 180d * Math.PI : null, memoryLimit, paramsR);
    return cf;
}
Also used : CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) GeneralRouterProfile(net.osmand.router.GeneralRouter.GeneralRouterProfile) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) LinkedHashMap(java.util.LinkedHashMap) RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter) RoutingConfiguration(net.osmand.router.RoutingConfiguration) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with RoutingConfiguration

use of net.osmand.router.RoutingConfiguration in project Osmand by osmandapp.

the class CurrentPositionHelper method initCtx.

private void initCtx(SampleApplication app, List<BinaryMapIndexReader> checkReaders) {
    BinaryMapIndexReader[] rs = checkReaders.toArray(new BinaryMapIndexReader[checkReaders.size()]);
    if (rs.length > 0) {
        RoutingConfiguration defCfg = RoutingConfiguration.getDefault().build("geocoding", 10, new HashMap<String, String>());
        defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs);
    } else {
        defCtx = null;
    }
    usedReaders = checkReaders;
}
Also used : RoutingConfiguration(net.osmand.router.RoutingConfiguration) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd)

Aggregations

RoutingConfiguration (net.osmand.router.RoutingConfiguration)13 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)12 RoutingContext (net.osmand.router.RoutingContext)10 ArrayList (java.util.ArrayList)8 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)7 Builder (net.osmand.router.RoutingConfiguration.Builder)5 File (java.io.File)4 RandomAccessFile (java.io.RandomAccessFile)4 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)4 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)4 Point (java.awt.Point)3 RouteDataObject (net.osmand.binary.RouteDataObject)3 LatLon (net.osmand.data.LatLon)3 RouteSegmentResult (net.osmand.router.RouteSegmentResult)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LinkedHashMap (java.util.LinkedHashMap)2 LocationPoint (net.osmand.data.LocationPoint)2 Entity (net.osmand.osm.edit.Entity)2