Search in sources :

Example 46 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.

the class ImpassableRoadsLayer method applyNewObjectPosition.

@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable final ApplyMovedObjectCallback callback) {
    if (o instanceof RouteDataObject) {
        final RouteDataObject object = (RouteDataObject) o;
        final OsmandApplication application = activity.getMyApplication();
        application.getAvoidSpecificRoads().replaceImpassableRoad(activity, object, position, false, new AvoidSpecificRoadsCallback() {

            @Override
            public void onAddImpassableRoad(boolean success, RouteDataObject newObject) {
                if (callback != null) {
                    callback.onApplyMovedObject(success, newObject);
                }
            }

            @Override
            public boolean isCancelled() {
                return callback != null && callback.isCancelled();
            }
        });
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AvoidSpecificRoadsCallback(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidSpecificRoadsCallback) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 47 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.

the class ImpassableRoadsLayer method getObjectLocation.

@Override
public LatLon getObjectLocation(Object o) {
    if (o instanceof RouteDataObject) {
        RouteDataObject route = (RouteDataObject) o;
        Location location = impassableRoadLocations.get(route.getId());
        return new LatLon(location.getLatitude(), location.getLongitude());
    }
    return null;
}
Also used : LatLon(net.osmand.data.LatLon) RouteDataObject(net.osmand.binary.RouteDataObject) Location(net.osmand.Location)

Example 48 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.

the class MapRenderRepositories method readRouteDataAsMapObjects.

private void readRouteDataAsMapObjects(SearchRequest<BinaryMapDataObject> sr, BinaryMapIndexReader c, final ArrayList<BinaryMapDataObject> tempResult, final TLongSet ids) {
    final boolean basemap = c.isBasemap();
    try {
        for (RouteRegion reg : c.getRoutingIndexes()) {
            List<RouteSubregion> parent = sr.getZoom() < 15 ? reg.getBaseSubregions() : reg.getSubregions();
            List<RouteSubregion> searchRouteIndexTree = c.searchRouteIndexTree(sr, parent);
            final MapIndex nmi = new MapIndex();
            c.loadRouteIndexData(searchRouteIndexTree, new ResultMatcher<RouteDataObject>() {

                @Override
                public boolean publish(RouteDataObject r) {
                    if (basemap) {
                        renderedState |= 1;
                    } else {
                        renderedState |= 2;
                    }
                    if (checkForDuplicateObjectIds && !basemap) {
                        if (ids.contains(r.getId()) && r.getId() > 0) {
                            // do not add object twice
                            return false;
                        }
                        ids.add(r.getId());
                    }
                    int[] coordinantes = new int[r.getPointsLength() * 2];
                    int[] roTypes = r.getTypes();
                    for (int k = 0; k < roTypes.length; k++) {
                        int type = roTypes[k];
                        registerMissingType(nmi, r, type);
                    }
                    for (int k = 0; k < coordinantes.length / 2; k++) {
                        coordinantes[2 * k] = r.getPoint31XTile(k);
                        coordinantes[2 * k + 1] = r.getPoint31YTile(k);
                    }
                    BinaryMapDataObject mo = new BinaryMapDataObject(r.getId(), coordinantes, new int[0][], RenderingRulesStorage.LINE_RULES, true, roTypes, null);
                    TIntObjectHashMap<String> names = r.getNames();
                    if (names != null) {
                        TIntObjectIterator<String> it = names.iterator();
                        while (it.hasNext()) {
                            it.advance();
                            registerMissingType(nmi, r, it.key());
                            mo.putObjectName(it.key(), it.value());
                        }
                    }
                    mo.setMapIndex(nmi);
                    tempResult.add(mo);
                    return false;
                }

                private void registerMissingType(final MapIndex nmi, RouteDataObject r, int type) {
                    if (!nmi.isRegisteredRule(type)) {
                        RouteTypeRule rr = r.region.quickGetEncodingRule(type);
                        String tag = rr.getTag();
                        int additional = ("highway".equals(tag) || "route".equals(tag) || "railway".equals(tag) || "aeroway".equals(tag) || "aerialway".equals(tag)) ? 0 : 1;
                        nmi.initMapEncodingRule(additional, type, rr.getTag(), rr.getValue());
                    }
                }

                @Override
                public boolean isCancelled() {
                    return !interrupted;
                }
            });
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        log.debug("Search failed " + c.getRegionNames(), e);
    }
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) TIntObjectIterator(gnu.trove.iterator.TIntObjectIterator) RouteTypeRule(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule) IOException(java.io.IOException) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex)

Example 49 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createMaxSpeedControl.

public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
    final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
    final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
    final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities();
    final TextInfoWidget speedControl = new TextInfoWidget(map) {

        private float cachedSpeed = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            float mx = 0;
            if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || rh.getCurrentGPXRoute() != null) && trackingUtilities.isMapLinkedToLocation()) {
                RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
                if (ro != null) {
                    mx = ro.getMaximumSpeed(ro.bearingVsRouteDirection(locationProvider.getLastKnownLocation()));
                }
            } else if (rh != null) {
                mx = rh.getCurrentMaxSpeed();
            } else {
                mx = 0f;
            }
            if (cachedSpeed != mx) {
                cachedSpeed = mx;
                if (cachedSpeed == 0) {
                    setText(null, null);
                } else if (cachedSpeed == RouteDataObject.NONE_MAX_SPEED) {
                    setText(map.getString(R.string.max_speed_none), "");
                } else {
                    String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map.getMyApplication());
                    int ls = ds.lastIndexOf(' ');
                    if (ls == -1) {
                        setText(ds, null);
                    } else {
                        setText(ds.substring(0, ls), ds.substring(ls + 1));
                    }
                }
                return true;
            }
            return false;
        }
    };
    speedControl.setIcons(R.drawable.widget_max_speed_day, R.drawable.widget_max_speed_night);
    speedControl.setText(null, null);
    return speedControl;
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingHelper(net.osmand.plus.routing.RoutingHelper) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Aggregations

RouteDataObject (net.osmand.binary.RouteDataObject)49 ArrayList (java.util.ArrayList)13 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)9 Location (net.osmand.Location)9 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)8 TLongHashSet (gnu.trove.set.hash.TLongHashSet)7 LatLon (net.osmand.data.LatLon)6 IOException (java.io.IOException)5 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 QuadPoint (net.osmand.data.QuadPoint)4 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)3 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)3 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)3 RoutingConfiguration (net.osmand.router.RoutingConfiguration)3 RoutingContext (net.osmand.router.RoutingContext)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 Point (java.awt.Point)2