Add overlay to map

This commit is contained in:
Victor Shcherb 2011-05-30 00:07:06 +02:00
parent f85fa4118d
commit 38a536457a
8 changed files with 125 additions and 34 deletions

View file

@ -12,7 +12,6 @@ public class ToDoConstants {
// Map Refactoring
// Remove notification from OsmAndMapTileView (?)
// Add transparency filter to bitmap layers
// Allow to create over/under map layers
// Allow to config transparency filter
// Yandex Traffic make downloadable

View file

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="layer_overlay">Карта покрытия...</string>
<string name="default_none">Нету</string>
<string name="map_overlay">Карта покрытия</string>
<string name="map_overlay_descr">Выберите слой для покрытия основной карты</string>
<string name="map_vector_data">Векторные карты</string>
<string name="map_vector_data_descr">Использовать загруженные векторные карты</string>
<string name="tile_source_already_installed">Карта уже установлена, настройки будут обновлены</string>

View file

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="layer_overlay">Overlay map...</string>
<string name="default_none">None</string>
<string name="map_overlay">Overlay map</string>
<string name="map_overlay_descr">Choose overlay map</string>
<string name="map_vector_data">Vector maps</string>
<string name="map_vector_data_descr">Use downloaded vector maps</string>
<string name="tile_source_already_installed">Map is already installed, settings will be updated</string>

View file

@ -11,6 +11,7 @@
android:key="use_english_names"></CheckBoxPreference>
<ListPreference android:key="renderer" android:title="@string/renderers" android:summary="@string/renderers_descr"></ListPreference>
<ListPreference android:key="daynight_mode" android:title="@string/daynight" android:summary="@string/daynight_descr"></ListPreference>
<ListPreference android:title="@string/map_overlay" android:summary="@string/map_overlay_descr" android:key="map_overlay"></ListPreference>
<CheckBoxPreference android:summary="@string/continuous_rendering_descr" android:title="@string/continuous_rendering"
android:key="use_step_by_step_rendering" />
<CheckBoxPreference android:key="use_high_res_maps" android:title="@string/use_high_res_maps" android:summary="@string/use_high_res_maps_descr"></CheckBoxPreference>

View file

@ -69,7 +69,6 @@ public class OsmandSettings {
private List<TileSourceTemplate> internetAvailableSourceTemplates = null;
// TODO make all layers profile preferenced????
// TODO profile preferences for map is using vector map???
private OsmandSettings(OsmandApplication ctx){
this.ctx = ctx;
globalPreferences = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
@ -514,16 +513,12 @@ public class OsmandSettings {
false, true);
// this value string is synchronized with settings_pref.xml preference name
public static final String MAP_TILE_SOURCES = "map_tile_sources"; //$NON-NLS-1$
public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay",
null, true);
public boolean setMapTileSource(String tileSource){
return globalPreferences.edit().putString(MAP_TILE_SOURCES, tileSource).commit();
}
public String getMapTileSourceName(){
return globalPreferences.getString(MAP_TILE_SOURCES, TileSourceManager.getMapnikSource().getName());
}
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> MAP_TILE_SOURCES = new StringPreference("map_tile_sources",
TileSourceManager.getMapnikSource().getName(), true);
public List<TileSourceTemplate> getInternetAvailableSourceTemplates(){
if(internetAvailableSourceTemplates == null && isInternetConnectionAvailable()){
@ -533,7 +528,7 @@ public class OsmandSettings {
}
public ITileSource getMapTileSource() {
String tileName = globalPreferences.getString(MAP_TILE_SOURCES, null);
String tileName = MAP_TILE_SOURCES.get();
if (tileName != null) {
ITileSource ts = getTileSourceByName(tileName);
if(ts != null){
@ -543,7 +538,11 @@ public class OsmandSettings {
return TileSourceManager.getMapnikSource();
}
private ITileSource getTileSourceByName(String tileName) {
public ITileSource getTileSourceByName(String tileName) {
if(tileName == null || tileName.length() == 0){
return null;
}
List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
File tPath = extendOsmandPath(ResourceManager.TILES_PATH);
File dir = new File(tPath, tileName);

View file

@ -15,8 +15,6 @@ import net.osmand.GPXUtilities.GPXFileResult;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.AmenityType;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.osm.LatLon;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.PoiFilter;
@ -61,6 +59,7 @@ public class MapActivityLayers {
// the order of layer should be preserved ! when you are inserting new layer
private MapTileLayer mapTileLayer;
private MapVectorLayer mapVectorLayer;
private MapTileLayer overlayLayer;
private GPXLayer gpxLayer;
private RouteLayer routeLayer;
private YandexTrafficLayer trafficLayer;
@ -97,9 +96,12 @@ public class MapActivityLayers {
mapVectorLayer = new MapVectorLayer(mapTileLayer);
mapView.addLayer(mapVectorLayer, 0.5f);
// 0.6 gpx layer
overlayLayer = new MapTileLayer();
// mapView.addLayer(overlayLayer, 0.7f);
// 0.9 gpx layer
gpxLayer = new GPXLayer();
mapView.addLayer(gpxLayer, 0.6f);
mapView.addLayer(gpxLayer, 0.9f);
// 1. route layer
routeLayer = new RouteLayer(routingHelper);
@ -109,7 +111,6 @@ public class MapActivityLayers {
trafficLayer = new YandexTrafficLayer();
mapView.addLayer(trafficLayer, 1.5f);
// 2. osm bugs layer
osmBugsLayer = new OsmBugsLayer(activity);
// 3. poi layer
@ -182,6 +183,9 @@ public class MapActivityLayers {
public void updateMapSource(OsmandMapTileView mapView){
OsmandSettings settings = getApplication().getSettings();
boolean showTiles = !settings.MAP_VECTOR_DATA.get();
// update overlay layer
updateOverlay(mapView, settings);
ITileSource source = showTiles ? settings.getMapTileSource() : null;
if (showTiles == mapTileLayer.isVisible() && Algoritms.objectEquals(mapTileLayer.getMap(), source)) {
return;
@ -209,6 +213,22 @@ public class MapActivityLayers {
} else {
mapView.setMainLayer(mapTileLayer);
}
}
private void updateOverlay(OsmandMapTileView mapView, OsmandSettings settings) {
ITileSource overlay = settings.getTileSourceByName(settings.MAP_OVERLAY.get());
if(!Algoritms.objectEquals(overlay, overlayLayer.getMap())){
if(overlay == null){
mapView.removeLayer(overlayLayer);
} else {
mapView.addLayer(overlayLayer, 0.7f);
}
overlayLayer.setMap(overlay);
mapView.refreshMap();
}
}
public void openLayerSelectionDialog(final OsmandMapTileView mapView){
@ -220,6 +240,7 @@ public class MapActivityLayers {
layersList.add(getString(R.string.layer_osm_bugs));
layersList.add(getString(R.string.layer_favorites));
layersList.add(getString(R.string.layer_gpx_layer));
layersList.add(getString(R.string.layer_overlay));
final int routeInfoInd = routeInfoLayer.couldBeVisible() ? layersList.size() : -1;
if(routeInfoLayer.couldBeVisible()){
layersList.add(getString(R.string.layer_route));
@ -238,6 +259,7 @@ public class MapActivityLayers {
selected[3] = settings.SHOW_OSM_BUGS.get();
selected[4] = settings.SHOW_FAVORITES.get();
selected[5] = gpxLayer.isVisible();
selected[6] = overlayLayer.getMap() != null;
selected[trafficInd] = trafficLayer.isVisible();
if(routeInfoInd != -1){
selected[routeInfoInd] = routeInfoLayer.isUserDefinedVisible();
@ -273,6 +295,14 @@ public class MapActivityLayers {
dialog.dismiss();
useGPXFileLayer(false, null, mapView);
}
} else if(item == 6){
if(overlayLayer.getMap() != null){
settings.MAP_OVERLAY.set(null);
updateMapSource(mapView);
} else {
dialog.dismiss();
selectMapOverlayLayer(mapView);
}
} else if(item == routeInfoInd){
routeInfoLayer.setVisible(isChecked);
} else if(item == transportRouteInfoInd){
@ -451,7 +481,7 @@ public class MapActivityLayers {
}
});
} else {
settings.setMapTileSource(keys.get(which - 1));
settings.MAP_TILE_SOURCES.set(keys.get(which - 1));
settings.MAP_VECTOR_DATA.set(false);
updateMapSource(mapView);
}
@ -463,6 +493,39 @@ public class MapActivityLayers {
}
private void selectMapOverlayLayer(final OsmandMapTileView mapView){
final OsmandSettings settings = getApplication().getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
final ArrayList<String> keys = new ArrayList<String>(entriesMap.keySet());
Builder builder = new AlertDialog.Builder(activity);
final String[] items = new String[entriesMap.size() + 1];
int i = 0;
for(String it : entriesMap.values()){
items[i++] = it;
}
items[i] = getString(R.string.more_external_layer);
builder.setItems(items, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == items.length - 1){
SettingsActivity.installMapLayers(activity, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
openLayerSelectionDialog(mapView);
}
});
} else {
settings.MAP_OVERLAY.set(keys.get(which));
updateMapSource(mapView);
}
}
});
builder.show();
}
private String getString(int resId) {
return activity.getString(resId);

View file

@ -55,6 +55,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private EditTextPreference applicationDir;
private ListPreference tileSourcePreference;
private ListPreference overlayPreference;
private CheckBoxPreference routeServiceEnabled;
private BroadcastReceiver broadcastReceiver;
@ -249,8 +250,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
registerListPreference(osmandSettings.RENDERER, screen, entries, entries);
tileSourcePreference = (ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
tileSourcePreference = (ListPreference) screen.findPreference(osmandSettings.MAP_TILE_SOURCES.getId());
tileSourcePreference.setOnPreferenceChangeListener(this);
overlayPreference = (ListPreference) screen.findPreference(osmandSettings.MAP_OVERLAY.getId());
overlayPreference.setOnPreferenceChangeListener(this);
reloadIndexes =(Preference) screen.findPreference(OsmandSettings.RELOAD_INDEXES);
@ -331,10 +334,32 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
private void updateTileSourceSummary() {
fillTileSourcesToPreference(tileSourcePreference, osmandSettings.MAP_TILE_SOURCES.get(), false);
fillTileSourcesToPreference(overlayPreference, osmandSettings.MAP_OVERLAY.get(), true);
String mapName = " " + osmandSettings.MAP_TILE_SOURCES.get(); //$NON-NLS-1$
String summary = tileSourcePreference.getSummary().toString();
if (summary.lastIndexOf(':') != -1) {
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
}
tileSourcePreference.setSummary(summary + mapName);
}
private void fillTileSourcesToPreference(ListPreference tileSourcePreference, String value, boolean addNone) {
Map<String, String> entriesMap = osmandSettings.getTileSourceEntries();
String[] entries = new String[entriesMap.size() + 1];
String[] values = new String[entriesMap.size() + 1];
int add = addNone ? 1 : 0;
String[] entries = new String[entriesMap.size() + 1 + add];
String[] values = new String[entriesMap.size() + 1 + add];
int ki = 0;
if(addNone){
entries[ki] = getString(R.string.default_none);
values[ki] = "";
ki++;
}
if (value == null) {
value = "";
}
for(Map.Entry<String, String> es : entriesMap.entrySet()){
entries[ki] = es.getValue();
values[ki] = es.getKey();
@ -342,15 +367,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
entries[ki] = getString(R.string.more_external_layer);
values[ki] = MORE_VALUE;
String value = osmandSettings.getMapTileSourceName();
fill(tileSourcePreference, entries, values, value);
String mapName = " " + osmandSettings.getMapTileSourceName(); //$NON-NLS-1$
String summary = tileSourcePreference.getSummary().toString();
if (summary.lastIndexOf(':') != -1) {
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
}
tileSourcePreference.setSummary(summary + mapName);
}
private void fill(ListPreference component, String[] list, String[] values, String selected) {
@ -421,7 +438,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
}
}
} else if (preference == tileSourcePreference) {
} else if (preference == tileSourcePreference || preference == overlayPreference) {
if(MORE_VALUE.equals(newValue)){
SettingsActivity.installMapLayers(this, new DialogInterface.OnClickListener() {
@Override
@ -429,9 +446,14 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
updateTileSourceSummary();
}
});
} else {
osmandSettings.setMapTileSource((String) newValue);
} else if(preference == tileSourcePreference){
osmandSettings.MAP_TILE_SOURCES.set((String) newValue);
updateTileSourceSummary();
} else {
if(((String) newValue).length() == 0){
newValue = null;
}
osmandSettings.MAP_OVERLAY.set(((String) newValue));
}
}
return true;

View file

@ -1,7 +1,6 @@
package net.osmand.plus.views;
import net.osmand.map.ITileSource;
import net.osmand.osm.MapUtils;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ResourceManager;
import android.graphics.Bitmap;