Search in sources :

Example 6 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MapActivityActions method createReloadTitleDialog.

private Dialog createReloadTitleDialog(final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
    builder.setMessage(R.string.context_menu_item_update_map_confirm);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    final OsmandMapTileView mapView = mapActivity.getMapView();
    builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int zoom = args.getInt(KEY_ZOOM);
            BaseMapLayer mainLayer = mapView.getMainLayer();
            if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
            if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
            final QuadRect tilesRect = tb.getTileBounds();
            int left = (int) Math.floor(tilesRect.left);
            int top = (int) Math.floor(tilesRect.top);
            int width = (int) (Math.ceil(tilesRect.right) - left);
            int height = (int) (Math.ceil(tilesRect.bottom) - top);
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    ((OsmandApplication) mapActivity.getApplication()).getResourceManager().clearTileForMap(null, mapSource, i + left, j + top, zoom);
                }
            }
            mapView.refreshMap();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) QuadRect(net.osmand.data.QuadRect) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 7 with RotatedTileBox

use of net.osmand.data.RotatedTileBox 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 8 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MapActivity method onTrackballEvent.

@Override
public boolean onTrackballEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_MOVE && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()) {
        float x = event.getX();
        float y = event.getY();
        final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
        final QuadPoint cp = tb.getCenterPixelPoint();
        final LatLon l = tb.getLatLonFromPixel(cp.x + x * 15, cp.y + y * 15);
        setMapLocation(l.getLatitude(), l.getLongitude());
        return true;
    }
    return super.onTrackballEvent(event);
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) QuadPoint(net.osmand.data.QuadPoint)

Example 9 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class DownloadTilesDialog method openDialog.

public void openDialog() {
    BaseMapLayer mainLayer = mapView.getMainLayer();
    if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
        Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
    }
    final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
    if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
        Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
        return;
    }
    final RotatedTileBox rb = mapView.getCurrentRotatedTileBox();
    final int max = mapSource.getMaximumZoomSupported();
    // get narrow zoom
    final int zoom = rb.getZoom();
    // calculate pixel rectangle
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.download_tiles, null);
    // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MinZoom)).setText(zoom + "");
    // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MaxZoom)).setText(max + "");
    final SeekBar seekBar = (SeekBar) view.findViewById(R.id.ZoomToDownload);
    seekBar.setMax(max - zoom);
    seekBar.setProgress((max - zoom) / 2);
    final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
    final String template = ctx.getString(R.string.tiles_to_download_estimated_size);
    updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, seekBar.getProgress());
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            run(zoom, seekBar.getProgress(), rb.getLatLonBounds(), mapSource);
        }
    });
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setView(view);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) TextView(android.widget.TextView)

Example 10 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class TransportStopsLayer method initLayer.

@SuppressWarnings("deprecation")
@Override
public void initLayer(final OsmandMapTileView view) {
    backgroundIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bg);
    backgroundIconHalfWidth = backgroundIcon.getWidth() / 2;
    backgroundIconHalfHeight = backgroundIcon.getWidth() / 2;
    this.view = view;
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
    wmgr.getDefaultDisplay().getMetrics(dm);
    paintIcon = new Paint();
    paintWhiteIcon = new Paint();
    paintWhiteIcon.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, R.color.primary_text_dark), PorterDuff.Mode.SRC_IN));
    path = new Path();
    stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
    stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small);
    attrs = new RenderingLineAttributes("transport_route");
    attrs.defaultWidth = (int) (6 * view.getDensity());
    data = new OsmandMapLayer.MapLayerData<List<TransportStop>>() {

        {
            ZOOM_THRESHOLD = 0;
        }

        @Override
        public boolean isInterrupted() {
            return super.isInterrupted();
        }

        @Override
        public void layerOnPostExecute() {
            view.refreshMap();
        }

        @Override
        protected List<TransportStop> calculateResult(RotatedTileBox tileBox) {
            QuadRect latLonBounds = tileBox.getLatLonBounds();
            if (latLonBounds == null) {
                return new ArrayList<>();
            }
            List<TransportStop> res = view.getApplication().getResourceManager().searchTransportSync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, new ResultMatcher<TransportStop>() {

                @Override
                public boolean publish(TransportStop object) {
                    return true;
                }

                @Override
                public boolean isCancelled() {
                    return isInterrupted();
                }
            });
            Collections.sort(res, new Comparator<TransportStop>() {

                @Override
                public int compare(TransportStop lhs, TransportStop rhs) {
                    return lhs.getId() < rhs.getId() ? -1 : (lhs.getId().longValue() == rhs.getId().longValue() ? 0 : 1);
                }
            });
            return res;
        }
    };
}
Also used : Path(android.graphics.Path) RotatedTileBox(net.osmand.data.RotatedTileBox) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) ResultMatcher(net.osmand.ResultMatcher) DisplayMetrics(android.util.DisplayMetrics) QuadRect(net.osmand.data.QuadRect) WindowManager(android.view.WindowManager) Comparator(java.util.Comparator) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransportStop(net.osmand.data.TransportStop)

Aggregations

RotatedTileBox (net.osmand.data.RotatedTileBox)48 LatLon (net.osmand.data.LatLon)20 QuadPoint (net.osmand.data.QuadPoint)15 Paint (android.graphics.Paint)11 QuadRect (net.osmand.data.QuadRect)8 SuppressLint (android.annotation.SuppressLint)7 View (android.view.View)6 ImageView (android.widget.ImageView)5 ArrayList (java.util.ArrayList)4 Location (net.osmand.Location)4 ITileSource (net.osmand.map.ITileSource)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 PointF (android.graphics.PointF)3 TextView (android.widget.TextView)3 List (java.util.List)3 QuadPointDouble (net.osmand.data.QuadPointDouble)3 WptPt (net.osmand.plus.GPXUtilities.WptPt)3 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2