diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml index edab890c..4507fcce 100644 --- a/vtm-android-example/AndroidManifest.xml +++ b/vtm-android-example/AndroidManifest.xml @@ -56,6 +56,9 @@ + diff --git a/vtm-android-example/assets/vtm/stylemenu.xml b/vtm-android-example/assets/vtm/stylemenu.xml new file mode 100644 index 00000000..36e4f7b0 --- /dev/null +++ b/vtm-android-example/assets/vtm/stylemenu.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vtm-android-example/res/menu/activity_map.xml b/vtm-android-example/res/menu/activity_map.xml deleted file mode 100644 index 748dcba1..00000000 --- a/vtm-android-example/res/menu/activity_map.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/vtm-android-example/res/menu/style_menu.xml b/vtm-android-example/res/menu/style_menu.xml new file mode 100644 index 00000000..f9b6ef2d --- /dev/null +++ b/vtm-android-example/res/menu/style_menu.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/vtm-android-example/res/menu/theme_menu.xml b/vtm-android-example/res/menu/theme_menu.xml index 70987103..a4d9fa05 100644 --- a/vtm-android-example/res/menu/theme_menu.xml +++ b/vtm-android-example/res/menu/theme_menu.xml @@ -7,26 +7,21 @@ + android:title="@string/theme_default" /> + android:title="@string/theme_tubes" /> + android:title="@string/theme_osmarender" /> + android:title="@string/theme_newtron" /> + android:title="@string/menu_gridlayer" /> - \ No newline at end of file + diff --git a/vtm-android-example/res/values/strings.xml b/vtm-android-example/res/values/strings.xml index 7d7261ab..80db8c4a 100644 --- a/vtm-android-example/res/values/strings.xml +++ b/vtm-android-example/res/values/strings.xml @@ -1,7 +1,6 @@ VTM Samples - Settings Default Tubes Osmarender @@ -14,6 +13,8 @@ Area Outline Controls - Gridlayer + Show nature + Hide nature + Grid diff --git a/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java b/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java index b9497957..4d01cfd9 100644 --- a/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java @@ -118,7 +118,7 @@ public class MapsforgeMapActivity extends MapActivity { if (tileSource.setMapFile(file)) { VectorTileLayer l = mMap.setBaseMap(tileSource); - mMap.setTheme(VtmThemes.DEFAULT); + loadTheme(null); mMap.layers().add(new BuildingLayer(mMap, l)); mMap.layers().add(new LabelLayer(mMap, l)); @@ -132,4 +132,8 @@ public class MapsforgeMapActivity extends MapActivity { } } } + + protected void loadTheme(final String styleId) { + mMap.setTheme(VtmThemes.DEFAULT); + } } diff --git a/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java b/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java new file mode 100644 index 00000000..9dff4f0a --- /dev/null +++ b/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java @@ -0,0 +1,89 @@ +/* + * Copyright 2016 devemux86 + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.android.test; + +import android.view.Menu; +import android.view.MenuItem; +import android.widget.Toast; + +import org.oscim.android.theme.AssetsRenderTheme; +import org.oscim.theme.XmlRenderThemeMenuCallback; +import org.oscim.theme.XmlRenderThemeStyleLayer; +import org.oscim.theme.XmlRenderThemeStyleMenu; + +import java.util.Set; + +/** + * Load render theme from Android assets folder and show a configuration menu based on stylemenu. + */ +public class MapsforgeStyleActivity extends MapsforgeMapActivity { + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.style_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.style_1: + item.setChecked(true); + loadTheme("1"); + mMap.clearMap(); + Toast.makeText(this, "Show nature layers", Toast.LENGTH_SHORT).show(); + return true; + case R.id.style_2: + item.setChecked(true); + loadTheme("2"); + mMap.clearMap(); + Toast.makeText(this, "Hide nature layers", Toast.LENGTH_SHORT).show(); + return true; + default: + return false; + } + } + + @Override + protected void loadTheme(final String styleId) { + mMap.setTheme(new AssetsRenderTheme(this, "", "vtm/stylemenu.xml", new XmlRenderThemeMenuCallback() { + @Override + public Set getCategories(XmlRenderThemeStyleMenu renderThemeStyleMenu) { + // Use the selected style or the default + String style = styleId != null ? styleId : renderThemeStyleMenu.getDefaultValue(); + + // Retrieve the layer from the style id + XmlRenderThemeStyleLayer renderThemeStyleLayer = renderThemeStyleMenu.getLayer(style); + if (renderThemeStyleLayer == null) { + System.err.println("Invalid style " + style); + return null; + } + + // First get the selected layer's categories that are enabled together + Set categories = renderThemeStyleLayer.getCategories(); + + // Then add the selected layer's overlays that are enabled individually + // Here we use the style menu, but users can use their own preferences + for (XmlRenderThemeStyleLayer overlay : renderThemeStyleLayer.getOverlays()) { + if (overlay.isEnabled()) + categories.addAll(overlay.getCategories()); + } + + // This is the whole categories set to be enabled + return categories; + } + })); + } +} diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java index a2e69cd7..4edb40ff 100644 --- a/vtm-android-example/src/org/oscim/android/test/Samples.java +++ b/vtm-android-example/src/org/oscim/android/test/Samples.java @@ -41,6 +41,7 @@ public class Samples extends Activity { LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples); linearLayout.addView(createButton(SimpleMapActivity.class)); linearLayout.addView(createButton(MapsforgeMapActivity.class)); + linearLayout.addView(createButton(MapsforgeStyleActivity.class)); linearLayout.addView(createButton(MapboxMapActivity.class)); linearLayout.addView(createButton(OsmJsonMapActivity.class));