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());
}
}
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();
}
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();
}
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);
}
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);
}
Aggregations