implement layers
git-svn-id: https://osmand.googlecode.com/svn/trunk@383 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
e4129286b7
commit
ee2de0c5cb
5 changed files with 88 additions and 52 deletions
|
@ -11,7 +11,7 @@ public class ToDoConstants {
|
|||
// TODO ANDROID 0.3
|
||||
// Improvements
|
||||
// 1. Show layers (?) -
|
||||
// 0) map 1) transport (+) 2) Poi (choose filter) 3) osm bugs (+) 3) Favorites(+)
|
||||
// 0) map 1) transport (+) 2) Poi (choose filter) (+) 3) osm bugs (+) 3) Favorites(+)
|
||||
// 4) Route (gmaps) - 5) Transport route -
|
||||
// and remove from settings (+)
|
||||
// 1.4 show detailed route on the map with turns and show route information directly (like in gmaps)
|
||||
|
@ -19,6 +19,7 @@ public class ToDoConstants {
|
|||
// 2. Using NameFinder to search online -
|
||||
// 3. Show route info after route calc (+)
|
||||
// 4. show vehicle for calculating route (+)
|
||||
// 5. Add zorders list to OsmandMapView
|
||||
|
||||
// BUGS
|
||||
// ISSUE 21. (+, +, +)
|
||||
|
|
|
@ -46,6 +46,11 @@ public class OsmandSettings {
|
|||
public static final int CENTER_CONSTANT = 0;
|
||||
public static final int BOTTOM_CONSTANT = 1;
|
||||
|
||||
public static final Editor getWriteableEditor(Context ctx){
|
||||
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||
return prefs.edit();
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public static final String USE_INTERNET_TO_DOWNLOAD_TILES = "use_internet_to_download_tiles"; //$NON-NLS-1$
|
||||
public static final boolean USE_INTERNET_TO_DOWNLOAD_TILES_DEF = true;
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.text.MessageFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
|
@ -195,7 +196,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
routingHelper = RoutingHelper.getInstance(this);
|
||||
// 1. route layer
|
||||
routeLayer = new RouteLayer(routingHelper);
|
||||
mapView.addLayer(routeLayer);
|
||||
mapView.addLayer(routeLayer, 1);
|
||||
// 2. osm bugs layer
|
||||
osmBugsLayer = new OsmBugsLayer(this);
|
||||
// 3. poi layer
|
||||
|
@ -206,13 +207,13 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
transportStopsLayer = new TransportStopsLayer();
|
||||
// 6. point navigation layer
|
||||
navigationLayer = new PointNavigationLayer();
|
||||
mapView.addLayer(navigationLayer);
|
||||
mapView.addLayer(navigationLayer, 6);
|
||||
// 7. point location layer
|
||||
locationLayer = new PointLocationLayer();
|
||||
mapView.addLayer(locationLayer);
|
||||
mapView.addLayer(locationLayer, 7);
|
||||
// 8. map info layer
|
||||
mapInfoLayer = new MapInfoLayer(this, routeLayer);
|
||||
mapView.addLayer(mapInfoLayer);
|
||||
mapView.addLayer(mapInfoLayer, 8);
|
||||
|
||||
|
||||
savingTrackHelper = new SavingTrackHelper(this);
|
||||
|
@ -636,14 +637,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
private void updateLayers(){
|
||||
if(mapView.getLayers().contains(transportStopsLayer) != OsmandSettings.isShowingTransportOverMap(this)){
|
||||
if(OsmandSettings.isShowingTransportOverMap(this)){
|
||||
mapView.addLayer(transportStopsLayer, routeLayer);
|
||||
mapView.addLayer(transportStopsLayer, 5);
|
||||
} else {
|
||||
mapView.removeLayer(transportStopsLayer);
|
||||
}
|
||||
}
|
||||
if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(this)){
|
||||
if(OsmandSettings.isShowingOsmBugs(this)){
|
||||
mapView.addLayer(osmBugsLayer, routeLayer);
|
||||
mapView.addLayer(osmBugsLayer, 2);
|
||||
} else {
|
||||
mapView.removeLayer(osmBugsLayer);
|
||||
}
|
||||
|
@ -651,7 +652,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){
|
||||
if(OsmandSettings.isShowingPoiOverMap(this)){
|
||||
mapView.addLayer(poiMapLayer, routeLayer);
|
||||
mapView.addLayer(poiMapLayer, 3);
|
||||
} else {
|
||||
mapView.removeLayer(poiMapLayer);
|
||||
}
|
||||
|
@ -659,7 +660,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
if(mapView.getLayers().contains(favoritesLayer) != OsmandSettings.isShowingFavorites(this)){
|
||||
if(OsmandSettings.isShowingFavorites(this)){
|
||||
mapView.addLayer(favoritesLayer, routeLayer);
|
||||
mapView.addLayer(favoritesLayer, 4);
|
||||
} else {
|
||||
mapView.removeLayer(favoritesLayer);
|
||||
}
|
||||
|
@ -667,6 +668,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
}
|
||||
|
||||
private void updateMapSource(ITileSource newSource){
|
||||
if(mapView.getMap() instanceof SQLiteTileSource){
|
||||
((SQLiteTileSource)mapView.getMap()).closeDB();
|
||||
}
|
||||
ResourceManager.getResourceManager().setMapSource(newSource);
|
||||
mapView.setMap(newSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -679,11 +688,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
routingHelper = RoutingHelper.getInstance(this);
|
||||
ITileSource source = OsmandSettings.getMapTileSource(this);
|
||||
if(!Algoritms.objectEquals(mapView.getMap(), source)){
|
||||
if(mapView.getMap() instanceof SQLiteTileSource){
|
||||
((SQLiteTileSource)mapView.getMap()).closeDB();
|
||||
}
|
||||
ResourceManager.getResourceManager().setMapSource(source);
|
||||
mapView.setMap(source);
|
||||
updateMapSource(source);
|
||||
}
|
||||
|
||||
updateApplicationModeSettings();
|
||||
|
@ -1097,7 +1102,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int item, boolean isChecked) {
|
||||
if (item == 0) {
|
||||
// TODO show another builder with all sources
|
||||
dialog.dismiss();
|
||||
selectMapLayer();
|
||||
} else if(item == 1){
|
||||
if(isChecked){
|
||||
selectPOIFilterLayer();
|
||||
|
@ -1153,6 +1159,24 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
builder.show();
|
||||
}
|
||||
|
||||
private void selectMapLayer(){
|
||||
Map<String, String> entriesMap = SettingsActivity.getTileSourceEntries();
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
final ArrayList<String> keys = new ArrayList<String>(entriesMap.keySet());
|
||||
builder.setItems(entriesMap.values().toArray(new String[entriesMap.size()]), new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Editor edit = OsmandSettings.getWriteableEditor(MapActivity.this);
|
||||
edit.putString(OsmandSettings.MAP_TILE_SOURCES, keys.get(which));
|
||||
edit.commit();
|
||||
updateMapSource(OsmandSettings.getMapTileSource(MapActivity.this));
|
||||
mapView.refreshMap();
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
||||
public void contextMenuPoint(final double latitude, final double longitude, boolean menu){
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package com.osmand.activities;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
|
@ -302,33 +303,16 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
maxLevelToDownload.setValue(OsmandSettings.getMaximumLevelToDownloadTile(this)+""); //$NON-NLS-1$
|
||||
|
||||
|
||||
List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
|
||||
List<File> sqLiteFiles = new ArrayList<File>();
|
||||
|
||||
File dir = new File(Environment.getExternalStorageDirectory(), ResourceManager.TILES_PATH);
|
||||
if (dir != null) {
|
||||
for (File f : dir.listFiles()) {
|
||||
if (f.getName().endsWith(SQLiteTileSource.EXT)) {
|
||||
sqLiteFiles.add(f);
|
||||
}
|
||||
}
|
||||
Map<String, String> entriesMap = getTileSourceEntries();
|
||||
entries = new String[entriesMap.size()];
|
||||
valueEntries = new String[entriesMap.size()];
|
||||
int ki = 0;
|
||||
for(Map.Entry<String, String> es : entriesMap.entrySet()){
|
||||
entries[ki] = es.getValue();
|
||||
valueEntries[ki] = es.getKey();
|
||||
ki++;
|
||||
}
|
||||
|
||||
entries = new String[list.size() + sqLiteFiles.size()];
|
||||
valueEntries = new String[list.size() + sqLiteFiles.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
entries[i + sqLiteFiles.size()] = list.get(i).getName();
|
||||
valueEntries[i + sqLiteFiles.size()] = list.get(i).getName();
|
||||
}
|
||||
for (int i = 0; i < sqLiteFiles.size(); i++) {
|
||||
String n = sqLiteFiles.get(i).getName();
|
||||
entries[i] = n.substring(0, n.indexOf('.'));
|
||||
valueEntries[i] = sqLiteFiles.get(i).getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
tileSourcePreference.setEntries(entries);
|
||||
tileSourcePreference.setEntryValues(valueEntries);
|
||||
tileSourcePreference.setValue(OsmandSettings.getMapTileSourceName(this));
|
||||
|
@ -340,6 +324,25 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
tileSourcePreference.setSummary(summary + mapName);
|
||||
}
|
||||
|
||||
public static Map<String, String> getTileSourceEntries(){
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
File dir = new File(Environment.getExternalStorageDirectory(), ResourceManager.TILES_PATH);
|
||||
if (dir != null && dir.canRead()) {
|
||||
for (File f : dir.listFiles()) {
|
||||
if (f.getName().endsWith(SQLiteTileSource.EXT)) {
|
||||
String n = f.getName();
|
||||
map.put(f.getName(), n.substring(0, n.indexOf('.')));
|
||||
}
|
||||
}
|
||||
}
|
||||
for(TileSourceTemplate l : TileSourceManager.getKnownSourceTemplates()){
|
||||
map.put(l.getName(), l.getName());
|
||||
}
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.osmand.views;
|
|||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -89,6 +91,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
private OnTrackBallListener trackBallDelegate;
|
||||
|
||||
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
||||
private Map<OsmandMapLayer, Float> zOrders = new HashMap<OsmandMapLayer, Float>();
|
||||
|
||||
// UI Part
|
||||
// handler to refresh map (in ui thread - not necessary in ui thread, but msg queue is desirable).
|
||||
|
@ -172,23 +175,23 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
}
|
||||
|
||||
public void addLayer(OsmandMapLayer layer, OsmandMapLayer afterIt){
|
||||
layer.initLayer(this);
|
||||
int i = layers.indexOf(afterIt);
|
||||
if(i == -1){
|
||||
layers.add(layer);
|
||||
} else {
|
||||
layers.add(i, layer);
|
||||
}
|
||||
}
|
||||
|
||||
public void addLayer(OsmandMapLayer layer){
|
||||
|
||||
public void addLayer(OsmandMapLayer layer, float zOrder){
|
||||
int i=0;
|
||||
for(i=0; i<layers.size(); i++){
|
||||
if(zOrders.get(layers.get(i)) > zOrder){
|
||||
break;
|
||||
}
|
||||
}
|
||||
layer.initLayer(this);
|
||||
layers.add(layer);
|
||||
layers.add(i, layer);
|
||||
zOrders.put(layer, zOrder);
|
||||
}
|
||||
|
||||
public void removeLayer(OsmandMapLayer layer){
|
||||
layers.remove(layer);
|
||||
zOrders.remove(layer);
|
||||
layer.destroyLayer();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue