Theme texture atlas #324 improvements, #63

This commit is contained in:
Emux
2017-03-06 15:18:07 +02:00
parent 2d3ab0b6fd
commit 808671c1fb
8 changed files with 126 additions and 353 deletions

View File

@@ -15,159 +15,22 @@
*/
package org.oscim.android.test;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import org.oscim.android.filepicker.FilePicker;
import org.oscim.android.filepicker.FilterByFileExtension;
import org.oscim.android.filepicker.ValidMapFile;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.layers.TileGridLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.renderer.BitmapRenderer;
import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.DefaultMapScaleBar;
import org.oscim.scalebar.ImperialUnitAdapter;
import org.oscim.scalebar.MapScaleBar;
import org.oscim.scalebar.MapScaleBarLayer;
import org.oscim.scalebar.MetricUnitAdapter;
import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.mapfile.MapFileTileSource;
import org.oscim.tiling.source.mapfile.MapInfo;
public class AtlasThemeMapActivity extends MapActivity {
private static final int SELECT_MAP_FILE = 0;
private TileGridLayer mGridLayer;
private DefaultMapScaleBar mMapScaleBar;
public class AtlasThemeMapActivity extends SimpleMapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set flag to use TextureAtlas for Theme-Symbol's!
public void onCreate(Bundle savedInstanceState) {
ThemeLoader.USE_ATLAS = true;
startActivityForResult(new Intent(this, MapFilePicker.class),
SELECT_MAP_FILE);
}
@Override
protected void onDestroy() {
mMapScaleBar.destroy();
super.onDestroy();
}
public static class MapFilePicker extends FilePicker {
public MapFilePicker() {
setFileDisplayFilter(new FilterByFileExtension(".map"));
setFileSelectFilter(new ValidMapFile());
}
super.onCreate(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.theme_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.theme_default:
mMap.setTheme(VtmThemes.DEFAULT);
item.setChecked(true);
return true;
case R.id.theme_osmarender:
mMap.setTheme(VtmThemes.OSMARENDER);
item.setChecked(true);
return true;
case R.id.theme_osmagray:
mMap.setTheme(VtmThemes.OSMAGRAY);
item.setChecked(true);
return true;
case R.id.theme_tubes:
mMap.setTheme(VtmThemes.TRONRENDER);
item.setChecked(true);
return true;
case R.id.theme_newtron:
mMap.setTheme(VtmThemes.NEWTRON);
item.setChecked(true);
return true;
case R.id.gridlayer:
if (item.isChecked()) {
item.setChecked(false);
mMap.layers().remove(mGridLayer);
} else {
item.setChecked(true);
if (mGridLayer == null)
mGridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
mMap.layers().add(mGridLayer);
}
mMap.updateMap(true);
return true;
}
return false;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == SELECT_MAP_FILE) {
if (resultCode != RESULT_OK || intent == null || intent.getStringExtra(FilePicker.SELECTED_FILE) == null) {
finish();
return;
}
MapFileTileSource tileSource = new MapFileTileSource();
tileSource.setPreferredLanguage("en");
String file = intent.getStringExtra(FilePicker.SELECTED_FILE);
if (tileSource.setMapFile(file)) {
VectorTileLayer l = mMap.setBaseMap(tileSource);
loadTheme(null);
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMapScaleBar = new DefaultMapScaleBar(mMap);
mMapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mMapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mMapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
mMapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mMapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
mMap.layers().add(mapScaleBarLayer);
MapInfo info = tileSource.getMapInfo();
MapPosition pos = new MapPosition();
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
mMap.setMapPosition(pos);
mPrefs.clear();
}
}
}
protected void loadTheme(final String styleId) {
mMap.setTheme(VtmThemes.DEFAULT);
}
}