use of net.osmand.plus.views.MapLayers in project Osmand by osmandapp.
the class ContextMenuScrollFragment method setupControlButtons.
protected void setupControlButtons(@NonNull View view) {
MapActivity mapActivity = requireMapActivity();
View zoomInButtonView = view.findViewById(R.id.map_zoom_in_button);
View zoomOutButtonView = view.findViewById(R.id.map_zoom_out_button);
View myLocButtonView = view.findViewById(R.id.map_my_location_button);
MapLayers mapLayers = mapActivity.getMapLayers();
OsmandMapTileView mapTileView = mapActivity.getMapView();
View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView);
MapControlsLayer mapControlsLayer = mapLayers.getMapControlsLayer();
mapControlsLayer.setupZoomInButton(zoomInButtonView, longClickListener, ZOOM_IN_BUTTON_ID);
mapControlsLayer.setupZoomOutButton(zoomOutButtonView, longClickListener, ZOOM_OUT_BUTTON_ID);
mapControlsLayer.setupBackToLocationButton(myLocButtonView, false, BACK_TO_LOC_BUTTON_ID);
setupMapRulerWidget(view, mapLayers);
}
use of net.osmand.plus.views.MapLayers in project Osmand by osmandapp.
the class MapActivity method updateApplicationModeSettings.
public void updateApplicationModeSettings() {
changeKeyguardFlags();
updateMapSettings();
app.getPoiFilters().loadSelectedPoiFilters();
getMapViewTrackingUtilities().appModeChanged();
OsmandMapTileView mapView = getMapView();
MapLayers mapLayers = getMapLayers();
if (mapLayers.getMapInfoLayer() != null) {
mapLayers.getMapInfoLayer().recreateControls();
}
if (mapLayers.getMapQuickActionLayer() != null) {
mapLayers.getMapQuickActionLayer().refreshLayer();
}
MapControlsLayer mapControlsLayer = mapLayers.getMapControlsLayer();
if (mapControlsLayer != null && (!mapControlsLayer.isMapControlsVisible() && !settings.MAP_EMPTY_STATE_ALLOWED.get())) {
showMapControls();
}
mapLayers.updateLayers(this);
mapActions.updateDrawerMenu();
updateNavigationBarColor();
mapView.setComplexZoom(mapView.getZoom(), mapView.getSettingsMapDensity());
app.getDaynightHelper().startSensorIfNeeded(change -> app.runInUIThread(() -> getMapView().refreshMap(true)));
getMapView().refreshMap(true);
applyScreenOrientation();
app.getAppCustomization().updateMapMargins(this);
dashboardOnMap.onApplicationModeSettingsUpdated();
}
use of net.osmand.plus.views.MapLayers 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());
}
}
}
use of net.osmand.plus.views.MapLayers 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);
}
}
use of net.osmand.plus.views.MapLayers in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method updateMapLayers.
public void updateMapLayers(@NonNull Context context, @Nullable MapActivity mapActivity, @Nullable CommonPreference<String> settingsToWarnAboutMap) {
if (overlayLayer == null) {
createLayers(context);
}
overlayLayer.setAlpha(settings.MAP_OVERLAY_TRANSPARENCY.get());
overlayLayer.updateParameter();
OsmandMapTileView mapView = app.getOsmandMap().getMapView();
if (isActive()) {
updateLayer(mapView, settings, overlayLayer, settings.MAP_OVERLAY, ZORDER_OVERLAY, settings.MAP_OVERLAY == settingsToWarnAboutMap);
} else {
mapView.removeLayer(overlayLayer);
overlayLayer.setMap(null);
}
if (isActive()) {
updateLayer(mapView, settings, underlayLayer, settings.MAP_UNDERLAY, ZORDER_UNDERLAY, settings.MAP_UNDERLAY == settingsToWarnAboutMap);
} else {
mapView.removeLayer(underlayLayer);
underlayLayer.setMap(null);
}
if (mapActivity != null) {
MapLayers layers = mapActivity.getMapLayers();
if (settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get() == LayerTransparencySeekbarMode.UNDERLAY && underlayLayer.getMap() != null || underlayLayer.getMapTileAdapter() != null) {
layers.getMapControlsLayer().showTransparencyBar(settings.MAP_TRANSPARENCY);
} else if (settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get() == LayerTransparencySeekbarMode.OVERLAY && overlayLayer.getMap() != null || overlayLayer.getMapTileAdapter() != null) {
if (settings.SHOW_MAP_LAYER_PARAMETER.get()) {
layers.getMapControlsLayer().showParameterBar(overlayLayer);
} else {
layers.getMapControlsLayer().showTransparencyBar(settings.MAP_OVERLAY_TRANSPARENCY);
}
} else {
layers.getMapControlsLayer().hideTransparencyBar();
}
}
app.getOsmandMap().getMapLayers().updateMapSource(mapView, settingsToWarnAboutMap);
}
Aggregations