Search in sources :

Example 1 with MapTileLayer

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

the class MapLayers method createLayers.

public void createLayers(@NonNull OsmandMapTileView mapView) {
    // first create to make accessible
    mapTextLayer = new MapTextLayer(app);
    // 5.95 all labels
    mapView.addLayer(mapTextLayer, 5.95f);
    // 8. context menu layer
    contextMenuLayer = new ContextMenuLayer(app);
    mapView.addLayer(contextMenuLayer, 8);
    // mapView.addLayer(underlayLayer, -0.5f);
    mapTileLayer = new MapTileLayer(app, true);
    mapView.addLayer(mapTileLayer, 0.05f);
    mapView.setMainLayer(mapTileLayer);
    // 0.5 layer
    mapVectorLayer = new MapVectorLayer(app);
    mapView.addLayer(mapVectorLayer, 0.0f);
    downloadedRegionsLayer = new DownloadedRegionsLayer(app);
    mapView.addLayer(downloadedRegionsLayer, 0.5f);
    // 0.9 gpx layer
    gpxLayer = new GPXLayer(app);
    mapView.addLayer(gpxLayer, 0.9f);
    // 1. route layer
    routeLayer = new RouteLayer(app);
    mapView.addLayer(routeLayer, 1);
    // 1.5 preview route line layer
    previewRouteLineLayer = new PreviewRouteLineLayer(app);
    mapView.addLayer(previewRouteLineLayer, 1.5f);
    // 2. osm bugs layer
    // 3. poi layer
    poiMapLayer = new POIMapLayer(app);
    mapView.addLayer(poiMapLayer, 3);
    // 4. favorites layer
    mFavouritesLayer = new FavouritesLayer(app);
    mapView.addLayer(mFavouritesLayer, 4);
    // 4.6 measurement tool layer
    measurementToolLayer = new MeasurementToolLayer(app);
    mapView.addLayer(measurementToolLayer, 4.6f);
    // 5. transport layer
    transportStopsLayer = new TransportStopsLayer(app);
    mapView.addLayer(transportStopsLayer, 5);
    // 5.95 all text labels
    // 6. point location layer
    locationLayer = new PointLocationLayer(app);
    mapView.addLayer(locationLayer, 6);
    // 7. point navigation layer
    navigationLayer = new PointNavigationLayer(app);
    mapView.addLayer(navigationLayer, 7);
    // 7.3 map markers layer
    mapMarkersLayer = new MapMarkersLayer(app);
    mapView.addLayer(mapMarkersLayer, 7.3f);
    // 7.5 Impassible roads
    impassableRoadsLayer = new ImpassableRoadsLayer(app);
    mapView.addLayer(impassableRoadsLayer, 7.5f);
    // 7.8 radius ruler control layer
    radiusRulerControlLayer = new RadiusRulerControlLayer(app);
    mapView.addLayer(radiusRulerControlLayer, 7.8f);
    // 7.9 ruler by tap control layer
    distanceRulerControlLayer = new DistanceRulerControlLayer(app);
    mapView.addLayer(distanceRulerControlLayer, 7.9f);
    // 8. context menu layer
    // 9. map info layer
    mapInfoLayer = new MapInfoLayer(app, routeLayer);
    mapView.addLayer(mapInfoLayer, 9);
    // 11. route info layer
    mapControlsLayer = new MapControlsLayer(app);
    mapView.addLayer(mapControlsLayer, 11);
    // 12. quick actions layer
    mapQuickActionLayer = new MapQuickActionLayer(app);
    mapView.addLayer(mapQuickActionLayer, 12);
    contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
    transparencyListener = change -> app.runInUIThread(() -> {
        mapTileLayer.setAlpha(change);
        mapVectorLayer.setAlpha(change);
        mapView.refreshMap();
    });
    app.getSettings().MAP_TRANSPARENCY.addListener(transparencyListener);
    createAdditionalLayers();
}
Also used : MapControlsLayer(net.osmand.plus.views.layers.MapControlsLayer) PointLocationLayer(net.osmand.plus.views.layers.PointLocationLayer) MapMarkersLayer(net.osmand.plus.views.layers.MapMarkersLayer) POIMapLayer(net.osmand.plus.views.layers.POIMapLayer) MeasurementToolLayer(net.osmand.plus.measurementtool.MeasurementToolLayer) ImpassableRoadsLayer(net.osmand.plus.views.layers.ImpassableRoadsLayer) ContextMenuLayer(net.osmand.plus.views.layers.ContextMenuLayer) MapVectorLayer(net.osmand.plus.views.layers.MapVectorLayer) RouteLayer(net.osmand.plus.views.layers.RouteLayer) MapQuickActionLayer(net.osmand.plus.views.layers.MapQuickActionLayer) GPXLayer(net.osmand.plus.views.layers.GPXLayer) FavouritesLayer(net.osmand.plus.views.layers.FavouritesLayer) PointNavigationLayer(net.osmand.plus.views.layers.PointNavigationLayer) MapTextLayer(net.osmand.plus.views.layers.MapTextLayer) DownloadedRegionsLayer(net.osmand.plus.views.layers.DownloadedRegionsLayer) RadiusRulerControlLayer(net.osmand.plus.views.layers.RadiusRulerControlLayer) DistanceRulerControlLayer(net.osmand.plus.views.layers.DistanceRulerControlLayer) MapTileLayer(net.osmand.plus.views.layers.MapTileLayer) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer) PreviewRouteLineLayer(net.osmand.plus.views.layers.PreviewRouteLineLayer) TransportStopsLayer(net.osmand.plus.views.layers.TransportStopsLayer)

Example 2 with MapTileLayer

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

the class RasterMapMenu method createLayersItems.

private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
    final OsmandApplication app = mapActivity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final OsmandRasterMapsPlugin plugin = OsmandPlugin.getPlugin(OsmandRasterMapsPlugin.class);
    assert plugin != null;
    final CommonPreference<Integer> mapTransparencyPreference;
    final CommonPreference<String> mapTypePreference;
    final CommonPreference<String> exMapTypePreference;
    final LayerTransparencySeekbarMode currentMode = type == RasterMapType.OVERLAY ? OVERLAY : UNDERLAY;
    @StringRes final int mapTypeString;
    @StringRes final int mapTypeStringTransparency;
    if (type == RasterMapType.OVERLAY) {
        mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
        mapTypePreference = settings.MAP_OVERLAY;
        exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
        mapTypeString = R.string.map_overlay;
        mapTypeStringTransparency = R.string.overlay_transparency;
    } else if (type == RasterMapType.UNDERLAY) {
        mapTransparencyPreference = settings.MAP_TRANSPARENCY;
        mapTypePreference = settings.MAP_UNDERLAY;
        exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
        mapTypeString = R.string.map_underlay;
        mapTypeStringTransparency = R.string.map_transparency;
    } else {
        throw new RuntimeException("Unexpected raster map type");
    }
    CommonPreference<Boolean> hidePolygonsPref = settings.getCustomRenderBooleanProperty("noPolygons");
    CommonPreference<Boolean> hideWaterPolygonsPref = settings.getCustomRenderBooleanProperty("hideWaterPolygons");
    String mapTypeDescr = mapTypePreference.get();
    if (mapTypeDescr != null && mapTypeDescr.contains(".sqlitedb")) {
        mapTypeDescr = mapTypeDescr.replaceFirst(".sqlitedb", "");
    }
    final boolean mapSelected = mapTypeDescr != null;
    final int toggleActionStringId = mapSelected ? R.string.shared_string_on : R.string.shared_string_off;
    final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {

        @Override
        public void onMapSelected(boolean canceled) {
            mapActivity.getDashboard().refreshContent(true);
            boolean refreshToHidePolygons = type == RasterMapType.UNDERLAY;
            if (refreshToHidePolygons) {
                mapActivity.refreshMapComplete();
            }
        }
    };
    final MapLayers mapLayers = mapActivity.getMapLayers();
    ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
            if (itemId == mapTypeString) {
                if (mapSelected) {
                    plugin.selectMapOverlayLayer(mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
                }
                return false;
            }
            return super.onRowItemClick(adapter, view, itemId, pos);
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
            if (itemId == toggleActionStringId) {
                app.runInUIThread(() -> {
                    plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
                    mapActivity.refreshMapComplete();
                });
            } else if (itemId == R.string.show_polygons) {
                hidePolygonsPref.set(!isChecked);
                hideWaterPolygonsPref.set(!isChecked);
                mapActivity.refreshMapComplete();
            } else if (itemId == R.string.show_transparency_seekbar) {
                updateTransparencyBarVisibility(isChecked);
            } else if (itemId == R.string.show_parameter_seekbar) {
                if (isChecked) {
                    settings.SHOW_MAP_LAYER_PARAMETER.set(true);
                    MapTileLayer overlayLayer = plugin.getOverlayLayer();
                    if (overlayLayer != null) {
                        mapLayers.getMapControlsLayer().showParameterBar(overlayLayer);
                    }
                } else {
                    settings.SHOW_MAP_LAYER_PARAMETER.set(false);
                    mapLayers.getMapControlsLayer().hideParameterBar();
                    updateTransparencyBarVisibility(isSeekbarVisible(app, RasterMapType.OVERLAY));
                }
            }
            return false;
        }

        private void updateTransparencyBarVisibility(boolean visible) {
            if (visible) {
                settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(currentMode);
                mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
            } else // if(settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get() == currentMode)
            {
                settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(LayerTransparencySeekbarMode.OFF);
                mapLayers.getMapControlsLayer().hideTransparencyBar();
            }
        }
    };
    mapTypeDescr = mapSelected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
    contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(mapSelected).createItem());
    if (mapSelected) {
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
        ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {

            @Override
            public boolean onIntegerValueChangedListener(int newValue) {
                mapTransparencyPreference.set(newValue);
                mapActivity.getMapLayers().getMapControlsLayer().updateTransparencySliderValue();
                mapActivity.refreshMap();
                return false;
            }
        };
        // android:max="255" in layout is expected
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
        if (type == RasterMapType.UNDERLAY) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_polygons, mapActivity).hideDivider(true).setListener(l).setSelected(!hidePolygonsPref.get()).createItem());
        }
        Boolean transparencySwitchState = isSeekbarVisible(app, type);
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
        ITileSource oveplayMap = plugin.getOverlayLayer().getMap();
        if (type == RasterMapType.OVERLAY && oveplayMap != null && oveplayMap.getParamType() != ParameterType.UNDEFINED) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_parameter_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(settings.SHOW_MAP_LAYER_PARAMETER.get()).createItem());
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) StringRes(androidx.annotation.StringRes) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) ContextMenuItem(net.osmand.plus.ContextMenuItem) LayerTransparencySeekbarMode(net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode) View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OnMapSelectedCallback(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) MapTileLayer(net.osmand.plus.views.layers.MapTileLayer) ITileSource(net.osmand.map.ITileSource) ArrayAdapter(android.widget.ArrayAdapter) MapLayers(net.osmand.plus.views.MapLayers)

Example 3 with MapTileLayer

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

the class OsmandRasterMapsPlugin method createLayers.

private void createLayers(@NonNull Context context) {
    OsmandMapTileView mapView = app.getOsmandMap().getMapView();
    if (underlayLayer != null) {
        mapView.removeLayer(underlayLayer);
    }
    if (overlayLayer != null) {
        mapView.removeLayer(overlayLayer);
    }
    underlayLayer = new MapTileLayer(context, false);
    overlayLayer = new MapTileLayer(context, false);
    overlayLayerListener = change -> app.runInUIThread(() -> overlayLayer.setAlpha(change));
    settings.MAP_OVERLAY_TRANSPARENCY.addListener(overlayLayerListener);
}
Also used : MapTileLayer(net.osmand.plus.views.layers.MapTileLayer) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 4 with MapTileLayer

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

the class OsmandRasterMapsPlugin method toggleUnderlayState.

public void toggleUnderlayState(@NonNull MapActivity mapActivity, @NonNull RasterMapType type, @Nullable OnMapSelectedCallback callback) {
    OsmandMapTileView mapView = mapActivity.getMapView();
    CommonPreference<String> mapTypePreference;
    CommonPreference<String> exMapTypePreference;
    // boolean isMapSelected;
    MapTileLayer layer;
    if (type == RasterMapType.OVERLAY) {
        mapTypePreference = settings.MAP_OVERLAY;
        exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
        layer = overlayLayer;
    } else {
        // Underlay expected
        mapTypePreference = settings.MAP_UNDERLAY;
        exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
        layer = underlayLayer;
    }
    MapLayers mapLayers = mapActivity.getMapLayers();
    ITileSource map = layer.getMap();
    final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == OsmandRasterMapsPlugin.RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
    if (map != null) {
        mapTypePreference.set(null);
        if (callback != null) {
            callback.onMapSelected(false);
        }
        updateMapLayers(mapActivity, mapActivity, null);
        // hide seekbar
        if (currentMapTypeSeekbarMode == settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get()) {
            settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(LayerTransparencySeekbarMode.UNDEFINED);
            mapLayers.getMapControlsLayer().hideTransparencyBar();
        }
    } else {
        settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(currentMapTypeSeekbarMode);
        selectMapOverlayLayer(mapTypePreference, exMapTypePreference, false, mapActivity, callback);
    }
}
Also used : MapTileLayer(net.osmand.plus.views.layers.MapTileLayer) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) MapLayers(net.osmand.plus.views.MapLayers)

Example 5 with MapTileLayer

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

the class DownloadTilesFragment method shouldShowDialog.

public static boolean shouldShowDialog(@NonNull OsmandApplication app) {
    BaseMapLayer mainLayer = app.getOsmandMap().getMapView().getMainLayer();
    MapTileLayer mapTileLayer = mainLayer instanceof MapTileLayer ? ((MapTileLayer) mainLayer) : null;
    ITileSource tileSource = app.getSettings().getMapTileSource(false);
    return mapTileLayer != null && mapTileLayer.isVisible() && tileSource.couldBeDownloadedFromInternet();
}
Also used : BaseMapLayer(net.osmand.plus.views.layers.base.BaseMapLayer) MapTileLayer(net.osmand.plus.views.layers.MapTileLayer) ITileSource(net.osmand.map.ITileSource)

Aggregations

MapTileLayer (net.osmand.plus.views.layers.MapTileLayer)5 ITileSource (net.osmand.map.ITileSource)4 View (android.view.View)2 ArrayAdapter (android.widget.ArrayAdapter)2 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)2 ContextMenuItem (net.osmand.plus.ContextMenuItem)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)2 MapLayers (net.osmand.plus.views.MapLayers)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Drawable (android.graphics.drawable.Drawable)1 AsyncTask (android.os.AsyncTask)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 StringRes (androidx.annotation.StringRes)1 AlertDialog (androidx.appcompat.app.AlertDialog)1