Search in sources :

Example 1 with MapRouteInfoMenu

use of net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu in project Osmand by osmandapp.

the class MapActivity method newRouteIsCalculated.

@Override
public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToast) {
    RoutingHelper rh = app.getRoutingHelper();
    if (newRoute && rh.isRoutePlanningMode() && mapView != null) {
        Location lt = rh.getLastProjection();
        if (lt == null) {
            lt = app.getTargetPointsHelper().getPointToStartLocation();
        }
        if (lt != null) {
            double left = lt.getLongitude(), right = lt.getLongitude();
            double top = lt.getLatitude(), bottom = lt.getLatitude();
            List<Location> list = rh.getCurrentCalculatedRoute();
            for (Location l : list) {
                left = Math.min(left, l.getLongitude());
                right = Math.max(right, l.getLongitude());
                top = Math.max(top, l.getLatitude());
                bottom = Math.min(bottom, l.getLatitude());
            }
            List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
            for (TargetPoint l : targetPoints) {
                left = Math.min(left, l.getLongitude());
                right = Math.max(right, l.getLongitude());
                top = Math.max(top, l.getLatitude());
                bottom = Math.min(bottom, l.getLatitude());
            }
            RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
            int tileBoxWidthPx = 0;
            int tileBoxHeightPx = 0;
            MapRouteInfoMenu routeInfoMenu = mapLayers.getMapControlsLayer().getMapRouteInfoMenu();
            WeakReference<MapRouteInfoMenuFragment> fragmentRef = routeInfoMenu.findMenuFragment();
            if (fragmentRef != null) {
                MapRouteInfoMenuFragment f = fragmentRef.get();
                if (landscapeLayout) {
                    tileBoxWidthPx = tb.getPixWidth() - f.getWidth();
                } else {
                    tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
                }
            }
            mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
        }
    }
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) MapRouteInfoMenuFragment(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Location(net.osmand.Location)

Example 2 with MapRouteInfoMenu

use of net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu in project Osmand by osmandapp.

the class MapControlsLayer method initRouteControls.

private void initRouteControls() {
    mapRouteInfoMenu = new MapRouteInfoMenu(mapActivity, this);
    trackDetailsMenu = new TrackDetailsMenu(mapActivity);
}
Also used : TrackDetailsMenu(net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu)

Example 3 with MapRouteInfoMenu

use of net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu in project Osmand by osmandapp.

the class MapMarkerSelectionFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = null;
    if (getArguments() != null) {
        bundle = getArguments();
    } else if (savedInstanceState != null) {
        bundle = savedInstanceState;
    }
    if (bundle != null) {
        target = bundle.getBoolean(TARGET_KEY);
        intermediate = bundle.getBoolean(INTERMEDIATE_KEY);
    }
    MapActivity mapActivity = getMapActivity();
    OsmandApplication app = getMyApplication();
    if (mapActivity != null) {
        MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
        onClickListener = routeInfoMenu.getOnMarkerSelectListener();
        screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
        MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities();
        if (trackingUtils != null) {
            Float head = trackingUtils.getHeading();
            float mapRotation = mapActivity.getMapRotate();
            LatLon mw = mapActivity.getMapLocation();
            Location l = trackingUtils.getMyLocation();
            boolean mapLinked = trackingUtils.isMapLinkedToLocation() && l != null;
            LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
            useCenter = !mapLinked;
            loc = (useCenter ? mw : myLoc);
            if (useCenter) {
                heading = -mapRotation;
            } else {
                heading = head;
            }
        }
    }
    nightMode = !app.getSettings().isLightContent();
    View view = inflater.inflate(R.layout.map_marker_selection_fragment, container, false);
    ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
    closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ListView listView = (ListView) view.findViewById(android.R.id.list);
    final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter();
    List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getMapMarkers();
    if (markers.size() > 0) {
        for (MapMarker marker : markers) {
            adapter.add(marker);
        }
    }
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (onClickListener != null) {
                onClickListener.onSelect(position, target, intermediate);
            }
            dismiss();
        }
    });
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Bundle(android.os.Bundle) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location) Nullable(android.support.annotation.Nullable)

Example 4 with MapRouteInfoMenu

use of net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method openDetails.

void openDetails() {
    if (gpxItem != null) {
        LatLon location = null;
        WptPt wpt = null;
        gpxItem.chartTypes = new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE };
        if (gpxItem.chartHighlightPos != -1) {
            TrkSegment segment = gpx.tracks.get(0).segments.get(0);
            if (segment != null) {
                float distance = gpxItem.chartHighlightPos * elevationDataSet.getDivX();
                for (WptPt p : segment.points) {
                    if (p.distance >= distance) {
                        wpt = p;
                        break;
                    }
                }
                if (wpt != null) {
                    location = new LatLon(wpt.lat, wpt.lon);
                }
            }
        }
        if (location == null) {
            location = new LatLon(gpxItem.locationStart.lat, gpxItem.locationStart.lon);
        }
        if (wpt != null) {
            gpxItem.locationOnMap = wpt;
        } else {
            gpxItem.locationOnMap = gpxItem.locationStart;
        }
        final MapActivity activity = (MapActivity) getActivity();
        if (activity != null) {
            dismiss();
            final OsmandSettings settings = activity.getMyApplication().getSettings();
            settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name), false, gpxItem);
            final MapRouteInfoMenu mapRouteInfoMenu = activity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
            if (MapRouteInfoMenu.isVisible()) {
                // We arrived here by the route info menu.
                // First, we close it and then show the details.
                mapRouteInfoMenu.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        mapRouteInfoMenu.setOnDismissListener(null);
                        MapActivity.launchMapActivityMoveToTop(activity);
                    }
                });
                mapRouteInfoMenu.hide();
            } else {
                // We arrived here by the dashboard.
                MapActivity.launchMapActivityMoveToTop(activity);
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.plus.GPXUtilities.WptPt) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) DialogInterface(android.content.DialogInterface) PointDescription(net.osmand.data.PointDescription) OnDismissListener(android.content.DialogInterface.OnDismissListener) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

MapRouteInfoMenu (net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu)4 Location (net.osmand.Location)2 LatLon (net.osmand.data.LatLon)2 DialogInterface (android.content.DialogInterface)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ListView (android.widget.ListView)1 PointDescription (net.osmand.data.PointDescription)1 QuadPoint (net.osmand.data.QuadPoint)1 RotatedTileBox (net.osmand.data.RotatedTileBox)1 TrkSegment (net.osmand.plus.GPXUtilities.TrkSegment)1 WptPt (net.osmand.plus.GPXUtilities.WptPt)1 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1