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