Search in sources :

Example 1 with MapTileLayer

use of net.osmand.plus.views.MapTileLayer in project Osmand by osmandapp.

the class OsmandRasterMapsPlugin method registerMapContextMenuActions.

@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, Object selectedObj) {
    final OsmandMapTileView mapView = mapActivity.getMapView();
    if (mapView.getMainLayer() instanceof MapTileLayer) {
        ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
                if (resId == R.string.context_menu_item_update_map) {
                    mapActivity.getMapActions().reloadTile(mapView.getZoom(), latitude, longitude);
                } else if (resId == R.string.shared_string_download_map) {
                    DownloadTilesDialog dlg = new DownloadTilesDialog(mapActivity, (OsmandApplication) mapActivity.getApplication(), mapView);
                    dlg.openDialog();
                }
                return true;
            }
        };
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_update_map, mapActivity).setIcon(R.drawable.ic_action_refresh_dark).setOrder(UPDATE_MAP_ITEM_ORDER).setListener(listener).createItem());
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_download_map, mapActivity).setIcon(R.drawable.ic_action_import).setOrder(DOWNLOAD_MAP_ITEM_ORDER).setListener(listener).createItem());
    }
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) DownloadTilesDialog(net.osmand.plus.activities.DownloadTilesDialog) OsmandApplication(net.osmand.plus.OsmandApplication) MapTileLayer(net.osmand.plus.views.MapTileLayer) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with MapTileLayer

use of net.osmand.plus.views.MapTileLayer 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 3 with MapTileLayer

use of net.osmand.plus.views.MapTileLayer 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 4 with MapTileLayer

use of net.osmand.plus.views.MapTileLayer in project Osmand by osmandapp.

the class MapActivityLayers method createLayers.

public void createLayers(final OsmandMapTileView mapView) {
    OsmandApplication app = getApplication();
    RoutingHelper routingHelper = app.getRoutingHelper();
    // first create to make accessible
    mapTextLayer = new MapTextLayer();
    // 5.95 all labels
    mapView.addLayer(mapTextLayer, 5.95f);
    // 8. context menu layer
    contextMenuLayer = new ContextMenuLayer(activity);
    mapView.addLayer(contextMenuLayer, 8);
    // mapView.addLayer(underlayLayer, -0.5f);
    mapTileLayer = new MapTileLayer(true);
    mapView.addLayer(mapTileLayer, 0.0f);
    mapView.setMainLayer(mapTileLayer);
    // 0.5 layer
    mapVectorLayer = new MapVectorLayer(mapTileLayer, false);
    mapView.addLayer(mapVectorLayer, 0.5f);
    downloadedRegionsLayer = new DownloadedRegionsLayer();
    mapView.addLayer(downloadedRegionsLayer, 0.5f);
    // 0.9 gpx layer
    gpxLayer = new GPXLayer();
    mapView.addLayer(gpxLayer, 0.9f);
    // 1. route layer
    routeLayer = new RouteLayer(routingHelper);
    mapView.addLayer(routeLayer, 1);
    // 2. osm bugs layer
    // 3. poi layer
    poiMapLayer = new POIMapLayer(activity);
    mapView.addLayer(poiMapLayer, 3);
    // 4. favorites layer
    mFavouritesLayer = new FavouritesLayer();
    mapView.addLayer(mFavouritesLayer, 4);
    // 4.6 measurement tool layer
    measurementToolLayer = new MeasurementToolLayer();
    mapView.addLayer(measurementToolLayer, 4.6f);
    // 5. transport layer
    transportStopsLayer = new TransportStopsLayer(activity);
    mapView.addLayer(transportStopsLayer, 5);
    // 5.95 all text labels
    // 6. point location layer
    locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
    mapView.addLayer(locationLayer, 6);
    // 7. point navigation layer
    navigationLayer = new PointNavigationLayer(activity);
    mapView.addLayer(navigationLayer, 7);
    // 7.3 map markers layer
    mapMarkersLayer = new MapMarkersLayer(activity);
    mapView.addLayer(mapMarkersLayer, 7.3f);
    // 7.5 Impassible roads
    impassableRoadsLayer = new ImpassableRoadsLayer(activity);
    mapView.addLayer(impassableRoadsLayer, 7.5f);
    // 7.8 ruler control layer
    rulerControlLayer = new RulerControlLayer(activity);
    mapView.addLayer(rulerControlLayer, 7.8f);
    // 8. context menu layer
    // 9. map info layer
    mapInfoLayer = new MapInfoLayer(activity, routeLayer);
    mapView.addLayer(mapInfoLayer, 9);
    // 11. route info layer
    mapControlsLayer = new MapControlsLayer(activity);
    mapView.addLayer(mapControlsLayer, 11);
    // 12. quick actions layer
    mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer);
    mapView.addLayer(mapQuickActionLayer, 12);
    contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
    mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer);
    transparencyListener = new StateChangedListener<Integer>() {

        @Override
        public void stateChanged(Integer change) {
            mapTileLayer.setAlpha(change);
            mapVectorLayer.setAlpha(change);
            mapView.refreshMap();
        }
    };
    app.getSettings().MAP_TRANSPARENCY.addListener(transparencyListener);
    OsmandPlugin.createLayers(mapView, activity);
    app.getAppCustomization().createLayers(mapView, activity);
    app.getAidlApi().registerMapLayers(activity);
}
Also used : MapControlsLayer(net.osmand.plus.views.MapControlsLayer) PointLocationLayer(net.osmand.plus.views.PointLocationLayer) MapMarkersLayer(net.osmand.plus.views.MapMarkersLayer) OsmandApplication(net.osmand.plus.OsmandApplication) POIMapLayer(net.osmand.plus.views.POIMapLayer) MeasurementToolLayer(net.osmand.plus.measurementtool.MeasurementToolLayer) ImpassableRoadsLayer(net.osmand.plus.views.ImpassableRoadsLayer) ContextMenuLayer(net.osmand.plus.views.ContextMenuLayer) RoutingHelper(net.osmand.plus.routing.RoutingHelper) MapVectorLayer(net.osmand.plus.render.MapVectorLayer) RouteLayer(net.osmand.plus.views.RouteLayer) MapQuickActionLayer(net.osmand.plus.views.MapQuickActionLayer) GPXLayer(net.osmand.plus.views.GPXLayer) FavouritesLayer(net.osmand.plus.views.FavouritesLayer) PointNavigationLayer(net.osmand.plus.views.PointNavigationLayer) RulerControlLayer(net.osmand.plus.views.RulerControlLayer) MapTextLayer(net.osmand.plus.views.MapTextLayer) DownloadedRegionsLayer(net.osmand.plus.views.DownloadedRegionsLayer) MapTileLayer(net.osmand.plus.views.MapTileLayer) MapInfoLayer(net.osmand.plus.views.MapInfoLayer) TransportStopsLayer(net.osmand.plus.views.TransportStopsLayer)

Example 5 with MapTileLayer

use of net.osmand.plus.views.MapTileLayer in project Osmand by osmandapp.

the class OsmandRasterMapsPlugin method createLayers.

private void createLayers() {
    underlayLayer = new MapTileLayer(false);
    // mapView.addLayer(underlayLayer, -0.5f);
    overlayLayer = new MapTileLayer(false);
    overlayLayerListener = new StateChangedListener<Integer>() {

        @Override
        public void stateChanged(Integer change) {
            overlayLayer.setAlpha(change);
        }
    };
    // mapView.addLayer(overlayLayer, 0.7f);
    settings.MAP_OVERLAY_TRANSPARENCY.addListener(overlayLayerListener);
}
Also used : MapTileLayer(net.osmand.plus.views.MapTileLayer)

Aggregations

MapTileLayer (net.osmand.plus.views.MapTileLayer)5 OsmandApplication (net.osmand.plus.OsmandApplication)3 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 RotatedTileBox (net.osmand.data.RotatedTileBox)2 ITileSource (net.osmand.map.ITileSource)2 BaseMapLayer (net.osmand.plus.views.BaseMapLayer)2 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 QuadRect (net.osmand.data.QuadRect)1 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)1 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)1 DownloadTilesDialog (net.osmand.plus.activities.DownloadTilesDialog)1 MeasurementToolLayer (net.osmand.plus.measurementtool.MeasurementToolLayer)1 MapVectorLayer (net.osmand.plus.render.MapVectorLayer)1 GPXRouteParamsBuilder (net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder)1