Samples improvements #785
This commit is contained in:
@@ -31,22 +31,17 @@ import org.oscim.scalebar.MapScaleBarLayer;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.mapfile.MapFileTileSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
/**
|
||||
* A very basic Android app example.
|
||||
* <p>
|
||||
* You'll need a map with filename berlin.map from download.mapsforge.org in device storage:
|
||||
* /sdcard/Android/data/org.oscim.android.test/files/
|
||||
* You'll need a map with filename berlin.map from download.mapsforge.org in device storage.
|
||||
*/
|
||||
public class GettingStarted extends Activity {
|
||||
|
||||
// Name of the map file in device storage
|
||||
private static final String MAP_FILE = "berlin.map";
|
||||
|
||||
// Request code for selecting a map file
|
||||
private static final int PICK_MAP_FILE = 0;
|
||||
private static final int SELECT_MAP_FILE = 0;
|
||||
|
||||
private MapView mapView;
|
||||
|
||||
@@ -59,18 +54,15 @@ public class GettingStarted extends Activity {
|
||||
setContentView(mapView);
|
||||
|
||||
// Open map
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
startActivityForResult(intent, PICK_MAP_FILE);
|
||||
} else
|
||||
openMap(null);
|
||||
startActivityForResult(intent, SELECT_MAP_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == PICK_MAP_FILE && resultCode == Activity.RESULT_OK) {
|
||||
if (requestCode == SELECT_MAP_FILE && resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
Uri uri = data.getData();
|
||||
openMap(uri);
|
||||
@@ -82,14 +74,8 @@ public class GettingStarted extends Activity {
|
||||
try {
|
||||
// Tile source
|
||||
MapFileTileSource tileSource = new MapFileTileSource();
|
||||
if (uri != null) {
|
||||
FileInputStream fis = (FileInputStream) getContentResolver().openInputStream(uri);
|
||||
tileSource.setMapFileInputStream(fis);
|
||||
} else {
|
||||
String mapPath = new File(getExternalFilesDir(null), MAP_FILE).getAbsolutePath();
|
||||
if (!tileSource.setMapFile(mapPath))
|
||||
return;
|
||||
}
|
||||
|
||||
// Vector layer
|
||||
VectorTileLayer tileLayer = mapView.map().setBaseMap(tileSource);
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.oscim.renderer.BitmapRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.bucket.RenderBuckets;
|
||||
import org.oscim.scalebar.*;
|
||||
import org.oscim.theme.ExternalRenderTheme;
|
||||
import org.oscim.theme.ThemeFile;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.theme.styles.AreaStyle;
|
||||
@@ -63,11 +62,8 @@ public class MapsforgeActivity extends MapActivity {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MapsforgeActivity.class);
|
||||
|
||||
static final int PICK_MAP_FILE = 0;
|
||||
static final int PICK_THEME_FILE = 1;
|
||||
|
||||
static final int SELECT_MAP_FILE = 2;
|
||||
static final int SELECT_THEME_FILE = 3;
|
||||
static final int SELECT_MAP_FILE = 0;
|
||||
static final int SELECT_THEME_FILE = 1;
|
||||
|
||||
private static final Tag ISSEA_TAG = new Tag("natural", "issea");
|
||||
private static final Tag NOSEA_TAG = new Tag("natural", "nosea");
|
||||
@@ -96,14 +92,10 @@ public class MapsforgeActivity extends MapActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
startActivityForResult(intent, PICK_MAP_FILE);
|
||||
} else
|
||||
startActivityForResult(new Intent(this, MapFilePicker.class),
|
||||
SELECT_MAP_FILE);
|
||||
startActivityForResult(intent, SELECT_MAP_FILE);
|
||||
}
|
||||
|
||||
public static class MapFilePicker extends FilePicker {
|
||||
@@ -157,14 +149,10 @@ public class MapsforgeActivity extends MapActivity {
|
||||
return true;
|
||||
|
||||
case R.id.theme_external:
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
startActivityForResult(intent, PICK_THEME_FILE);
|
||||
} else
|
||||
startActivityForResult(new Intent(this, ThemeFilePicker.class),
|
||||
SELECT_THEME_FILE);
|
||||
startActivityForResult(intent, SELECT_THEME_FILE);
|
||||
return true;
|
||||
|
||||
case R.id.gridlayer:
|
||||
@@ -188,7 +176,7 @@ public class MapsforgeActivity extends MapActivity {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
||||
if (requestCode == PICK_MAP_FILE || requestCode == SELECT_MAP_FILE) {
|
||||
if (requestCode == SELECT_MAP_FILE) {
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
finish();
|
||||
return;
|
||||
@@ -197,7 +185,6 @@ public class MapsforgeActivity extends MapActivity {
|
||||
MapFileTileSource tileSource = new MapFileTileSource();
|
||||
//tileSource.setPreferredLanguage("en");
|
||||
|
||||
if (requestCode == PICK_MAP_FILE) {
|
||||
try {
|
||||
Uri uri = data.getData();
|
||||
FileInputStream fis = (FileInputStream) getContentResolver().openInputStream(uri);
|
||||
@@ -207,18 +194,6 @@ public class MapsforgeActivity extends MapActivity {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (data.getStringExtra(FilePicker.SELECTED_FILE) == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
String file = data.getStringExtra(FilePicker.SELECTED_FILE);
|
||||
if (!tileSource.setMapFile(file)) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mTileLayer = mMap.setBaseMap(tileSource);
|
||||
loadTheme(null);
|
||||
@@ -248,21 +223,12 @@ public class MapsforgeActivity extends MapActivity {
|
||||
mMap.setMapPosition(pos);
|
||||
mPrefs.clear();
|
||||
}
|
||||
} else if (requestCode == PICK_THEME_FILE || requestCode == SELECT_THEME_FILE) {
|
||||
} else if (requestCode == SELECT_THEME_FILE) {
|
||||
if (resultCode != Activity.RESULT_OK || data == null)
|
||||
return;
|
||||
|
||||
ThemeFile theme;
|
||||
if (requestCode == PICK_THEME_FILE) {
|
||||
Uri uri = data.getData();
|
||||
theme = new ContentRenderTheme(getContentResolver(), "", uri);
|
||||
} else {
|
||||
if (data.getStringExtra(FilePicker.SELECTED_FILE) == null)
|
||||
return;
|
||||
|
||||
String file = data.getStringExtra(FilePicker.SELECTED_FILE);
|
||||
theme = new ExternalRenderTheme(file);
|
||||
}
|
||||
ThemeFile theme = new ContentRenderTheme(getContentResolver(), "", uri);
|
||||
|
||||
// Use tessellation with sea and land for Mapsforge themes
|
||||
if (theme.isMapsforgeTheme()) {
|
||||
|
||||
Reference in New Issue
Block a user