switch package org.mapsforge -> org.oscim

This commit is contained in:
Hannes Janetzek
2012-09-12 00:33:39 +02:00
parent 489f07dd5d
commit e2da87d8e0
155 changed files with 548 additions and 535 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app;
import java.text.DecimalFormat;
import android.content.res.Resources;
final class FileUtils {
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.00 ");
private static final double ONE_GIGABYTE = 1000000000;
private static final double ONE_KILOBYTE = 1000;
private static final double ONE_MEGABYTE = 1000000;
/**
* Formats the given file size as a human readable string, using SI prefixes.
*
* @param fileSize
* the file size to be formatted.
* @param resources
* a reference to the application resources.
* @return a human readable file size.
* @throws IllegalArgumentException
* if the given file size is negative.
*/
static String formatFileSize(long fileSize, Resources resources) {
if (fileSize < 0) {
throw new IllegalArgumentException("invalid file size: " + fileSize);
} else if (fileSize < 1000) {
if (fileSize == 1) {
// singular
return "1 " + resources.getString(R.string.file_size_byte);
}
// plural, including zero
return fileSize + " " + resources.getString(R.string.file_size_bytes);
} else {
if (fileSize < ONE_MEGABYTE) {
return DECIMAL_FORMAT.format(fileSize / ONE_KILOBYTE)
+ resources.getString(R.string.file_size_kb);
} else if (fileSize < ONE_GIGABYTE) {
return DECIMAL_FORMAT.format(fileSize / ONE_MEGABYTE)
+ resources.getString(R.string.file_size_mb);
}
return DECIMAL_FORMAT.format(fileSize / ONE_GIGABYTE)
+ resources.getString(R.string.file_size_gb);
}
}
private FileUtils() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.WindowManager;
import android.webkit.WebView;
/**
* Simple activity to display the info web page from the assets folder.
*/
public class InfoView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.loadUrl("file:///android_asset/info.xml");
setContentView(webView);
}
@Override
protected void onResume() {
super.onResume();
// check if the full screen mode should be activated
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
}

View File

@@ -0,0 +1,258 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
public class LocationHandler {
private static final int DIALOG_LOCATION_PROVIDER_DISABLED = 2;
private MyLocationListener mLocationListener;
private LocationManager mLocationManager;
private boolean mShowMyLocation;
private ToggleButton mSnapToLocationView;
private boolean mSnapToLocation;
/* package */final TileMap mTileMap;
LocationHandler(TileMap tileMap) {
mTileMap = tileMap;
mLocationManager = (LocationManager) tileMap
.getSystemService(Context.LOCATION_SERVICE);
mLocationListener = new MyLocationListener();
mSnapToLocationView = (ToggleButton) tileMap
.findViewById(R.id.snapToLocationView);
mSnapToLocationView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (isSnapToLocationEnabled()) {
disableSnapToLocation(true);
} else {
enableSnapToLocation(true);
}
}
});
}
boolean enableShowMyLocation(boolean centerAtFirstFix) {
Log.d("TileMap", "enableShowMyLocation " + mShowMyLocation);
gotoLastKnownPosition();
if (!mShowMyLocation) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String bestProvider = mLocationManager.getBestProvider(criteria, true);
if (bestProvider == null) {
mTileMap.showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
return false;
}
mShowMyLocation = true;
Log.d("TileMap", "enableShowMyLocation " + mShowMyLocation);
mLocationListener.setFirstCenter(centerAtFirstFix);
mLocationManager.requestLocationUpdates(bestProvider, 1000, 0,
mLocationListener);
mSnapToLocationView.setVisibility(View.VISIBLE);
return true;
}
return false;
}
void gotoLastKnownPosition() {
Location currentLocation;
Location bestLocation = null;
for (String provider : mLocationManager.getProviders(true)) {
currentLocation = mLocationManager.getLastKnownLocation(provider);
if (currentLocation == null)
continue;
if (bestLocation == null
|| currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
bestLocation = currentLocation;
}
}
if (bestLocation != null) {
byte zoom = mTileMap.mMapView.getMapPosition().getZoomLevel();
if (zoom < 12)
zoom = (byte) 12;
MapPosition mapPosition = new MapPosition(bestLocation.getLatitude(),
bestLocation.getLongitude(), zoom, 1, 0);
mTileMap.mMapView.setMapCenter(mapPosition);
} else {
mTileMap.showToastOnUiThread(mTileMap
.getString(R.string.error_last_location_unknown));
}
}
/**
* Disables the "show my location" mode.
*
* @return ...
*/
boolean disableShowMyLocation() {
if (mShowMyLocation) {
mShowMyLocation = false;
disableSnapToLocation(false);
mLocationManager.removeUpdates(mLocationListener);
// if (circleOverlay != null) {
// mapView.getOverlays().remove(circleOverlay);
// mapView.getOverlays().remove(itemizedOverlay);
// circleOverlay = null;
// itemizedOverlay = null;
// }
mSnapToLocationView.setVisibility(View.GONE);
return true;
}
return false;
}
/**
* Returns the status of the "show my location" mode.
*
* @return true if the "show my location" mode is enabled, false otherwise.
*/
boolean isShowMyLocationEnabled() {
return mShowMyLocation;
}
/**
* Disables the "snap to location" mode.
*
* @param showToast
* defines whether a toast message is displayed or not.
*/
void disableSnapToLocation(boolean showToast) {
if (mSnapToLocation) {
mSnapToLocation = false;
mSnapToLocationView.setChecked(false);
mTileMap.mMapView.setClickable(true);
if (showToast) {
mTileMap.showToastOnUiThread(mTileMap
.getString(R.string.snap_to_location_disabled));
}
}
}
/**
* Enables the "snap to location" mode.
*
* @param showToast
* defines whether a toast message is displayed or not.
*/
void enableSnapToLocation(boolean showToast) {
if (!mSnapToLocation) {
mSnapToLocation = true;
mTileMap.mMapView.setClickable(false);
if (showToast) {
mTileMap.showToastOnUiThread(mTileMap
.getString(R.string.snap_to_location_enabled));
}
}
}
/**
* Returns the status of the "snap to location" mode.
*
* @return true if the "snap to location" mode is enabled, false otherwise.
*/
boolean isSnapToLocationEnabled() {
return mSnapToLocation;
}
class MyLocationListener implements LocationListener {
private boolean mSetCenter;
@Override
public void onLocationChanged(Location location) {
Log.d("LocationListener", "onLocationChanged, "
+ " lon:" + location.getLongitude()
+ " lat:" + location.getLatitude());
if (!isShowMyLocationEnabled()) {
return;
}
GeoPoint point = new GeoPoint(location.getLatitude(), location.getLongitude());
// this.advancedMapViewer.overlayCircle.setCircleData(point, location.getAccuracy());
// this.advancedMapViewer.overlayItem.setPoint(point);
// this.advancedMapViewer.circleOverlay.requestRedraw();
// this.advancedMapViewer.itemizedOverlay.requestRedraw();
if (mSetCenter || isSnapToLocationEnabled()) {
mSetCenter = false;
mTileMap.mMapView.setCenter(point);
}
}
@Override
public void onProviderDisabled(String provider) {
// do nothing
}
@Override
public void onProviderEnabled(String provider) {
// do nothing
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// do nothing
}
boolean isFirstCenter() {
return mSetCenter;
}
void setFirstCenter(boolean center) {
mSetCenter = center;
}
}
}

679
src/org/oscim/app/TileMap.java Executable file
View File

@@ -0,0 +1,679 @@
package org.oscim.app;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import org.oscim.app.filefilter.FilterByFileExtension;
import org.oscim.app.filefilter.ValidMapFile;
import org.oscim.app.filefilter.ValidRenderTheme;
import org.oscim.app.filepicker.FilePicker;
import org.oscim.app.preferences.EditPreferences;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.database.MapDatabases;
import org.oscim.theme.InternalRenderTheme;
import org.oscim.view.DebugSettings;
import org.oscim.view.MapActivity;
import org.oscim.view.MapView;
import org.oscim.view.utils.AndroidUtils;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
/**
* A map application which uses the features from the mapsforge map library. The map can be centered to the current
* location. A simple file browser for selecting the map file is also included. Some preferences can be adjusted via the
* {@link EditPreferences} activity.
*/
public class TileMap extends MapActivity {
// implements ActionBar.OnNavigationListener {
// private static final String BUNDLE_CENTER_AT_FIRST_FIX = "centerAtFirstFix";
private static final String BUNDLE_SHOW_MY_LOCATION = "showMyLocation";
private static final String BUNDLE_SNAP_TO_LOCATION = "snapToLocation";
private static final int DIALOG_ENTER_COORDINATES = 0;
private static final int DIALOG_INFO_MAP_FILE = 1;
private static final int DIALOG_LOCATION_PROVIDER_DISABLED = 2;
private static final FileFilter FILE_FILTER_EXTENSION_MAP =
new FilterByFileExtension(".map");
private static final FileFilter FILE_FILTER_EXTENSION_XML =
new FilterByFileExtension(".xml");
private static final int SELECT_MAP_FILE = 0;
private static final int SELECT_RENDER_THEME_FILE = 1;
LocationHandler mLocation;
private MapDatabases mMapDatabase;
private WakeLock mWakeLock;
MapView mMapView;
private Menu mMenu = null;
SpinnerAdapter mSpinnerAdapter;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
getMenuInflater().inflate(R.menu.options_menu, menu);
else
getMenuInflater().inflate(R.menu.options_menu_pre_honeycomb, menu);
mMenu = menu;
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_info_about:
startActivity(new Intent(this, InfoView.class));
return true;
case R.id.menu_position:
return true;
case R.id.menu_rotation_enable:
mMapView.enableRotation(true);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_rotation_disable:
mMapView.enableRotation(false);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_compass_enable:
mMapView.enableCompass(true);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_compass_disable:
mMapView.enableCompass(false);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_position_my_location_enable:
toggleMenuItem(mMenu,
R.id.menu_position_my_location_enable,
R.id.menu_position_my_location_disable,
!mLocation.enableShowMyLocation(true));
return true;
case R.id.menu_position_my_location_disable:
toggleMenuItem(mMenu,
R.id.menu_position_my_location_enable,
R.id.menu_position_my_location_disable,
mLocation.disableShowMyLocation());
return true;
// case R.id.menu_position_last_known:
// mLocation.gotoLastKnownPosition();
// return true;
case R.id.menu_position_enter_coordinates:
showDialog(DIALOG_ENTER_COORDINATES);
return true;
case R.id.menu_position_map_center:
// disable GPS follow mode if it is enabled
mLocation.disableSnapToLocation(true);
mMapView.setCenter(mMapView.getMapDatabase()
.getMapInfo().mapCenter);
return true;
case R.id.menu_preferences:
startActivity(new Intent(this, EditPreferences.class));
return true;
case R.id.menu_render_theme:
return true;
case R.id.menu_options:
return true;
case R.id.menu_render_theme_osmarender:
mMapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
return true;
case R.id.menu_render_theme_tronrender:
mMapView.setRenderTheme(InternalRenderTheme.TRONRENDER);
return true;
case R.id.menu_render_theme_select_file:
startRenderThemePicker();
return true;
case R.id.menu_mapfile:
startMapFilePicker();
return true;
default:
return false;
}
}
private static void toggleMenuRotation(Menu menu, boolean rotate, boolean compass) {
toggleMenuItem(menu,
R.id.menu_rotation_enable,
R.id.menu_rotation_disable,
!rotate);
toggleMenuItem(menu,
R.id.menu_compass_enable,
R.id.menu_compass_disable,
!compass);
}
private static void toggleMenuItem(Menu menu, int id, int id2, boolean enable) {
menu.findItem(id).setVisible(enable);
menu.findItem(id).setEnabled(enable);
menu.findItem(id2).setVisible(!enable);
menu.findItem(id2).setEnabled(!enable);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
onCreateOptionsMenu(menu);
toggleMenuItem(menu,
R.id.menu_position_my_location_enable,
R.id.menu_position_my_location_disable,
!mLocation.isShowMyLocationEnabled());
// if (mLocation.isShowMyLocationEnabled()) {
// menu.findItem(R.id.menu_position_my_location_enable).setVisible(false);
// menu.findItem(R.id.menu_position_my_location_enable).setEnabled(false);
// menu.findItem(R.id.menu_position_my_location_disable).setVisible(true);
// menu.findItem(R.id.menu_position_my_location_disable).setEnabled(true);
// } else {
// menu.findItem(R.id.menu_position_my_location_enable).setVisible(true);
// menu.findItem(R.id.menu_position_my_location_enable).setEnabled(true);
// menu.findItem(R.id.menu_position_my_location_disable).setVisible(false);
// menu.findItem(R.id.menu_position_my_location_disable).setEnabled(false);
// }
menu.findItem(R.id.menu_render_theme).setEnabled(true);
if (mMapDatabase == MapDatabases.MAP_READER) {
menu.findItem(R.id.menu_mapfile).setVisible(true);
menu.findItem(R.id.menu_position_map_center).setVisible(true);
} else {
menu.findItem(R.id.menu_mapfile).setVisible(false);
menu.findItem(R.id.menu_position_map_center).setVisible(false);
}
toggleMenuItem(menu,
R.id.menu_compass_enable,
R.id.menu_compass_disable,
!mMapView.enableCompass);
toggleMenuItem(mMenu,
R.id.menu_rotation_enable,
R.id.menu_rotation_disable,
!mMapView.enableRotation);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
// forward the event to the MapView
return mMapView.onTrackballEvent(event);
}
private void configureMapView() {
// configure the MapView and activate the zoomLevel buttons
mMapView.setClickable(true);
// mMapView.setBuiltInZoomControls(true);
mMapView.setFocusable(true);
}
private void startMapFilePicker() {
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_MAP);
FilePicker.setFileSelectFilter(new ValidMapFile());
startActivityForResult(new Intent(this, FilePicker.class), SELECT_MAP_FILE);
}
private void startRenderThemePicker() {
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_XML);
FilePicker.setFileSelectFilter(new ValidRenderTheme());
startActivityForResult(new Intent(this, FilePicker.class),
SELECT_RENDER_THEME_FILE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
// if (requestCode == SELECT_MAP_FILE) {
// if (resultCode == RESULT_OK) {
//
// mLocation.disableSnapToLocation(true);
//
// if (intent != null) {
// if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
// mMapView.setMapFile(intent
// .getStringExtra(FilePicker.SELECTED_FILE));
// }
// }
// } else if (resultCode == RESULT_CANCELED) {
// startActivity(new Intent(this, EditPreferences.class));
// }
// } else
if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK
&& intent != null
&& intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
try {
mMapView.setRenderTheme(intent
.getStringExtra(FilePicker.SELECTED_FILE));
} catch (FileNotFoundException e) {
showToastOnUiThread(e.getLocalizedMessage());
}
}
}
@TargetApi(11)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mSpinnerAdapter = ArrayAdapter.createFromResource(this,
R.array.view_sections,
android.R.layout.simple_spinner_dropdown_item);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
// actionBar.setListNavigationCallbacks(mSpinnerAdapter, this);
actionBar.setDisplayShowTitleEnabled(false);
}
// set up the layout views
setContentView(R.layout.activity_tilemap);
// getActionBar().setDisplayOptions(ActionBar.NAVIGATION_MODE_TABS);
mMapView = (MapView) findViewById(R.id.mapView);
configureMapView();
mLocation = new LocationHandler(this);
// get the pointers to different system services
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager
.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "AMV");
if (savedInstanceState != null) {
if (savedInstanceState.getBoolean(BUNDLE_SHOW_MY_LOCATION)) {
// enableShowMyLocation(savedInstanceState
// .getBoolean(BUNDLE_CENTER_AT_FIRST_FIX));
if (savedInstanceState.getBoolean(BUNDLE_SNAP_TO_LOCATION)) {
mLocation.enableSnapToLocation(false);
}
}
}
}
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
if (id == DIALOG_ENTER_COORDINATES) {
builder.setIcon(android.R.drawable.ic_menu_mylocation);
builder.setTitle(R.string.menu_position_enter_coordinates);
LayoutInflater factory = LayoutInflater.from(this);
final View view = factory.inflate(R.layout.dialog_enter_coordinates, null);
builder.setView(view);
builder.setPositiveButton(R.string.go_to_position,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// disable GPS follow mode if it is enabled
mLocation.disableSnapToLocation(true);
// set the map center and zoom level
EditText latitudeView = (EditText) view
.findViewById(R.id.latitude);
EditText longitudeView = (EditText) view
.findViewById(R.id.longitude);
double latitude = Double.parseDouble(latitudeView.getText()
.toString());
double longitude = Double.parseDouble(longitudeView.getText()
.toString());
SeekBar zoomLevelView = (SeekBar) view
.findViewById(R.id.zoomLevel);
byte zoom = (byte) (zoomLevelView.getProgress());
MapPosition mapPosition = new MapPosition(latitude,
longitude, zoom, 1, 0);
TileMap.this.mMapView.setMapCenter(mapPosition);
}
});
builder.setNegativeButton(R.string.cancel, null);
return builder.create();
} else if (id == DIALOG_LOCATION_PROVIDER_DISABLED) {
builder.setIcon(android.R.drawable.ic_menu_info_details);
builder.setTitle(R.string.error);
builder.setMessage(R.string.no_location_provider_available);
builder.setPositiveButton(R.string.ok, null);
return builder.create();
} else if (id == DIALOG_INFO_MAP_FILE) {
builder.setIcon(android.R.drawable.ic_menu_info_details);
builder.setTitle(R.string.menu_info_map_file);
LayoutInflater factory = LayoutInflater.from(this);
builder.setView(factory.inflate(R.layout.dialog_info_map_file, null));
builder.setPositiveButton(R.string.ok, null);
return builder.create();
} else {
// no dialog will be created
return null;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mLocation.disableShowMyLocation();
}
@Override
protected void onPause() {
super.onPause();
// release the wake lock if necessary
if (mWakeLock.isHeld()) {
mWakeLock.release();
}
}
@Override
protected void onPrepareDialog(int id, final Dialog dialog) {
if (id == DIALOG_ENTER_COORDINATES) {
EditText editText = (EditText) dialog.findViewById(R.id.latitude);
GeoPoint mapCenter = mMapView.getMapPosition().getMapCenter();
editText.setText(Double.toString(mapCenter.getLatitude()));
editText = (EditText) dialog.findViewById(R.id.longitude);
editText.setText(Double.toString(mapCenter.getLongitude()));
SeekBar zoomlevel = (SeekBar) dialog.findViewById(R.id.zoomLevel);
zoomlevel.setMax(20); // FIXME mMapView.getMapGenerator().getZoomLevelMax());
zoomlevel.setProgress(mMapView.getMapPosition().getZoomLevel());
final TextView textView = (TextView) dialog.findViewById(R.id.zoomlevelValue);
textView.setText(String.valueOf(zoomlevel.getProgress()));
zoomlevel.setOnSeekBarChangeListener(new SeekBarChangeListener(textView));
// } else if (id == DIALOG_INFO_MAP_FILE) {
// MapInfo mapInfo = mMapView.getMapDatabase().getMapInfo();
//
// TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
// textView.setText(mMapView.getMapFile());
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
// textView.setText(FileUtils.formatFileSize(mapInfo.fileSize,
// getResources()));
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
// textView.setText(String.valueOf(mapInfo.fileVersion));
//
// // textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug);
// // if (mapFileInfo.debugFile) {
// // textView.setText(R.string.info_map_file_debug_yes);
// // } else {
// // textView.setText(R.string.info_map_file_debug_no);
// // }
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDate);
// Date date = new Date(mapInfo.mapDate);
// textView.setText(DateFormat.getDateTimeInstance().format(date));
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea);
// BoundingBox boundingBox = mapInfo.boundingBox;
// textView.setText(boundingBox.getMinLatitude() + ", "
// + boundingBox.getMinLongitude() + " - \n"
// + boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude());
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition);
// GeoPoint startPosition = mapInfo.startPosition;
// if (startPosition == null) {
// textView.setText(null);
// } else {
// textView.setText(startPosition.getLatitude() + ", "
// + startPosition.getLongitude());
// }
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
// Byte startZoomLevel = mapInfo.startZoomLevel;
// if (startZoomLevel == null) {
// textView.setText(null);
// } else {
// textView.setText(startZoomLevel.toString());
// }
//
// textView = (TextView) dialog
// .findViewById(R.id.infoMapFileViewLanguagePreference);
// textView.setText(mapInfo.languagePreference);
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
// textView.setText(mapInfo.comment);
//
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewCreatedBy);
// textView.setText(mapInfo.createdBy);
} else {
super.onPrepareDialog(id, dialog);
}
}
@Override
protected void onResume() {
super.onResume();
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this);
// MapScaleBar mapScaleBar = mapView.getMapScaleBar();
// mapScaleBar.setShowMapScaleBar(preferences.getBoolean("showScaleBar", false));
// String scaleBarUnitDefault = getString(R.string.preferences_scale_bar_unit_default);
// String scaleBarUnit = preferences.getString("scaleBarUnit", scaleBarUnitDefault);
// mapScaleBar.setImperialUnits(scaleBarUnit.equals("imperial"));
// if (preferences.contains("mapGenerator")) {
// String name = preferences.getString("mapGenerator", MapGeneratorInternal.SW_RENDERER.name());
// MapGeneratorInternal mapGeneratorInternalNew;
// try {
// mapGeneratorInternalNew = MapGeneratorInternal.valueOf(name);
// } catch (IllegalArgumentException e) {
// mapGeneratorInternalNew = MapGeneratorInternal.SW_RENDERER;
// }
//
// if (mapGeneratorInternalNew != mapGeneratorInternal) {
// MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(mapGeneratorInternalNew);
// mapView.setMapGenerator(mapGenerator);
// mapGeneratorInternal = mapGeneratorInternalNew;
// }
// }
if (preferences.contains("mapDatabase")) {
String name = preferences.getString("mapDatabase",
MapDatabases.PBMAP_READER.name());
MapDatabases mapDatabaseNew;
try {
mapDatabaseNew = MapDatabases.valueOf(name);
} catch (IllegalArgumentException e) {
mapDatabaseNew = MapDatabases.PBMAP_READER;
}
Log.d("VectorTileMap", "set map database " + mapDatabaseNew);
if (mapDatabaseNew != mMapDatabase) {
mMapView.setMapDatabase(mapDatabaseNew);
mMapDatabase = mapDatabaseNew;
}
}
// try {
// String textScaleDefault = getString(R.string.preferences_text_scale_default);
// mMapView.setTextScale(Float.parseFloat(preferences.getString("textScale",
// textScaleDefault)));
// } catch (NumberFormatException e) {
// mMapView.setTextScale(1);
// }
if (preferences.getBoolean("fullscreen", false)) {
Log.i("mapviewer", "FULLSCREEN");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
Log.i("mapviewer", "NO FULLSCREEN");
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
if (preferences.getBoolean("fixOrientation", true)) {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// this all returns the orientation which is not currently active?!
// getWindow().getWindowManager().getDefaultDisplay().getRotation());
// getWindow().getWindowManager().getDefaultDisplay().getOrientation());
}
if (preferences.getBoolean("wakeLock", false) && !mWakeLock.isHeld()) {
mWakeLock.acquire();
}
boolean drawTileFrames =
preferences.getBoolean("drawTileFrames", false);
boolean drawTileCoordinates =
preferences.getBoolean("drawTileCoordinates", false);
boolean disablePolygons =
preferences.getBoolean("disablePolygons", false);
boolean drawUnmatchedWays =
preferences.getBoolean("drawUnmatchedWays", false);
DebugSettings debugSettings = new DebugSettings(drawTileCoordinates,
drawTileFrames, disablePolygons, drawUnmatchedWays);
mMapView.setDebugSettings(debugSettings);
// if (mMapDatabase == MapDatabases.MAP_READER) {
// if (mMapView.getMapFile() == null)
// startMapFilePicker();
// } else {
// mMapView.setMapFile(mMapView.getMapFile());
// }
if (Build.VERSION.SDK_INT >= 11) {
VersionHelper.refreshActionBarMenu(this);
}
}
static class VersionHelper {
@TargetApi(11)
static void refreshActionBarMenu(Activity activity) {
activity.invalidateOptionsMenu();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(BUNDLE_SHOW_MY_LOCATION, mLocation.isShowMyLocationEnabled());
// outState.putBoolean(BUNDLE_CENTER_AT_FIRST_FIX,
// mMyLocationListener.isCenterAtFirstFix());
// outState.putBoolean(BUNDLE_SNAP_TO_LOCATION, mSnapToLocation);
}
/**
* Uses the UI thread to display the given text message as toast notification.
*
* @param text
* the text message to display
*/
void showToastOnUiThread(final String text) {
if (AndroidUtils.currentThreadIsUiThread()) {
Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG);
toast.show();
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast toast = Toast.makeText(TileMap.this, text, Toast.LENGTH_LONG);
toast.show();
}
});
}
}
// @Override
// public boolean onNavigationItemSelected(int arg0, long arg1) {
// // TODO Auto-generated method stub
// return false;
// }
class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
private final TextView textView;
SeekBarChangeListener(TextView textView) {
this.textView = textView;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
this.textView.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// do nothing
}
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.filefilter;
import java.io.File;
import java.io.FileFilter;
/**
* Accepts all readable directories and all readable files with a given extension.
*/
public class FilterByFileExtension implements FileFilter {
private final String extension;
/**
* @param extension
* the allowed file name extension.
*/
public FilterByFileExtension(String extension) {
this.extension = extension;
}
@Override
public boolean accept(File file) {
// accept only readable files
if (file.canRead()) {
if (file.isDirectory()) {
// accept all directories
return true;
} else if (file.isFile() && file.getName().endsWith(this.extension)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.filefilter;
import java.io.FileFilter;
import org.oscim.database.OpenResult;
/**
* An extension of the {@link FileFilter} interface.
*/
public interface ValidFileFilter extends FileFilter {
/**
* @return the result of the last {@link #accept} call (might be null).
*/
OpenResult getFileOpenResult();
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.filefilter;
import java.io.File;
import java.util.HashMap;
import org.oscim.database.IMapDatabase;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.MapDatabase;
/**
* Accepts all valid map files.
*/
public final class ValidMapFile implements ValidFileFilter {
private OpenResult openResult;
@Override
public boolean accept(File file) {
IMapDatabase mapDatabase = new MapDatabase();
HashMap<String, String> options = new HashMap<String, String>();
options.put("mapfile", file.getAbsolutePath());
this.openResult = mapDatabase.open(options);
mapDatabase.close();
return this.openResult.isSuccess();
}
@Override
public OpenResult getFileOpenResult() {
return this.openResult;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.filefilter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.oscim.database.OpenResult;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
* Accepts all valid render theme XML files.
*/
public final class ValidRenderTheme implements ValidFileFilter {
private OpenResult openResult;
@Override
public boolean accept(File file) {
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
RenderThemeHandler renderThemeHandler = new RenderThemeHandler();
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
xmlReader.setContentHandler(renderThemeHandler);
xmlReader.parse(new InputSource(inputStream));
this.openResult = OpenResult.SUCCESS;
} catch (ParserConfigurationException e) {
this.openResult = new OpenResult(e.getMessage());
} catch (SAXException e) {
this.openResult = new OpenResult(e.getMessage());
} catch (IOException e) {
this.openResult = new OpenResult(e.getMessage());
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
this.openResult = new OpenResult(e.getMessage());
}
}
return this.openResult.isSuccess();
}
@Override
public OpenResult getFileOpenResult() {
return this.openResult;
}
}

View File

@@ -0,0 +1,255 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.filepicker;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Comparator;
import org.oscim.app.R;
import org.oscim.app.filefilter.ValidFileFilter;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
/**
* A FilePicker displays the contents of directories. The user can navigate within the file system and select a single
* file whose path is then returned to the calling activity. The ordering of directory contents can be specified via
* {@link #setFileComparator(Comparator)}. By default subfolders and files are grouped and each group is ordered
* alphabetically.
* <p>
* A {@link FileFilter} can be activated via {@link #setFileDisplayFilter(FileFilter)} to restrict the displayed files
* and folders. By default all files and folders are visible.
* <p>
* Another <code>FileFilter</code> can be applied via {@link #setFileSelectFilter(ValidFileFilter)} to check if a
* selected file is valid before its path is returned. By default all files are considered as valid and can be selected.
*/
public class FilePicker extends Activity implements AdapterView.OnItemClickListener {
/**
* The name of the extra data in the result {@link Intent}.
*/
public static final String SELECTED_FILE = "selectedFile";
private static final String CURRENT_DIRECTORY = "currentDirectory";
private static final String DEFAULT_DIRECTORY = "/";
private static final int DIALOG_FILE_INVALID = 0;
// private static final int DIALOG_FILE_SELECT = 1;
private static Comparator<File> fileComparator = getDefaultFileComparator();
private static FileFilter fileDisplayFilter;
private static ValidFileFilter fileSelectFilter;
private static final String PREFERENCES_FILE = "FilePicker";
/**
* Sets the file comparator which is used to order the contents of all directories before displaying them. If set to
* null, subfolders and files will not be ordered.
*
* @param fileComparator
* the file comparator (may be null).
*/
public static void setFileComparator(Comparator<File> fileComparator) {
FilePicker.fileComparator = fileComparator;
}
/**
* Sets the file display filter. This filter is used to determine which files and subfolders of directories will be
* displayed. If set to null, all files and subfolders are shown.
*
* @param fileDisplayFilter
* the file display filter (may be null).
*/
public static void setFileDisplayFilter(FileFilter fileDisplayFilter) {
FilePicker.fileDisplayFilter = fileDisplayFilter;
}
/**
* Sets the file select filter. This filter is used when the user selects a file to determine if it is valid. If set
* to null, all files are considered as valid.
*
* @param fileSelectFilter
* the file selection filter (may be null).
*/
public static void setFileSelectFilter(ValidFileFilter fileSelectFilter) {
FilePicker.fileSelectFilter = fileSelectFilter;
}
/**
* Creates the default file comparator.
*
* @return the default file comparator.
*/
private static Comparator<File> getDefaultFileComparator() {
// order all files by type and alphabetically by name
return new Comparator<File>() {
@Override
public int compare(File file1, File file2) {
if (file1.isDirectory() && !file2.isDirectory()) {
return -1;
} else if (!file1.isDirectory() && file2.isDirectory()) {
return 1;
} else {
return file1.getName().compareToIgnoreCase(file2.getName());
}
}
};
}
private File currentDirectory;
private FilePickerIconAdapter filePickerIconAdapter;
private File[] files;
private File[] filesWithParentFolder;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
File selectedFile = this.files[(int) id];
if (selectedFile.isDirectory()) {
this.currentDirectory = selectedFile;
browseToCurrentDirectory();
} else if (fileSelectFilter == null || fileSelectFilter.accept(selectedFile)) {
setResult(RESULT_OK,
new Intent().putExtra(SELECTED_FILE, selectedFile.getAbsolutePath()));
finish();
} else {
showDialog(DIALOG_FILE_INVALID);
}
}
/**
* Browses to the current directory.
*/
private void browseToCurrentDirectory() {
setTitle(this.currentDirectory.getAbsolutePath());
// read the subfolders and files from the current directory
if (fileDisplayFilter == null) {
this.files = this.currentDirectory.listFiles();
} else {
this.files = this.currentDirectory.listFiles(fileDisplayFilter);
}
if (this.files == null) {
this.files = new File[0];
} else {
// order the subfolders and files
Arrays.sort(this.files, fileComparator);
}
// if a parent directory exists, add it at the first position
if (this.currentDirectory.getParentFile() != null) {
this.filesWithParentFolder = new File[this.files.length + 1];
this.filesWithParentFolder[0] = this.currentDirectory.getParentFile();
System.arraycopy(this.files, 0, this.filesWithParentFolder, 1,
this.files.length);
this.files = this.filesWithParentFolder;
this.filePickerIconAdapter.setFiles(this.files, true);
} else {
this.filePickerIconAdapter.setFiles(this.files, false);
}
this.filePickerIconAdapter.notifyDataSetChanged();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_picker);
this.filePickerIconAdapter = new FilePickerIconAdapter(this);
GridView gridView = (GridView) findViewById(R.id.filePickerView);
gridView.setOnItemClickListener(this);
gridView.setAdapter(this.filePickerIconAdapter);
// if (savedInstanceState == null) {
// // first start of this instance
// showDialog(DIALOG_FILE_SELECT);
// }
}
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
switch (id) {
case DIALOG_FILE_INVALID:
builder.setIcon(android.R.drawable.ic_menu_info_details);
builder.setTitle(R.string.error);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(getString(R.string.file_invalid));
stringBuilder.append("\n\n");
stringBuilder.append(FilePicker.fileSelectFilter.getFileOpenResult()
.getErrorMessage());
builder.setMessage(stringBuilder.toString());
builder.setPositiveButton(R.string.ok, null);
return builder.create();
// case DIALOG_FILE_SELECT:
// builder.setMessage(R.string.file_select);
// builder.setPositiveButton(R.string.ok, null);
// return builder.create();
default:
// do dialog will be created
return null;
}
}
@Override
protected void onPause() {
super.onPause();
// save the current directory
Editor editor = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE).edit();
editor.clear();
if (this.currentDirectory != null) {
editor.putString(CURRENT_DIRECTORY, this.currentDirectory.getAbsolutePath());
}
editor.commit();
}
@TargetApi(11)
@Override
protected void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
getActionBar().hide();
// check if the full screen mode should be activated
// if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen",
// false)) {
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// } else {
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// }
// restore the current directory
SharedPreferences preferences = getSharedPreferences(PREFERENCES_FILE,
MODE_PRIVATE);
this.currentDirectory = new File(preferences.getString(CURRENT_DIRECTORY,
DEFAULT_DIRECTORY));
if (!this.currentDirectory.exists() || !this.currentDirectory.canRead()) {
this.currentDirectory = new File(DEFAULT_DIRECTORY);
}
browseToCurrentDirectory();
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.filepicker;
import java.io.File;
import org.oscim.app.R;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* An adapter for the FilePicker GridView.
*/
class FilePickerIconAdapter extends BaseAdapter {
private final Context context;
private File currentFile;
private File[] files;
private boolean hasParentFolder;
private TextView textView;
/**
* Creates a new FilePickerIconAdapter with the given context.
*
* @param context
* the context of this adapter, through which new Views are created.
*/
FilePickerIconAdapter(Context context) {
super();
this.context = context;
}
@Override
public int getCount() {
if (this.files == null) {
return 0;
}
return this.files.length;
}
@Override
public Object getItem(int index) {
return this.files[index];
}
@Override
public long getItemId(int index) {
return index;
}
@Override
public View getView(int index, View convertView, ViewGroup parent) {
if (convertView instanceof TextView) {
// recycle the old view
this.textView = (TextView) convertView;
} else {
// create a new view object
this.textView = new TextView(this.context);
this.textView.setLines(2);
this.textView.setGravity(Gravity.CENTER_HORIZONTAL);
this.textView.setPadding(5, 10, 5, 10);
}
if (index == 0 && this.hasParentFolder) {
// the parent directory of the current folder
this.textView.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.file_picker_back, 0, 0);
this.textView.setText("..");
} else {
this.currentFile = this.files[index];
if (this.currentFile.isDirectory()) {
this.textView.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.file_picker_folder, 0, 0);
} else {
this.textView.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.file_picker_file, 0, 0);
}
this.textView.setText(this.currentFile.getName());
}
return this.textView;
}
/**
* Sets the data of this adapter.
*
* @param files
* the new files for this adapter.
* @param newHasParentFolder
* true if the file array has a parent folder at index 0, false otherwise.
*/
void setFiles(File[] files, boolean newHasParentFolder) {
this.files = files.clone();
this.hasParentFolder = newHasParentFolder;
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.preferences;
import org.oscim.app.R;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
/**
* Activity to edit the application preferences.
*/
public class EditPreferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
@TargetApi(11)
@Override
protected void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
getActionBar().hide();
// check if the full screen mode should be activated
// if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen",
// false)) {
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// } else {
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// }
}
}

View File

@@ -0,0 +1,154 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.app.preferences;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.DialogPreference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
/**
* This abstract class provides all code for a seek bar preference. Deriving classes only need to set the current and
* maximum value of the seek bar. An optional text message above the seek bar is also supported as well as an optional
* current value message below the seek bar.
*/
abstract class SeekBarPreference extends DialogPreference implements OnSeekBarChangeListener {
private TextView currentValueTextView;
private Editor editor;
private SeekBar preferenceSeekBar;
/**
* How much the value should increase when the seek bar is moved.
*/
int increment = 1;
/**
* The maximum value of the seek bar.
*/
int max;
/**
* Optional text message to display on top of the seek bar.
*/
String messageText;
/**
* The SharedPreferences instance that is used.
*/
final SharedPreferences preferencesDefault;
/**
* The current value of the seek bar.
*/
int seekBarCurrentValue;
/**
* Create a new seek bar preference.
*
* @param context
* the context of the seek bar preferences activity.
* @param attrs
* A set of attributes (currently ignored).
*/
SeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
this.preferencesDefault = PreferenceManager.getDefaultSharedPreferences(context);
}
@Override
public void onClick(DialogInterface dialog, int which) {
// check if the "OK" button was pressed and the seek bar value has changed
if (which == DialogInterface.BUTTON_POSITIVE
&& this.seekBarCurrentValue != this.preferenceSeekBar.getProgress()) {
// get the value of the seek bar and save it in the preferences
this.seekBarCurrentValue = this.preferenceSeekBar.getProgress();
this.editor = this.preferencesDefault.edit();
this.editor.putInt(this.getKey(), this.seekBarCurrentValue);
this.editor.commit();
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (this.currentValueTextView != null) {
this.currentValueTextView.setText(getCurrentValueText(progress));
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// do nothing
}
@Override
protected View onCreateDialogView() {
// create a layout for the optional text messageText and the seek bar
LinearLayout linearLayout = new LinearLayout(getContext());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(20, 10, 20, 10);
// check if a text message should appear above the seek bar
if (this.messageText != null) {
// create a text view for the text messageText
TextView messageTextView = new TextView(getContext());
messageTextView.setText(this.messageText);
messageTextView.setPadding(0, 0, 0, 20);
// add the text message view to the layout
linearLayout.addView(messageTextView);
}
// create the seek bar and set the maximum and current value
this.preferenceSeekBar = new SeekBar(getContext());
this.preferenceSeekBar.setOnSeekBarChangeListener(this);
this.preferenceSeekBar.setMax(this.max);
this.preferenceSeekBar.setProgress(Math.min(this.seekBarCurrentValue, this.max));
this.preferenceSeekBar.setKeyProgressIncrement(this.increment);
this.preferenceSeekBar.setPadding(0, 0, 0, 10);
// add the seek bar to the layout
linearLayout.addView(this.preferenceSeekBar);
// create the text view for the current value below the seek bar
this.currentValueTextView = new TextView(getContext());
this.currentValueTextView.setText(getCurrentValueText(this.preferenceSeekBar.getProgress()));
this.currentValueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
// add the current value text view to the layout
linearLayout.addView(this.currentValueTextView);
return linearLayout;
}
/**
* Get the current value text.
*
* @param progress
* the current progress level of the seek bar.
* @return the new current value text
*/
abstract String getCurrentValueText(int progress);
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
/**
* A BoundingBox represents an immutable set of two latitude and two longitude coordinates.
*/
public class BoundingBox implements Serializable {
/**
* Conversion factor from degrees to microdegrees.
*/
private static final double CONVERSION_FACTOR = 1000000d;
private static final long serialVersionUID = 1L;
private static boolean isBetween(int number, int min, int max) {
return min <= number && number <= max;
}
/**
* The maximum latitude value of this BoundingBox in microdegrees (degrees * 10^6).
*/
public final int maxLatitudeE6;
/**
* The maximum longitude value of this BoundingBox in microdegrees (degrees * 10^6).
*/
public final int maxLongitudeE6;
/**
* The minimum latitude value of this BoundingBox in microdegrees (degrees * 10^6).
*/
public final int minLatitudeE6;
/**
* The minimum longitude value of this BoundingBox in microdegrees (degrees * 10^6).
*/
public final int minLongitudeE6;
/**
* The hash code of this object.
*/
private transient int hashCodeValue;
/**
* @param minLatitudeE6
* the minimum latitude in microdegrees (degrees * 10^6).
* @param minLongitudeE6
* the minimum longitude in microdegrees (degrees * 10^6).
* @param maxLatitudeE6
* the maximum latitude in microdegrees (degrees * 10^6).
* @param maxLongitudeE6
* the maximum longitude in microdegrees (degrees * 10^6).
*/
public BoundingBox(int minLatitudeE6, int minLongitudeE6, int maxLatitudeE6, int maxLongitudeE6) {
this.minLatitudeE6 = minLatitudeE6;
this.minLongitudeE6 = minLongitudeE6;
this.maxLatitudeE6 = maxLatitudeE6;
this.maxLongitudeE6 = maxLongitudeE6;
this.hashCodeValue = calculateHashCode();
}
/**
* @param geoPoint
* the point whose coordinates should be checked.
* @return true if this BoundingBox contains the given GeoPoint, false otherwise.
*/
public boolean contains(GeoPoint geoPoint) {
return isBetween(geoPoint.latitudeE6, this.minLatitudeE6, this.maxLatitudeE6)
&& isBetween(geoPoint.longitudeE6, this.minLongitudeE6, this.maxLongitudeE6);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof BoundingBox)) {
return false;
}
BoundingBox other = (BoundingBox) obj;
if (this.maxLatitudeE6 != other.maxLatitudeE6) {
return false;
} else if (this.maxLongitudeE6 != other.maxLongitudeE6) {
return false;
} else if (this.minLatitudeE6 != other.minLatitudeE6) {
return false;
} else if (this.minLongitudeE6 != other.minLongitudeE6) {
return false;
}
return true;
}
/**
* @return the GeoPoint at the horizontal and vertical center of this BoundingBox.
*/
public GeoPoint getCenterPoint() {
int latitudeOffset = (this.maxLatitudeE6 - this.minLatitudeE6) / 2;
int longitudeOffset = (this.maxLongitudeE6 - this.minLongitudeE6) / 2;
return new GeoPoint(this.minLatitudeE6 + latitudeOffset, this.minLongitudeE6 + longitudeOffset);
}
/**
* @return the maximum latitude value of this BoundingBox in degrees.
*/
public double getMaxLatitude() {
return this.maxLatitudeE6 / CONVERSION_FACTOR;
}
/**
* @return the maximum longitude value of this BoundingBox in degrees.
*/
public double getMaxLongitude() {
return this.maxLongitudeE6 / CONVERSION_FACTOR;
}
/**
* @return the minimum latitude value of this BoundingBox in degrees.
*/
public double getMinLatitude() {
return this.minLatitudeE6 / CONVERSION_FACTOR;
}
/**
* @return the minimum longitude value of this BoundingBox in degrees.
*/
public double getMinLongitude() {
return this.minLongitudeE6 / CONVERSION_FACTOR;
}
@Override
public int hashCode() {
return this.hashCodeValue;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("BoundingBox [minLatitudeE6=");
stringBuilder.append(this.minLatitudeE6);
stringBuilder.append(", minLongitudeE6=");
stringBuilder.append(this.minLongitudeE6);
stringBuilder.append(", maxLatitudeE6=");
stringBuilder.append(this.maxLatitudeE6);
stringBuilder.append(", maxLongitudeE6=");
stringBuilder.append(this.maxLongitudeE6);
stringBuilder.append("]");
return stringBuilder.toString();
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + this.maxLatitudeE6;
result = 31 * result + this.maxLongitudeE6;
result = 31 * result + this.minLatitudeE6;
result = 31 * result + this.minLongitudeE6;
return result;
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
objectInputStream.defaultReadObject();
this.hashCodeValue = calculateHashCode();
}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
* A GeoPoint represents an immutable pair of latitude and longitude coordinates.
*/
public class GeoPoint implements Comparable<GeoPoint> {
/**
* Conversion factor from degrees to microdegrees.
*/
private static final double CONVERSION_FACTOR = 1000000d;
/**
* The latitude value of this GeoPoint in microdegrees (degrees * 10^6).
*/
public final int latitudeE6;
/**
* The longitude value of this GeoPoint in microdegrees (degrees * 10^6).
*/
public final int longitudeE6;
/**
* The hash code of this object.
*/
private int hashCodeValue = 0;
/**
* @param latitude
* the latitude in degrees, will be limited to the possible latitude range.
* @param longitude
* the longitude in degrees, will be limited to the possible longitude range.
*/
public GeoPoint(double latitude, double longitude) {
double limitLatitude = MercatorProjection.limitLatitude(latitude);
this.latitudeE6 = (int) (limitLatitude * CONVERSION_FACTOR);
double limitLongitude = MercatorProjection.limitLongitude(longitude);
this.longitudeE6 = (int) (limitLongitude * CONVERSION_FACTOR);
}
/**
* @param latitudeE6
* the latitude in microdegrees (degrees * 10^6), will be limited to the possible latitude range.
* @param longitudeE6
* the longitude in microdegrees (degrees * 10^6), will be limited to the possible longitude range.
*/
public GeoPoint(int latitudeE6, int longitudeE6) {
this(latitudeE6 / CONVERSION_FACTOR, longitudeE6 / CONVERSION_FACTOR);
}
@Override
public int compareTo(GeoPoint geoPoint) {
if (this.longitudeE6 > geoPoint.longitudeE6) {
return 1;
} else if (this.longitudeE6 < geoPoint.longitudeE6) {
return -1;
} else if (this.latitudeE6 > geoPoint.latitudeE6) {
return 1;
} else if (this.latitudeE6 < geoPoint.latitudeE6) {
return -1;
}
return 0;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof GeoPoint)) {
return false;
}
GeoPoint other = (GeoPoint) obj;
if (this.latitudeE6 != other.latitudeE6) {
return false;
} else if (this.longitudeE6 != other.longitudeE6) {
return false;
}
return true;
}
/**
* @return the latitude value of this GeoPoint in degrees.
*/
public double getLatitude() {
return this.latitudeE6 / CONVERSION_FACTOR;
}
/**
* @return the longitude value of this GeoPoint in degrees.
*/
public double getLongitude() {
return this.longitudeE6 / CONVERSION_FACTOR;
}
@Override
public int hashCode() {
if (this.hashCodeValue == 0)
this.hashCodeValue = calculateHashCode();
return this.hashCodeValue;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("GeoPoint [latitudeE6=");
stringBuilder.append(this.latitudeE6);
stringBuilder.append(", longitudeE6=");
stringBuilder.append(this.longitudeE6);
stringBuilder.append("]");
return stringBuilder.toString();
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + this.latitudeE6;
result = 31 * result + this.longitudeE6;
return result;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* An LRUCache with a fixed size and an access-order policy. Old mappings are automatically removed from the cache when
* new mappings are added. This implementation uses an {@link LinkedHashMap} internally.
*
* @param <K>
* the type of the map key, see {@link Map}.
* @param <V>
* the type of the map value, see {@link Map}.
*/
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
private static final float LOAD_FACTOR = 0.6f;
private static final long serialVersionUID = 1L;
private static int calculateInitialCapacity(int capacity) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity must not be negative: " + capacity);
}
return (int) (capacity / LOAD_FACTOR) + 2;
}
private final int capacity;
/**
* @param capacity
* the maximum capacity of this cache.
* @throws IllegalArgumentException
* if the capacity is negative.
*/
public LRUCache(int capacity) {
super(calculateInitialCapacity(capacity), LOAD_FACTOR, true);
this.capacity = capacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > this.capacity;
}
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
* A MapPosition represents an immutable pair of {@link GeoPoint} and zoom level.
*/
public class MapPosition {
/**
* The map position.
*/
// public final GeoPoint geoPoint;
public final double lon;
public final double lat;
/**
* The zoom level.
*/
public final byte zoomLevel;
/**
* 1.0 - 2.0 scale of current zoomlevel
*/
public final float scale;
public final float angle;
public final double x;
public final double y;
public MapPosition() {
this.zoomLevel = (byte) 1;
this.scale = 1;
this.lat = 0;
this.lon = 0;
this.angle = 0;
this.x = MercatorProjection.longitudeToPixelX(this.lon, zoomLevel);
this.y = MercatorProjection.latitudeToPixelY(this.lat, zoomLevel);
}
/**
* @param geoPoint
* the map position.
* @param zoomLevel
* the zoom level.
* @param scale
* ...
*/
public MapPosition(GeoPoint geoPoint, byte zoomLevel, float scale) {
// this.geoPoint = geoPoint;
this.zoomLevel = zoomLevel;
this.scale = scale;
this.lat = geoPoint.getLatitude();
this.lon = geoPoint.getLongitude();
this.angle = 0;
this.x = MercatorProjection.longitudeToPixelX(this.lon, zoomLevel);
this.y = MercatorProjection.latitudeToPixelY(this.lat, zoomLevel);
}
public MapPosition(double latitude, double longitude, byte zoomLevel, float scale,
float angle) {
this.zoomLevel = zoomLevel;
this.scale = scale;
this.lat = latitude;
this.lon = longitude;
this.angle = angle;
this.x = MercatorProjection.longitudeToPixelX(longitude, zoomLevel);
this.y = MercatorProjection.latitudeToPixelY(latitude, zoomLevel);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MapPosition [geoPoint=");
builder.append("lat");
builder.append(this.lat);
builder.append("lon");
builder.append(this.lon);
builder.append(", zoomLevel=");
builder.append(this.zoomLevel);
builder.append("]");
return builder.toString();
}
}

View File

@@ -0,0 +1,237 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
* An implementation of the spherical Mercator projection.
*/
public final class MercatorProjection {
/**
* The circumference of the earth at the equator in meters.
*/
public static final double EARTH_CIRCUMFERENCE = 40075016.686;
/**
* Maximum possible latitude coordinate of the map.
*/
public static final double LATITUDE_MAX = 85.05112877980659;
/**
* Minimum possible latitude coordinate of the map.
*/
public static final double LATITUDE_MIN = -LATITUDE_MAX;
/**
* Maximum possible longitude coordinate of the map.
*/
public static final double LONGITUDE_MAX = 180;
/**
* Minimum possible longitude coordinate of the map.
*/
public static final double LONGITUDE_MIN = -LONGITUDE_MAX;
/**
* Calculates the distance on the ground that is represented by a single pixel on the map.
*
* @param latitude
* the latitude coordinate at which the resolution should be calculated.
* @param zoomLevel
* the zoom level at which the resolution should be calculated.
* @return the ground resolution at the given latitude and zoom level.
*/
public static double calculateGroundResolution(double latitude, byte zoomLevel) {
return Math.cos(latitude * (Math.PI / 180)) * EARTH_CIRCUMFERENCE
/ ((long) Tile.TILE_SIZE << zoomLevel);
}
/**
* Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain zoom level.
*
* @param latitude
* the latitude coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the pixel Y coordinate of the latitude value.
*/
public static double latitudeToPixelY(double latitude, byte zoomLevel) {
double sinLatitude = Math.sin(latitude * (Math.PI / 180));
return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI))
* ((long) Tile.TILE_SIZE << zoomLevel);
}
public static double latitudeToPixelY(MapPosition mapPosition) {
double sinLatitude = Math.sin(mapPosition.lat * (Math.PI / 180));
return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI))
* ((long) Tile.TILE_SIZE << mapPosition.zoomLevel);
}
/**
* Converts a latitude coordinate (in degrees) to a tile Y number at a certain zoom level.
*
* @param latitude
* the latitude coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the tile Y number of the latitude value.
*/
public static long latitudeToTileY(double latitude, byte zoomLevel) {
return pixelYToTileY(latitudeToPixelY(latitude, zoomLevel), zoomLevel);
}
/**
* @param latitude
* the latitude value which should be checked.
* @return the given latitude value, limited to the possible latitude range.
*/
public static double limitLatitude(double latitude) {
return Math.max(Math.min(latitude, LATITUDE_MAX), LATITUDE_MIN);
}
/**
* @param longitude
* the longitude value which should be checked.
* @return the given longitude value, limited to the possible longitude range.
*/
public static double limitLongitude(double longitude) {
return Math.max(Math.min(longitude, LONGITUDE_MAX), LONGITUDE_MIN);
}
public static double wrapLongitude(double longitude) {
if (longitude < -180)
return Math.max(Math.min(360 + longitude, LONGITUDE_MAX), LONGITUDE_MIN);
else if (longitude > 180)
return Math.max(Math.min(longitude - 360, LONGITUDE_MAX), LONGITUDE_MIN);
return longitude;
}
/**
* Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain zoom level.
*
* @param longitude
* the longitude coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the pixel X coordinate of the longitude value.
*/
public static double longitudeToPixelX(double longitude, byte zoomLevel) {
return (longitude + 180) / 360 * ((long) Tile.TILE_SIZE << zoomLevel);
}
public static double longitudeToPixelX(MapPosition mapPosition) {
return (mapPosition.lon + 180) / 360
* ((long) Tile.TILE_SIZE << mapPosition.zoomLevel);
}
/**
* Converts a longitude coordinate (in degrees) to the tile X number at a certain zoom level.
*
* @param longitude
* the longitude coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the tile X number of the longitude value.
*/
public static long longitudeToTileX(double longitude, byte zoomLevel) {
return pixelXToTileX(longitudeToPixelX(longitude, zoomLevel), zoomLevel);
}
/**
* Converts a pixel X coordinate at a certain zoom level to a longitude coordinate.
*
* @param pixelX
* the pixel X coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the longitude value of the pixel X coordinate.
*/
public static double pixelXToLongitude(double pixelX, byte zoomLevel) {
return 360 * ((pixelX / ((long) Tile.TILE_SIZE << zoomLevel)) - 0.5);
}
/**
* Converts a pixel X coordinate to the tile X number.
*
* @param pixelX
* the pixel X coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the tile X number.
*/
public static int pixelXToTileX(double pixelX, byte zoomLevel) {
return (int) Math.min(Math.max(pixelX / Tile.TILE_SIZE, 0),
Math.pow(2, zoomLevel) - 1);
}
/**
* Converts a pixel Y coordinate at a certain zoom level to a latitude coordinate.
*
* @param pixelY
* the pixel Y coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the latitude value of the pixel Y coordinate.
*/
public static double pixelYToLatitude(double pixelY, byte zoomLevel) {
double y = 0.5 - (pixelY / ((long) Tile.TILE_SIZE << zoomLevel));
return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
}
/**
* Converts a pixel Y coordinate to the tile Y number.
*
* @param pixelY
* the pixel Y coordinate that should be converted.
* @param zoomLevel
* the zoom level at which the coordinate should be converted.
* @return the tile Y number.
*/
public static int pixelYToTileY(double pixelY, byte zoomLevel) {
return (int) Math.min(Math.max(pixelY / Tile.TILE_SIZE, 0),
Math.pow(2, zoomLevel) - 1);
}
/**
* Converts a tile X number at a certain zoom level to a longitude coordinate.
*
* @param tileX
* the tile X number that should be converted.
* @param zoomLevel
* the zoom level at which the number should be converted.
* @return the longitude value of the tile X number.
*/
public static double tileXToLongitude(long tileX, byte zoomLevel) {
return pixelXToLongitude(tileX * Tile.TILE_SIZE, zoomLevel);
}
/**
* Converts a tile Y number at a certain zoom level to a latitude coordinate.
*
* @param tileY
* the tile Y number that should be converted.
* @param zoomLevel
* the zoom level at which the number should be converted.
* @return the latitude value of the tile Y number.
*/
public static double tileYToLatitude(long tileY, byte zoomLevel) {
return pixelYToLatitude(tileY * Tile.TILE_SIZE, zoomLevel);
}
private MercatorProjection() {
throw new IllegalStateException();
}
}

153
src/org/oscim/core/Tag.java Normal file
View File

@@ -0,0 +1,153 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
* A tag represents an immutable key-value pair.
*/
public class Tag {
private static final char KEY_VALUE_SEPARATOR = '=';
/**
* The key of the house number OpenStreetMap tag.
*/
public static final String TAG_KEY_HOUSE_NUMBER = "addr:housenumber";
/**
* The key of the name OpenStreetMap tag.
*/
public static final String TAG_KEY_NAME = "name";
/**
* The key of the reference OpenStreetMap tag.
*/
public static final String TAG_KEY_REF = "ref";
/**
* The key of the elevation OpenStreetMap tag.
*/
public static final String TAG_KEY_ELE = "ele";
/**
* The key of this tag.
*/
public final String key;
/**
* The value of this tag.
*/
public String value;
private transient int hashCodeValue = 0;
/**
* @param tag
* the textual representation of the tag.
*/
public Tag(String tag) {
int splitPosition = tag.indexOf(KEY_VALUE_SEPARATOR);
if (splitPosition < 0) {
System.out.println("TAG:" + tag);
}
this.key = tag.substring(0, splitPosition).intern();
this.value = tag.substring(splitPosition + 1).intern();
}
public Tag(String tag, boolean hashValue) {
int splitPosition = tag.indexOf(KEY_VALUE_SEPARATOR);
if (splitPosition < 0) {
System.out.println("TAG:" + tag);
}
this.key = tag.substring(0, splitPosition).intern();
if (!hashValue)
this.value = tag.substring(splitPosition + 1);
else
this.value = tag.substring(splitPosition + 1).intern();
}
/**
* @param key
* the key of the tag.
* @param value
* the value of the tag.
*/
public Tag(String key, String value) {
this.key = (key == null ? null : key.intern());
this.value = (value == null ? null : value.intern());
}
/**
* @param key
* the key of the tag.
* @param value
* the value of the tag.
* @param intern
* true when string should be intern()alized.
*/
public Tag(String key, String value, boolean intern) {
if (intern) {
this.key = (key == null ? null : key.intern());
this.value = (value == null ? null : value.intern());
}
else {
this.key = (key == null ? null : key);
this.value = (value == null ? null : value);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof Tag)) {
return false;
}
Tag other = (Tag) obj;
if ((this.key == other.key) && (this.value == other.value))
return true;
return false;
}
@Override
public int hashCode() {
if (this.hashCodeValue == 0)
this.hashCodeValue = calculateHashCode();
return this.hashCodeValue;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Tag [key=");
stringBuilder.append(this.key);
stringBuilder.append(", value=");
stringBuilder.append(this.value);
stringBuilder.append("]");
return stringBuilder.toString();
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + ((this.key == null) ? 0 : this.key.hashCode());
result = 31 * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
* A tile represents a rectangular part of the world map. All tiles can be identified by their X and Y number together
* with their zoom level. The actual area that a tile covers on a map depends on the underlying map projection.
*/
public class Tile {
/**
* Width and height of a map tile in pixel.
*/
public static int TILE_SIZE = 256;
/**
* The X number of this tile.
*/
public final int tileX;
/**
* The Y number of this tile.
*/
public final int tileY;
/**
* The Zoom level of this tile.
*/
public final byte zoomLevel;
/**
* the pixel X coordinate of the upper left corner of this tile.
*/
public final long pixelX;
/**
* the pixel Y coordinate of the upper left corner of this tile.
*/
public final long pixelY;
/**
* @param tileX
* the X number of the tile.
* @param tileY
* the Y number of the tile.
* @param zoomLevel
* the zoom level of the tile.
*/
public Tile(int tileX, int tileY, byte zoomLevel) {
this.tileX = tileX;
this.tileY = tileY;
this.pixelX = this.tileX * TILE_SIZE;
this.pixelY = this.tileY * TILE_SIZE;
this.zoomLevel = zoomLevel;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Tile [tileX=");
stringBuilder.append(this.tileX);
stringBuilder.append(", tileY=");
stringBuilder.append(this.tileY);
stringBuilder.append(", zoomLevel=");
stringBuilder.append(this.zoomLevel);
stringBuilder.append("]");
return stringBuilder.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Tile))
return false;
Tile o = (Tile) obj;
if (o.tileX == this.tileX && o.tileY == this.tileY
&& o.zoomLevel == this.zoomLevel)
return true;
return false;
}
private int mHash = 0;
@Override
public int hashCode() {
if (mHash == 0) {
int result = 7;
result = 31 * result + this.tileX;
result = 31 * result + this.tileY;
result = 31 * result + this.zoomLevel;
mHash = result;
}
return mHash;
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General 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 License for more details.
*
* You should have received a copy of the GNU Lesser General License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
*
*/
public class WebMercator {
/**
*
*/
public static final String NAME = "SphericalMercator";
private static final double f900913 = 20037508.342789244;
private static final double f900913_2 = 20037508.342789244 * 2;
/**
* @param lon
* ...
* @param z
* ...
* @param offset
* ...
* @return ...
*/
public static float sphericalMercatorToPixelX(float lon, long z, long offset) {
return (float) (((lon + f900913) / f900913_2) * z - offset);
}
/**
* @param lat
* ...
* @param z
* ...
* @param offset
* ...
* @return ...
*/
public static float sphericalMercatorToPixelY(float lat, long z, long offset) {
return (float) (((lat + f900913) / f900913_2) * z
- (z - offset));
}
/**
* @param pixelY
* ...
* @param z
* ...
* @return ...
*/
public static double PixelYtoSphericalMercator(long pixelY, byte z) {
long half = (Tile.TILE_SIZE << z) >> 1;
return ((half - pixelY) / (double) half) * f900913;
}
/**
* @param pixelX
* ...
* @param z
* ...
* @return ...
*/
public static double PixelXtoSphericalMercator(long pixelX, byte z) {
long half = (Tile.TILE_SIZE << z) >> 1;
return ((pixelX - half) / (double) half) * f900913;
}
private static double radius = 6378137;
private static double D2R = Math.PI / 180;
private static double HALF_PI = Math.PI / 2;
/**
* from http://pauldendulk.com/2011/04/projecting-from-wgs84-to.html
*
* @param lon
* ...
* @param lat
* ...
* @return ...
*/
public static float[] fromLonLat(double lon, double lat)
{
double lonRadians = (D2R * lon);
double latRadians = (D2R * lat);
double x = radius * lonRadians;
double y = radius * Math.log(Math.tan(Math.PI * 0.25 + latRadians * 0.5));
float[] result = { (float) x, (float) y };
return result;
}
/**
* from http://pauldendulk.com/2011/04/projecting-from-wgs84-to.html
*
* @param x
* ...
* @param y
* ...
* @return ...
*/
public static float[] toLonLat(double x, double y)
{
double ts;
ts = Math.exp(-y / (radius));
double latRadians = HALF_PI - 2 * Math.atan(ts);
double lonRadians = x / (radius);
double lon = (lonRadians / D2R);
double lat = (latRadians / D2R);
float[] result = { (float) lon, (float) lat };
return result;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import java.util.Map;
import org.oscim.view.mapgenerator.JobTile;
/**
*
*
*/
public interface IMapDatabase {
/**
* Starts a database query with the given parameters.
*
* @param tile
* the tile to read.
* @param mapDatabaseCallback
* the callback which handles the extracted map elements.
* @return true if successful
*/
public abstract QueryResult executeQuery(JobTile tile,
IMapDatabaseCallback mapDatabaseCallback);
/**
* @return the metadata for the current map file.
* @throws IllegalStateException
* if no map is currently opened.
*/
public abstract MapInfo getMapInfo();
/**
* @return true if a map database is currently opened, false otherwise.
*/
public abstract boolean isOpen();
/**
* Opens MapDatabase
*
* @param options
* the options.
* @return a OpenResult containing an error message in case of a failure.
*/
public abstract OpenResult open(Map<String, String> options);
/**
* Closes the map file and destroys all internal caches. Has no effect if no map file is currently opened.
*/
public abstract void close();
public abstract String getMapProjection();
/**
* Cancel loading
*/
public abstract void cancel();
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import org.oscim.core.Tag;
import org.oscim.database.mapfile.MapDatabase;
/**
* Callback methods which can be triggered from the {@link MapDatabase}.
*/
public interface IMapDatabaseCallback {
/**
* Renders a single point of interest node (POI).
*
* @param layer
* the layer of the node.
* @param latitude
* the latitude of the node.
* @param longitude
* the longitude of the node.
* @param tags
* the tags of the node.
*/
void renderPointOfInterest(byte layer, float latitude, float longitude, Tag[] tags);
/**
* Renders water background for the current tile.
*/
void renderWaterBackground();
/**
* Renders a single way or area (closed way).
*
* @param layer
* the layer of the way.
* @param tags
* the tags of the way.
* @param wayNodes
* the geographical coordinates of the way nodes in the order longitude/latitude.
* @param wayLength
* length of way data in wayNodes
* @param changed
* tags have changed since last call (just an optional hint)
*/
void renderWay(byte layer, Tag[] tags, float[] wayNodes, short[] wayLength,
boolean changed);
boolean checkWay(Tag[] tags, boolean closed);
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
public interface IMapTileData {
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import android.util.AttributeSet;
/**
*
*
*/
public final class MapDatabaseFactory {
private static final String MAP_DATABASE_ATTRIBUTE_NAME = "mapDatabase";
/**
* @param attributeSet
* A collection of attributes which includes the desired MapGenerator.
* @return a new MapGenerator instance.
*/
public static IMapDatabase createMapDatabase(AttributeSet attributeSet) {
String mapDatabaseName = attributeSet.getAttributeValue(null,
MAP_DATABASE_ATTRIBUTE_NAME);
if (mapDatabaseName == null) {
return new org.oscim.database.postgis.MapDatabase();
}
MapDatabases mapDatabaseInternal = MapDatabases.valueOf(mapDatabaseName);
return MapDatabaseFactory.createMapDatabase(mapDatabaseInternal);
}
public static MapDatabases getMapDatabase(AttributeSet attributeSet) {
String mapDatabaseName = attributeSet.getAttributeValue(null,
MAP_DATABASE_ATTRIBUTE_NAME);
if (mapDatabaseName == null) {
return MapDatabases.PBMAP_READER;
}
return MapDatabases.valueOf(mapDatabaseName);
}
/**
* @param mapDatabase
* the internal MapDatabase implementation.
* @return a new MapGenerator instance.
*/
public static IMapDatabase createMapDatabase(MapDatabases mapDatabase) {
switch (mapDatabase) {
case MAP_READER:
return new org.oscim.database.mapfile.MapDatabase();
case TEST_READER:
return new org.oscim.database.test.MapDatabase();
case POSTGIS_READER:
return new org.oscim.database.postgis.MapDatabase();
case PBMAP_READER:
return new org.oscim.database.pbmap.MapDatabase();
}
throw new IllegalArgumentException("unknown enum value: " + mapDatabase);
}
private MapDatabaseFactory() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
/**
* MapDatabase Implementations
*/
public enum MapDatabases {
/**
* ...
*/
MAP_READER,
/**
* ...
*/
TEST_READER,
/**
* ...
*/
POSTGIS_READER,
/**
* ...
*/
PBMAP_READER,
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import org.oscim.core.BoundingBox;
import org.oscim.core.GeoPoint;
import org.oscim.database.mapfile.MapDatabase;
/**
* Contains the immutable metadata of a map file.
*
* @see MapDatabase#getMapInfo()
*/
public class MapInfo {
/**
* The bounding box of the map file.
*/
public final BoundingBox boundingBox;
/**
* The comment field of the map file (may be null).
*/
public final String comment;
/**
* The created by field of the map file (may be null).
*/
public final String createdBy;
/**
* The size of the map file, measured in bytes.
*/
public final long fileSize;
/**
* The file version number of the map file.
*/
public final int fileVersion;
/**
* The preferred language for names as defined in ISO 3166-1 (may be null).
*/
public final String languagePreference;
/**
* The center point of the map file.
*/
public final GeoPoint mapCenter;
/**
* The date of the map data in milliseconds since January 1, 1970.
*/
public final long mapDate;
/**
* The name of the projection used in the map file.
*/
public final String projectionName;
/**
* The map start position from the file header (may be null).
*/
public final GeoPoint startPosition;
/**
* The map start zoom level from the file header (may be null).
*/
public final Byte startZoomLevel;
/**
* @param bbox
* ...
* @param zoom
* ...
* @param start
* ...
* @param projection
* ...
* @param date
* ...
* @param size
* ...
* @param version
* ...
* @param language
* ...
* @param comment
* ...
* @param createdBy
* ...
*/
public MapInfo(BoundingBox bbox, Byte zoom, GeoPoint start, String projection,
long date, long size, int version, String language, String comment, String createdBy) {
this.startZoomLevel = zoom;
this.startPosition = start;
this.projectionName = projection;
this.mapDate = date;
this.boundingBox = bbox;
this.mapCenter = bbox.getCenterPoint();
this.languagePreference = language;
this.fileSize = size;
this.fileVersion = version;
this.comment = comment;
this.createdBy = createdBy;
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
/**
* A FileOpenResult is a simple DTO which is returned by IMapDatabase#openFile(File).
*/
public class OpenResult {
/**
* Singleton for a FileOpenResult instance with {@code success=true}.
*/
public static final OpenResult SUCCESS = new OpenResult();
private final String errorMessage;
private final boolean success;
/**
* @param errorMessage
* a textual message describing the error, must not be null.
*/
public OpenResult(String errorMessage) {
if (errorMessage == null) {
throw new IllegalArgumentException("error message must not be null");
}
this.success = false;
this.errorMessage = errorMessage;
}
/**
*
*/
public OpenResult() {
this.success = true;
this.errorMessage = null;
}
/**
* @return a textual error description (might be null).
*/
public String getErrorMessage() {
return this.errorMessage;
}
/**
* @return true if the file could be opened successfully, false otherwise.
*/
public boolean isSuccess() {
return this.success;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("FileOpenResult [success=");
stringBuilder.append(this.success);
stringBuilder.append(", errorMessage=");
stringBuilder.append(this.errorMessage);
stringBuilder.append("]");
return stringBuilder.toString();
}
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
public enum QueryResult {
SUCCESS,
FAILED,
TILE_NOT_FOUND,
DELAYED,
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
/**
* This utility class contains methods to convert byte arrays to numbers.
*/
final class Deserializer {
/**
* Converts five bytes of a byte array to an unsigned long.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the long value.
*/
static long getFiveBytesLong(byte[] buffer, int offset) {
return (buffer[offset] & 0xffL) << 32 | (buffer[offset + 1] & 0xffL) << 24 | (buffer[offset + 2] & 0xffL) << 16
| (buffer[offset + 3] & 0xffL) << 8 | (buffer[offset + 4] & 0xffL);
}
/**
* Converts four bytes of a byte array to a signed int.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the int value.
*/
static int getInt(byte[] buffer, int offset) {
return buffer[offset] << 24 | (buffer[offset + 1] & 0xff) << 16 | (buffer[offset + 2] & 0xff) << 8
| (buffer[offset + 3] & 0xff);
}
/**
* Converts eight bytes of a byte array to a signed long.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the long value.
*/
static long getLong(byte[] buffer, int offset) {
return (buffer[offset] & 0xffL) << 56 | (buffer[offset + 1] & 0xffL) << 48 | (buffer[offset + 2] & 0xffL) << 40
| (buffer[offset + 3] & 0xffL) << 32 | (buffer[offset + 4] & 0xffL) << 24
| (buffer[offset + 5] & 0xffL) << 16 | (buffer[offset + 6] & 0xffL) << 8 | (buffer[offset + 7] & 0xffL);
}
/**
* Converts two bytes of a byte array to a signed int.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the int value.
*/
static int getShort(byte[] buffer, int offset) {
return buffer[offset] << 8 | (buffer[offset + 1] & 0xff);
}
/**
* Private constructor to prevent instantiation from other classes.
*/
private Deserializer() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.oscim.core.LRUCache;
import org.oscim.database.mapfile.header.SubFileParameter;
/**
* A cache for database index blocks with a fixed size and LRU policy.
*/
class IndexCache {
/**
* Number of index entries that one index block consists of.
*/
private static final int INDEX_ENTRIES_PER_BLOCK = 128;
private static final Logger LOG = Logger.getLogger(IndexCache.class.getName());
/**
* Maximum size in bytes of one index block.
*/
private static final int SIZE_OF_INDEX_BLOCK = INDEX_ENTRIES_PER_BLOCK * SubFileParameter.BYTES_PER_INDEX_ENTRY;
private final Map<IndexCacheEntryKey, byte[]> map;
private final RandomAccessFile randomAccessFile;
/**
* @param randomAccessFile
* the map file from which the index should be read and cached.
* @param capacity
* the maximum number of entries in the cache.
* @throws IllegalArgumentException
* if the capacity is negative.
*/
IndexCache(RandomAccessFile randomAccessFile, int capacity) {
this.randomAccessFile = randomAccessFile;
this.map = new LRUCache<IndexCacheEntryKey, byte[]>(capacity);
}
/**
* Destroy the cache at the end of its lifetime.
*/
void destroy() {
this.map.clear();
}
/**
* Returns the index entry of a block in the given map file. If the required index entry is not cached, it will be
* read from the map file index and put in the cache.
*
* @param subFileParameter
* the parameters of the map file for which the index entry is needed.
* @param blockNumber
* the number of the block in the map file.
* @return the index entry or -1 if the block number is invalid.
*/
long getIndexEntry(SubFileParameter subFileParameter, long blockNumber) {
try {
// check if the block number is out of bounds
if (blockNumber >= subFileParameter.numberOfBlocks) {
return -1;
}
// calculate the index block number
long indexBlockNumber = blockNumber / INDEX_ENTRIES_PER_BLOCK;
// create the cache entry key for this request
IndexCacheEntryKey indexCacheEntryKey = new IndexCacheEntryKey(subFileParameter, indexBlockNumber);
// check for cached index block
byte[] indexBlock = this.map.get(indexCacheEntryKey);
if (indexBlock == null) {
// cache miss, seek to the correct index block in the file and read it
long indexBlockPosition = subFileParameter.indexStartAddress + indexBlockNumber * SIZE_OF_INDEX_BLOCK;
int remainingIndexSize = (int) (subFileParameter.indexEndAddress - indexBlockPosition);
int indexBlockSize = Math.min(SIZE_OF_INDEX_BLOCK, remainingIndexSize);
indexBlock = new byte[indexBlockSize];
this.randomAccessFile.seek(indexBlockPosition);
if (this.randomAccessFile.read(indexBlock, 0, indexBlockSize) != indexBlockSize) {
LOG.warning("reading the current index block has failed");
return -1;
}
// put the index block in the map
this.map.put(indexCacheEntryKey, indexBlock);
}
// calculate the address of the index entry inside the index block
long indexEntryInBlock = blockNumber % INDEX_ENTRIES_PER_BLOCK;
int addressInIndexBlock = (int) (indexEntryInBlock * SubFileParameter.BYTES_PER_INDEX_ENTRY);
// return the real index entry
return Deserializer.getFiveBytesLong(indexBlock, addressInIndexBlock);
} catch (IOException e) {
LOG.log(Level.SEVERE, null, e);
return -1;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import org.oscim.database.mapfile.header.SubFileParameter;
/**
* An immutable container class which is the key for the index cache.
*/
class IndexCacheEntryKey {
private final int hashCodeValue;
private final long indexBlockNumber;
private final SubFileParameter subFileParameter;
/**
* Creates an immutable key to be stored in a map.
*
* @param subFileParameter
* the parameters of the map file.
* @param indexBlockNumber
* the number of the index block.
*/
IndexCacheEntryKey(SubFileParameter subFileParameter, long indexBlockNumber) {
this.subFileParameter = subFileParameter;
this.indexBlockNumber = indexBlockNumber;
this.hashCodeValue = calculateHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof IndexCacheEntryKey)) {
return false;
}
IndexCacheEntryKey other = (IndexCacheEntryKey) obj;
if (this.subFileParameter == null && other.subFileParameter != null) {
return false;
} else if (this.subFileParameter != null && !this.subFileParameter.equals(other.subFileParameter)) {
return false;
} else if (this.indexBlockNumber != other.indexBlockNumber) {
return false;
}
return true;
}
@Override
public int hashCode() {
return this.hashCodeValue;
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + ((this.subFileParameter == null) ? 0 : this.subFileParameter.hashCode());
result = 31 * result + (int) (this.indexBlockNumber ^ (this.indexBlockNumber >>> 32));
return result;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import org.oscim.core.Tile;
import org.oscim.database.mapfile.header.SubFileParameter;
final class QueryCalculations {
private static int getFirstLevelTileBitmask(Tile tile) {
if (tile.tileX % 2 == 0 && tile.tileY % 2 == 0) {
// upper left quadrant
return 0xcc00;
} else if (tile.tileX % 2 == 1 && tile.tileY % 2 == 0) {
// upper right quadrant
return 0x3300;
} else if (tile.tileX % 2 == 0 && tile.tileY % 2 == 1) {
// lower left quadrant
return 0xcc;
} else {
// lower right quadrant
return 0x33;
}
}
private static int getSecondLevelTileBitmaskLowerLeft(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x80;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x40;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x8;
} else {
// lower right sub-tile
return 0x4;
}
}
private static int getSecondLevelTileBitmaskLowerRight(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x20;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x10;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x2;
} else {
// lower right sub-tile
return 0x1;
}
}
private static int getSecondLevelTileBitmaskUpperLeft(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x8000;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x4000;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x800;
} else {
// lower right sub-tile
return 0x400;
}
}
private static int getSecondLevelTileBitmaskUpperRight(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x2000;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x1000;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x200;
} else {
// lower right sub-tile
return 0x100;
}
}
static void calculateBaseTiles(QueryParameters queryParameters, Tile tile, SubFileParameter subFileParameter) {
if (tile.zoomLevel < subFileParameter.baseZoomLevel) {
// calculate the XY numbers of the upper left and lower right sub-tiles
int zoomLevelDifference = subFileParameter.baseZoomLevel - tile.zoomLevel;
queryParameters.fromBaseTileX = tile.tileX << zoomLevelDifference;
queryParameters.fromBaseTileY = tile.tileY << zoomLevelDifference;
queryParameters.toBaseTileX = queryParameters.fromBaseTileX + (1 << zoomLevelDifference) - 1;
queryParameters.toBaseTileY = queryParameters.fromBaseTileY + (1 << zoomLevelDifference) - 1;
queryParameters.useTileBitmask = false;
} else if (tile.zoomLevel > subFileParameter.baseZoomLevel) {
// calculate the XY numbers of the parent base tile
int zoomLevelDifference = tile.zoomLevel - subFileParameter.baseZoomLevel;
queryParameters.fromBaseTileX = tile.tileX >>> zoomLevelDifference;
queryParameters.fromBaseTileY = tile.tileY >>> zoomLevelDifference;
queryParameters.toBaseTileX = queryParameters.fromBaseTileX;
queryParameters.toBaseTileY = queryParameters.fromBaseTileY;
queryParameters.useTileBitmask = true;
queryParameters.queryTileBitmask = calculateTileBitmask(tile, zoomLevelDifference);
} else {
// use the tile XY numbers of the requested tile
queryParameters.fromBaseTileX = tile.tileX;
queryParameters.fromBaseTileY = tile.tileY;
queryParameters.toBaseTileX = queryParameters.fromBaseTileX;
queryParameters.toBaseTileY = queryParameters.fromBaseTileY;
queryParameters.useTileBitmask = false;
}
}
static void calculateBlocks(QueryParameters queryParameters, SubFileParameter subFileParameter) {
// calculate the blocks in the file which need to be read
queryParameters.fromBlockX = Math.max(queryParameters.fromBaseTileX - subFileParameter.boundaryTileLeft, 0);
queryParameters.fromBlockY = Math.max(queryParameters.fromBaseTileY - subFileParameter.boundaryTileTop, 0);
queryParameters.toBlockX = Math.min(queryParameters.toBaseTileX - subFileParameter.boundaryTileLeft,
subFileParameter.blocksWidth - 1);
queryParameters.toBlockY = Math.min(queryParameters.toBaseTileY - subFileParameter.boundaryTileTop,
subFileParameter.blocksHeight - 1);
}
static int calculateTileBitmask(Tile tile, int zoomLevelDifference) {
if (zoomLevelDifference == 1) {
return getFirstLevelTileBitmask(tile);
}
// calculate the XY numbers of the second level sub-tile
long subtileX = tile.tileX >>> (zoomLevelDifference - 2);
long subtileY = tile.tileY >>> (zoomLevelDifference - 2);
// calculate the XY numbers of the parent tile
long parentTileX = subtileX >>> 1;
long parentTileY = subtileY >>> 1;
// determine the correct bitmask for all 16 sub-tiles
if (parentTileX % 2 == 0 && parentTileY % 2 == 0) {
return getSecondLevelTileBitmaskUpperLeft(subtileX, subtileY);
} else if (parentTileX % 2 == 1 && parentTileY % 2 == 0) {
return getSecondLevelTileBitmaskUpperRight(subtileX, subtileY);
} else if (parentTileX % 2 == 0 && parentTileY % 2 == 1) {
return getSecondLevelTileBitmaskLowerLeft(subtileX, subtileY);
} else {
return getSecondLevelTileBitmaskLowerRight(subtileX, subtileY);
}
}
private QueryCalculations() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
class QueryParameters {
long fromBaseTileX;
long fromBaseTileY;
long fromBlockX;
long fromBlockY;
int queryTileBitmask;
int queryZoomLevel;
long toBaseTileX;
long toBaseTileY;
long toBlockX;
long toBlockY;
boolean useTileBitmask;
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("QueryParameters [fromBaseTileX=");
stringBuilder.append(this.fromBaseTileX);
stringBuilder.append(", fromBaseTileY=");
stringBuilder.append(this.fromBaseTileY);
stringBuilder.append(", fromBlockX=");
stringBuilder.append(this.fromBlockX);
stringBuilder.append(", fromBlockY=");
stringBuilder.append(this.fromBlockY);
stringBuilder.append(", queryTileBitmask=");
stringBuilder.append(this.queryTileBitmask);
stringBuilder.append(", queryZoomLevel=");
stringBuilder.append(this.queryZoomLevel);
stringBuilder.append(", toBaseTileX=");
stringBuilder.append(this.toBaseTileX);
stringBuilder.append(", toBaseTileY=");
stringBuilder.append(this.toBaseTileY);
stringBuilder.append(", toBlockX=");
stringBuilder.append(this.toBlockX);
stringBuilder.append(", toBlockY=");
stringBuilder.append(this.toBlockY);
stringBuilder.append(", useTileBitmask=");
stringBuilder.append(this.useTileBitmask);
stringBuilder.append("]");
return stringBuilder.toString();
}
}

View File

@@ -0,0 +1,535 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.util.logging.Logger;
import org.oscim.core.Tag;
/**
* Reads from a {@link RandomAccessFile} into a buffer and decodes the data.
*/
public class ReadBuffer {
private static final String CHARSET_UTF8 = "UTF-8";
private static final Logger LOG = Logger.getLogger(ReadBuffer.class.getName());
/**
* Maximum buffer size which is supported by this implementation.
*/
static final int MAXIMUM_BUFFER_SIZE = 8000000;
private byte[] mBufferData;
private int mBufferPosition;
private final RandomAccessFile mInputFile;
ReadBuffer(RandomAccessFile inputFile) {
mInputFile = inputFile;
}
/**
* Returns one signed byte from the read buffer.
*
* @return the byte value.
*/
public byte readByte() {
return mBufferData[mBufferPosition++];
}
/**
* Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position. If
* the capacity of the read buffer is too small, a larger one is created automatically.
*
* @param length
* the amount of bytes to read from the file.
* @return true if the whole data was read successfully, false otherwise.
* @throws IOException
* if an error occurs while reading the file.
*/
public boolean readFromFile(int length) throws IOException {
// ensure that the read buffer is large enough
if (mBufferData == null || mBufferData.length < length) {
// ensure that the read buffer is not too large
if (length > MAXIMUM_BUFFER_SIZE) {
LOG.warning("invalid read length: " + length);
return false;
}
mBufferData = new byte[length];
}
mBufferPosition = 0;
// reset the buffer position and read the data into the buffer
// bufferPosition = 0;
return mInputFile.read(mBufferData, 0, length) == length;
}
/**
* Converts four bytes from the read buffer to a signed int.
* <p>
* The byte order is big-endian.
*
* @return the int value.
*/
public int readInt() {
int pos = mBufferPosition;
byte[] data = mBufferData;
mBufferPosition += 4;
return data[pos] << 24
| (data[pos + 1] & 0xff) << 16
| (data[pos + 2] & 0xff) << 8
| (data[pos + 3] & 0xff);
}
/**
* Converts eight bytes from the read buffer to a signed long.
* <p>
* The byte order is big-endian.
*
* @return the long value.
*/
public long readLong() {
int pos = mBufferPosition;
byte[] data = mBufferData;
mBufferPosition += 8;
return (data[pos] & 0xffL) << 56
| (data[pos + 1] & 0xffL) << 48
| (data[pos + 2] & 0xffL) << 40
| (data[pos + 3] & 0xffL) << 32
| (data[pos + 4] & 0xffL) << 24
| (data[pos + 5] & 0xffL) << 16
| (data[pos + 6] & 0xffL) << 8
| (data[pos + 7] & 0xffL);
}
/**
* Converts two bytes from the read buffer to a signed int.
* <p>
* The byte order is big-endian.
*
* @return the int value.
*/
public int readShort() {
mBufferPosition += 2;
return mBufferData[mBufferPosition - 2] << 8 | (mBufferData[mBufferPosition - 1] & 0xff);
}
/**
* Converts a variable amount of bytes from the read buffer to a signed int.
* <p>
* The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data.
* The second bit in the last byte indicates the sign of the number.
*
* @return the value.
*/
public int readSignedInt() {
int pos = mBufferPosition;
byte[] data = mBufferData;
int flag;
if ((data[pos] & 0x80) == 0) {
mBufferPosition += 1;
flag = ((data[pos] & 0x40) >> 6);
return ((data[pos] & 0x3f) ^ -flag) + flag;
}
if ((data[pos + 1] & 0x80) == 0) {
mBufferPosition += 2;
flag = ((data[pos + 1] & 0x40) >> 6);
return (((data[pos] & 0x7f)
| (data[pos + 1] & 0x3f) << 7) ^ -flag) + flag;
}
if ((data[pos + 2] & 0x80) == 0) {
mBufferPosition += 3;
flag = ((data[pos + 2] & 0x40) >> 6);
return (((data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7
| (data[pos + 2] & 0x3f) << 14) ^ -flag) + flag;
}
if ((data[pos + 3] & 0x80) == 0) {
mBufferPosition += 4;
flag = ((data[pos + 3] & 0x40) >> 6);
return (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x3f) << 21)) ^ -flag) + flag;
}
mBufferPosition += 5;
flag = ((data[pos + 4] & 0x40) >> 6);
return ((((data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7
| (data[pos + 2] & 0x7f) << 14
| (data[pos + 3] & 0x7f) << 21
| (data[pos + 4] & 0x3f) << 28)) ^ -flag) + flag;
}
/**
* Converts a variable amount of bytes from the read buffer to a signed int array.
* <p>
* The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data.
* The second bit in the last byte indicates the sign of the number.
*
* @param values
* result values
* @param length
* number of values to read
*/
public void readSignedInt(int[] values, int length) {
int pos = mBufferPosition;
byte[] data = mBufferData;
int flag;
for (int i = 0; i < length; i++) {
if ((data[pos] & 0x80) == 0) {
flag = ((data[pos] & 0x40) >> 6);
values[i] = ((data[pos] & 0x3f) ^ -flag) + flag;
pos += 1;
} else if ((data[pos + 1] & 0x80) == 0) {
flag = ((data[pos + 1] & 0x40) >> 6);
values[i] = (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x3f) << 7)) ^ -flag) + flag;
pos += 2;
} else if ((data[pos + 2] & 0x80) == 0) {
flag = ((data[pos + 2] & 0x40) >> 6);
values[i] = (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x3f) << 14)) ^ -flag) + flag;
pos += 3;
} else if ((data[pos + 3] & 0x80) == 0) {
flag = ((data[pos + 3] & 0x40) >> 6);
values[i] = (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x3f) << 21)) ^ -flag) + flag;
pos += 4;
} else {
flag = ((data[pos + 4] & 0x40) >> 6);
values[i] = ((((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21)
| ((data[pos + 4] & 0x3f) << 28))) ^ -flag) + flag;
pos += 5;
}
}
mBufferPosition = pos;
}
// public void readSignedInt(int[] values, int length) {
// int pos = mBufferPosition;
// byte[] data = mBufferData;
//
// for (int i = 0; i < length; i++) {
//
// if ((data[pos] & 0x80) == 0) {
// if ((data[pos] & 0x40) != 0)
// values[i] = -(data[pos] & 0x3f);
// else
// values[i] = (data[pos] & 0x3f);
// pos += 1;
// } else if ((data[pos + 1] & 0x80) == 0) {
// if ((data[pos + 1] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x3f) << 7));
// else
// values[i] = (data[pos] & 0x7f)
// | ((data[pos + 1] & 0x3f) << 7);
// pos += 2;
// } else if ((data[pos + 2] & 0x80) == 0) {
// if ((data[pos + 2] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x3f) << 14));
// else
// values[i] = (data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x3f) << 14);
// pos += 3;
// } else if ((data[pos + 3] & 0x80) == 0) {
// if ((data[pos + 3] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x3f) << 21));
// else
// values[i] = (data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x3f) << 21);
// pos += 4;
// } else {
// if ((data[pos + 4] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x7f) << 21)
// | ((data[pos + 4] & 0x3f) << 28));
// else
// values[i] = ((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x7f) << 21)
// | ((data[pos + 4] & 0x3f) << 28));
// pos += 5;
// }
// }
//
// mBufferPosition = pos;
// }
/**
* Converts a variable amount of bytes from the read buffer to an unsigned int.
* <p>
* The first bit is for continuation info, the other seven bits are for data.
*
* @return the int value.
*/
public int readUnsignedInt() {
int pos = mBufferPosition;
byte[] data = mBufferData;
if ((data[pos] & 0x80) == 0) {
mBufferPosition += 1;
return (data[pos] & 0x7f);
}
if ((data[pos + 1] & 0x80) == 0) {
mBufferPosition += 2;
return (data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7;
}
if ((data[pos + 2] & 0x80) == 0) {
mBufferPosition += 3;
return (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14);
}
if ((data[pos + 3] & 0x80) == 0) {
mBufferPosition += 4;
return (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21);
}
mBufferPosition += 5;
return (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21)
| ((data[pos + 4] & 0x7f) << 28);
}
/**
* Decodes a variable amount of bytes from the read buffer to a string.
*
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedString() {
return readUTF8EncodedString(readUnsignedInt());
}
/**
* @return ...
*/
public int getPositionAndSkip() {
int pos = mBufferPosition;
int length = readUnsignedInt();
skipBytes(length);
return pos;
}
/**
* Decodes the given amount of bytes from the read buffer to a string.
*
* @param stringLength
* the length of the string in bytes.
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedString(int stringLength) {
if (stringLength > 0 && mBufferPosition + stringLength <= mBufferData.length) {
mBufferPosition += stringLength;
try {
return new String(mBufferData, mBufferPosition - stringLength, stringLength, CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
LOG.warning("invalid string length: " + stringLength);
return null;
}
/**
* Decodes a variable amount of bytes from the read buffer to a string.
*
* @param position
* buffer offset position of string
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedStringAt(int position) {
int curPosition = mBufferPosition;
mBufferPosition = position;
String result = readUTF8EncodedString(readUnsignedInt());
mBufferPosition = curPosition;
return result;
}
/**
* @return the current buffer position.
*/
int getBufferPosition() {
return mBufferPosition;
}
/**
* @return the current size of the read buffer.
*/
int getBufferSize() {
return mBufferData.length;
}
/**
* Sets the buffer position to the given offset.
*
* @param bufferPosition
* the buffer position.
*/
void setBufferPosition(int bufferPosition) {
mBufferPosition = bufferPosition;
}
/**
* Skips the given number of bytes in the read buffer.
*
* @param bytes
* the number of bytes to skip.
*/
void skipBytes(int bytes) {
mBufferPosition += bytes;
}
Tag[] readTags(Tag[] wayTags, byte numberOfTags) {
Tag[] tags = new Tag[numberOfTags];
int maxTag = wayTags.length;
for (byte i = 0; i < numberOfTags; i++) {
int tagId = readUnsignedInt();
if (tagId < 0 || tagId >= maxTag) {
LOG.warning("invalid tag ID: " + tagId);
return null;
}
tags[i] = wayTags[tagId];
}
return tags;
}
private static final int WAY_NUMBER_OF_TAGS_BITMASK = 0x0f;
int lastTagPosition;
int skipWays(int queryTileBitmask, int elements) {
int pos = mBufferPosition;
byte[] data = mBufferData;
int cnt = elements;
int skip;
lastTagPosition = -1;
while (cnt > 0) {
// read way size (unsigned int)
if ((data[pos] & 0x80) == 0) {
skip = (data[pos] & 0x7f);
pos += 1;
} else if ((data[pos + 1] & 0x80) == 0) {
skip = (data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7;
pos += 2;
} else if ((data[pos + 2] & 0x80) == 0) {
skip = (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14);
pos += 3;
} else if ((data[pos + 3] & 0x80) == 0) {
skip = (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21);
pos += 4;
} else {
skip = (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21)
| ((data[pos + 4] & 0x7f) << 28);
pos += 5;
}
// invalid way size
if (skip < 0) {
mBufferPosition = pos;
return -1;
}
// check if way matches queryTileBitmask
if ((((data[pos] << 8) | (data[pos + 1] & 0xff)) & queryTileBitmask) == 0) {
// remember last tags position
if ((data[pos + 2] & WAY_NUMBER_OF_TAGS_BITMASK) != 0)
lastTagPosition = pos + 2;
pos += skip;
cnt--;
} else {
pos += 2;
break;
}
}
mBufferPosition = pos;
return cnt;
}
}

View File

@@ -0,0 +1,251 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import java.io.IOException;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
/**
* Reads and validates the header data from a binary map file.
*/
public class MapFileHeader {
/**
* Maximum valid base zoom level of a sub-file.
*/
private static final int BASE_ZOOM_LEVEL_MAX = 20;
/**
* Minimum size of the file header in bytes.
*/
private static final int HEADER_SIZE_MIN = 70;
/**
* Length of the debug signature at the beginning of the index.
*/
private static final byte SIGNATURE_LENGTH_INDEX = 16;
/**
* A single whitespace character.
*/
private static final char SPACE = ' ';
private MapFileInfo mapFileInfo;
private SubFileParameter[] subFileParameters;
private byte zoomLevelMaximum;
private byte zoomLevelMinimum;
/**
* @return a MapFileInfo containing the header data.
*/
public MapFileInfo getMapFileInfo() {
return this.mapFileInfo;
}
/**
* @param zoomLevel
* the originally requested zoom level.
* @return the closest possible zoom level which is covered by a sub-file.
*/
public byte getQueryZoomLevel(byte zoomLevel) {
if (zoomLevel > this.zoomLevelMaximum) {
return this.zoomLevelMaximum;
} else if (zoomLevel < this.zoomLevelMinimum) {
return this.zoomLevelMinimum;
}
return zoomLevel;
}
/**
* @param queryZoomLevel
* the zoom level for which the sub-file parameters are needed.
* @return the sub-file parameters for the given zoom level.
*/
public SubFileParameter getSubFileParameter(int queryZoomLevel) {
return this.subFileParameters[queryZoomLevel];
}
/**
* Reads and validates the header block from the map file.
*
* @param readBuffer
* the ReadBuffer for the file data.
* @param fileSize
* the size of the map file in bytes.
* @return a FileOpenResult containing an error message in case of a failure.
* @throws IOException
* if an error occurs while reading the file.
*/
public OpenResult readHeader(ReadBuffer readBuffer, long fileSize) throws IOException {
OpenResult openResult = RequiredFields.readMagicByte(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readRemainingHeader(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder();
openResult = RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readFileSize(readBuffer, fileSize, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readMapDate(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readBoundingBox(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readTilePixelSize(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readProjectionName(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readPoiTags(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readWayTags(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = readSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
this.mapFileInfo = mapFileInfoBuilder.build();
return OpenResult.SUCCESS;
}
private OpenResult readSubFileParameters(ReadBuffer readBuffer, long fileSize,
MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of sub-files (1 byte)
byte numberOfSubFiles = readBuffer.readByte();
if (numberOfSubFiles < 1) {
return new OpenResult("invalid number of sub-files: " + numberOfSubFiles);
}
mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles;
SubFileParameter[] tempSubFileParameters = new SubFileParameter[numberOfSubFiles];
this.zoomLevelMinimum = Byte.MAX_VALUE;
this.zoomLevelMaximum = Byte.MIN_VALUE;
// get and check the information for each sub-file
for (byte currentSubFile = 0; currentSubFile < numberOfSubFiles; ++currentSubFile) {
SubFileParameterBuilder subFileParameterBuilder = new SubFileParameterBuilder();
// get and check the base zoom level (1 byte)
byte baseZoomLevel = readBuffer.readByte();
if (baseZoomLevel < 0 || baseZoomLevel > BASE_ZOOM_LEVEL_MAX) {
return new OpenResult("invalid base zooom level: " + baseZoomLevel);
}
subFileParameterBuilder.baseZoomLevel = baseZoomLevel;
// get and check the minimum zoom level (1 byte)
byte zoomLevelMin = readBuffer.readByte();
if (zoomLevelMin < 0 || zoomLevelMin > 22) {
return new OpenResult("invalid minimum zoom level: " + zoomLevelMin);
}
subFileParameterBuilder.zoomLevelMin = zoomLevelMin;
// get and check the maximum zoom level (1 byte)
byte zoomLevelMax = readBuffer.readByte();
if (zoomLevelMax < 0 || zoomLevelMax > 22) {
return new OpenResult("invalid maximum zoom level: " + zoomLevelMax);
}
subFileParameterBuilder.zoomLevelMax = zoomLevelMax;
// check for valid zoom level range
if (zoomLevelMin > zoomLevelMax) {
return new OpenResult("invalid zoom level range: " + zoomLevelMin + SPACE + zoomLevelMax);
}
// get and check the start address of the sub-file (8 bytes)
long startAddress = readBuffer.readLong();
if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize) {
return new OpenResult("invalid start address: " + startAddress);
}
subFileParameterBuilder.startAddress = startAddress;
long indexStartAddress = startAddress;
if (mapFileInfoBuilder.optionalFields.isDebugFile) {
// the sub-file has an index signature before the index
indexStartAddress += SIGNATURE_LENGTH_INDEX;
}
subFileParameterBuilder.indexStartAddress = indexStartAddress;
// get and check the size of the sub-file (8 bytes)
long subFileSize = readBuffer.readLong();
if (subFileSize < 1) {
return new OpenResult("invalid sub-file size: " + subFileSize);
}
subFileParameterBuilder.subFileSize = subFileSize;
subFileParameterBuilder.boundingBox = mapFileInfoBuilder.boundingBox;
// add the current sub-file to the list of sub-files
tempSubFileParameters[currentSubFile] = subFileParameterBuilder.build();
updateZoomLevelInformation(tempSubFileParameters[currentSubFile]);
}
// create and fill the lookup table for the sub-files
this.subFileParameters = new SubFileParameter[this.zoomLevelMaximum + 1];
for (int currentMapFile = 0; currentMapFile < numberOfSubFiles; ++currentMapFile) {
SubFileParameter subFileParameter = tempSubFileParameters[currentMapFile];
for (byte zoomLevel = subFileParameter.zoomLevelMin; zoomLevel <= subFileParameter.zoomLevelMax; ++zoomLevel) {
this.subFileParameters[zoomLevel] = subFileParameter;
}
}
return OpenResult.SUCCESS;
}
private void updateZoomLevelInformation(SubFileParameter subFileParameter) {
// update the global minimum and maximum zoom level information
if (this.zoomLevelMinimum > subFileParameter.zoomLevelMin) {
this.zoomLevelMinimum = subFileParameter.zoomLevelMin;
}
if (this.zoomLevelMaximum < subFileParameter.zoomLevelMax) {
this.zoomLevelMaximum = subFileParameter.zoomLevelMax;
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.Tag;
import org.oscim.database.mapfile.MapDatabase;
/**
* Contains the immutable metadata of a map file.
*
* @see MapDatabase#getMapInfo()
*/
public class MapFileInfo extends org.oscim.database.MapInfo {
/**
* True if the map file includes debug information, false otherwise.
*/
public final boolean debugFile;
/**
* The number of sub-files in the map file.
*/
public final byte numberOfSubFiles;
/**
* The POI tags.
*/
public final Tag[] poiTags;
/**
* The way tags.
*/
public final Tag[] wayTags;
/**
* The size of the tiles in pixels.
*/
public final int tilePixelSize;
MapFileInfo(MapFileInfoBuilder mapFileInfoBuilder) {
super(mapFileInfoBuilder.boundingBox,
mapFileInfoBuilder.optionalFields.startZoomLevel,
mapFileInfoBuilder.optionalFields.startPosition,
mapFileInfoBuilder.projectionName,
mapFileInfoBuilder.mapDate,
mapFileInfoBuilder.fileSize,
mapFileInfoBuilder.fileVersion,
mapFileInfoBuilder.optionalFields.languagePreference,
mapFileInfoBuilder.optionalFields.comment,
mapFileInfoBuilder.optionalFields.createdBy);
debugFile = mapFileInfoBuilder.optionalFields.isDebugFile;
numberOfSubFiles = mapFileInfoBuilder.numberOfSubFiles;
poiTags = mapFileInfoBuilder.poiTags;
tilePixelSize = mapFileInfoBuilder.tilePixelSize;
wayTags = mapFileInfoBuilder.wayTags;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.BoundingBox;
import org.oscim.core.Tag;
class MapFileInfoBuilder {
BoundingBox boundingBox;
long fileSize;
int fileVersion;
long mapDate;
byte numberOfSubFiles;
OptionalFields optionalFields;
Tag[] poiTags;
String projectionName;
int tilePixelSize;
Tag[] wayTags;
MapFileInfo build() {
return new MapFileInfo(this);
}
}

View File

@@ -0,0 +1,163 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.GeoPoint;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
final class OptionalFields {
/**
* Bitmask for the comment field in the file header.
*/
private static final int HEADER_BITMASK_COMMENT = 0x08;
/**
* Bitmask for the created by field in the file header.
*/
private static final int HEADER_BITMASK_CREATED_BY = 0x04;
/**
* Bitmask for the debug flag in the file header.
*/
private static final int HEADER_BITMASK_DEBUG = 0x80;
/**
* Bitmask for the language preference field in the file header.
*/
private static final int HEADER_BITMASK_LANGUAGE_PREFERENCE = 0x10;
/**
* Bitmask for the start position field in the file header.
*/
private static final int HEADER_BITMASK_START_POSITION = 0x40;
/**
* Bitmask for the start zoom level field in the file header.
*/
private static final int HEADER_BITMASK_START_ZOOM_LEVEL = 0x20;
/**
* The length of the language preference string.
*/
private static final int LANGUAGE_PREFERENCE_LENGTH = 2;
/**
* Maximum valid start zoom level.
*/
private static final int START_ZOOM_LEVEL_MAX = 22;
static OpenResult readOptionalFields(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
OptionalFields optionalFields = new OptionalFields(readBuffer.readByte());
mapFileInfoBuilder.optionalFields = optionalFields;
OpenResult openResult = optionalFields.readOptionalFields(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
return OpenResult.SUCCESS;
}
String comment;
String createdBy;
final boolean hasComment;
final boolean hasCreatedBy;
final boolean hasLanguagePreference;
final boolean hasStartPosition;
final boolean hasStartZoomLevel;
final boolean isDebugFile;
String languagePreference;
GeoPoint startPosition;
Byte startZoomLevel;
private OptionalFields(byte flags) {
this.isDebugFile = (flags & HEADER_BITMASK_DEBUG) != 0;
this.hasStartPosition = (flags & HEADER_BITMASK_START_POSITION) != 0;
this.hasStartZoomLevel = (flags & HEADER_BITMASK_START_ZOOM_LEVEL) != 0;
this.hasLanguagePreference = (flags & HEADER_BITMASK_LANGUAGE_PREFERENCE) != 0;
this.hasComment = (flags & HEADER_BITMASK_COMMENT) != 0;
this.hasCreatedBy = (flags & HEADER_BITMASK_CREATED_BY) != 0;
}
private OpenResult readLanguagePreference(ReadBuffer readBuffer) {
if (this.hasLanguagePreference) {
String countryCode = readBuffer.readUTF8EncodedString();
if (countryCode.length() != LANGUAGE_PREFERENCE_LENGTH) {
return new OpenResult("invalid language preference: " + countryCode);
}
this.languagePreference = countryCode;
}
return OpenResult.SUCCESS;
}
private OpenResult readMapStartPosition(ReadBuffer readBuffer) {
if (this.hasStartPosition) {
// get and check the start position latitude (4 byte)
int mapStartLatitude = readBuffer.readInt();
if (mapStartLatitude < RequiredFields.LATITUDE_MIN || mapStartLatitude > RequiredFields.LATITUDE_MAX) {
return new OpenResult("invalid map start latitude: " + mapStartLatitude);
}
// get and check the start position longitude (4 byte)
int mapStartLongitude = readBuffer.readInt();
if (mapStartLongitude < RequiredFields.LONGITUDE_MIN || mapStartLongitude > RequiredFields.LONGITUDE_MAX) {
return new OpenResult("invalid map start longitude: " + mapStartLongitude);
}
this.startPosition = new GeoPoint(mapStartLatitude, mapStartLongitude);
}
return OpenResult.SUCCESS;
}
private OpenResult readMapStartZoomLevel(ReadBuffer readBuffer) {
if (this.hasStartZoomLevel) {
// get and check the start zoom level (1 byte)
byte mapStartZoomLevel = readBuffer.readByte();
if (mapStartZoomLevel < 0 || mapStartZoomLevel > START_ZOOM_LEVEL_MAX) {
return new OpenResult("invalid map start zoom level: " + mapStartZoomLevel);
}
this.startZoomLevel = Byte.valueOf(mapStartZoomLevel);
}
return OpenResult.SUCCESS;
}
private OpenResult readOptionalFields(ReadBuffer readBuffer) {
OpenResult openResult = readMapStartPosition(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = readMapStartZoomLevel(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = readLanguagePreference(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
if (this.hasComment) {
this.comment = readBuffer.readUTF8EncodedString();
}
if (this.hasCreatedBy) {
this.createdBy = readBuffer.readUTF8EncodedString();
}
return OpenResult.SUCCESS;
}
}

View File

@@ -0,0 +1,235 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import java.io.IOException;
import org.oscim.core.BoundingBox;
import org.oscim.core.Tag;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
final class RequiredFields {
/**
* Magic byte at the beginning of a valid binary map file.
*/
private static final String BINARY_OSM_MAGIC_BYTE = "mapsforge binary OSM";
/**
* Maximum size of the file header in bytes.
*/
private static final int HEADER_SIZE_MAX = 1000000;
/**
* Minimum size of the file header in bytes.
*/
private static final int HEADER_SIZE_MIN = 70;
/**
* The name of the Mercator projection as stored in the file header.
*/
private static final String MERCATOR = "Mercator";
/**
* A single whitespace character.
*/
private static final char SPACE = ' ';
/**
* Version of the map file format which is supported by this implementation.
*/
private static final int SUPPORTED_FILE_VERSION = 4;
/**
* The maximum latitude values in microdegrees.
*/
static final int LATITUDE_MAX = 90000000;
/**
* The minimum latitude values in microdegrees.
*/
static final int LATITUDE_MIN = -90000000;
/**
* The maximum longitude values in microdegrees.
*/
static final int LONGITUDE_MAX = 180000000;
/**
* The minimum longitude values in microdegrees.
*/
static final int LONGITUDE_MIN = -180000000;
static OpenResult readBoundingBox(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the minimum latitude (4 bytes)
int minLatitude = readBuffer.readInt();
if (minLatitude < LATITUDE_MIN || minLatitude > LATITUDE_MAX) {
return new OpenResult("invalid minimum latitude: " + minLatitude);
}
// get and check the minimum longitude (4 bytes)
int minLongitude = readBuffer.readInt();
if (minLongitude < LONGITUDE_MIN || minLongitude > LONGITUDE_MAX) {
return new OpenResult("invalid minimum longitude: " + minLongitude);
}
// get and check the maximum latitude (4 bytes)
int maxLatitude = readBuffer.readInt();
if (maxLatitude < LATITUDE_MIN || maxLatitude > LATITUDE_MAX) {
return new OpenResult("invalid maximum latitude: " + maxLatitude);
}
// get and check the maximum longitude (4 bytes)
int maxLongitude = readBuffer.readInt();
if (maxLongitude < LONGITUDE_MIN || maxLongitude > LONGITUDE_MAX) {
return new OpenResult("invalid maximum longitude: " + maxLongitude);
}
// check latitude and longitude range
if (minLatitude > maxLatitude) {
return new OpenResult("invalid latitude range: " + minLatitude + SPACE + maxLatitude);
} else if (minLongitude > maxLongitude) {
return new OpenResult("invalid longitude range: " + minLongitude + SPACE + maxLongitude);
}
mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
return OpenResult.SUCCESS;
}
static OpenResult readFileSize(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the file size (8 bytes)
long headerFileSize = readBuffer.readLong();
if (headerFileSize != fileSize) {
return new OpenResult("invalid file size: " + headerFileSize);
}
mapFileInfoBuilder.fileSize = fileSize;
return OpenResult.SUCCESS;
}
static OpenResult readFileVersion(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the file version (4 bytes)
int fileVersion = readBuffer.readInt();
if (fileVersion != SUPPORTED_FILE_VERSION) {
return new OpenResult("unsupported file version: " + fileVersion);
}
mapFileInfoBuilder.fileVersion = fileVersion;
return OpenResult.SUCCESS;
}
static OpenResult readMagicByte(ReadBuffer readBuffer) throws IOException {
// read the the magic byte and the file header size into the buffer
int magicByteLength = BINARY_OSM_MAGIC_BYTE.length();
if (!readBuffer.readFromFile(magicByteLength + 4)) {
return new OpenResult("reading magic byte has failed");
}
// get and check the magic byte
String magicByte = readBuffer.readUTF8EncodedString(magicByteLength);
if (!BINARY_OSM_MAGIC_BYTE.equals(magicByte)) {
return new OpenResult("invalid magic byte: " + magicByte);
}
return OpenResult.SUCCESS;
}
static OpenResult readMapDate(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the the map date (8 bytes)
long mapDate = readBuffer.readLong();
// is the map date before 2010-01-10 ?
if (mapDate < 1200000000000L) {
return new OpenResult("invalid map date: " + mapDate);
}
mapFileInfoBuilder.mapDate = mapDate;
return OpenResult.SUCCESS;
}
static OpenResult readPoiTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of POI tags (2 bytes)
int numberOfPoiTags = readBuffer.readShort();
if (numberOfPoiTags < 0) {
return new OpenResult("invalid number of POI tags: " + numberOfPoiTags);
}
Tag[] poiTags = new Tag[numberOfPoiTags];
for (int currentTagId = 0; currentTagId < numberOfPoiTags; ++currentTagId) {
// get and check the POI tag
String tag = readBuffer.readUTF8EncodedString();
if (tag == null) {
return new OpenResult("POI tag must not be null: " + currentTagId);
}
poiTags[currentTagId] = new Tag(tag);
}
mapFileInfoBuilder.poiTags = poiTags;
return OpenResult.SUCCESS;
}
static OpenResult readProjectionName(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the projection name
String projectionName = readBuffer.readUTF8EncodedString();
if (!MERCATOR.equals(projectionName)) {
return new OpenResult("unsupported projection: " + projectionName);
}
mapFileInfoBuilder.projectionName = projectionName;
return OpenResult.SUCCESS;
}
static OpenResult readRemainingHeader(ReadBuffer readBuffer) throws IOException {
// get and check the size of the remaining file header (4 bytes)
int remainingHeaderSize = readBuffer.readInt();
if (remainingHeaderSize < HEADER_SIZE_MIN || remainingHeaderSize > HEADER_SIZE_MAX) {
return new OpenResult("invalid remaining header size: " + remainingHeaderSize);
}
// read the header data into the buffer
if (!readBuffer.readFromFile(remainingHeaderSize)) {
return new OpenResult("reading header data has failed: " + remainingHeaderSize);
}
return OpenResult.SUCCESS;
}
static OpenResult readTilePixelSize(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the tile pixel size (2 bytes)
int tilePixelSize = readBuffer.readShort();
// if (tilePixelSize != Tile.TILE_SIZE) {
// return new FileOpenResult("unsupported tile pixel size: " + tilePixelSize);
// }
mapFileInfoBuilder.tilePixelSize = tilePixelSize;
return OpenResult.SUCCESS;
}
static OpenResult readWayTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of way tags (2 bytes)
int numberOfWayTags = readBuffer.readShort();
if (numberOfWayTags < 0) {
return new OpenResult("invalid number of way tags: " + numberOfWayTags);
}
Tag[] wayTags = new Tag[numberOfWayTags];
for (int currentTagId = 0; currentTagId < numberOfWayTags; ++currentTagId) {
// get and check the way tag
String tag = readBuffer.readUTF8EncodedString();
if (tag == null) {
return new OpenResult("way tag must not be null: " + currentTagId);
}
wayTags[currentTagId] = new Tag(tag);
}
mapFileInfoBuilder.wayTags = wayTags;
return OpenResult.SUCCESS;
}
private RequiredFields() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,213 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.MercatorProjection;
/**
* Holds all parameters of a sub-file.
*/
public class SubFileParameter {
/**
* Number of bytes a single index entry consists of.
*/
public static final byte BYTES_PER_INDEX_ENTRY = 5;
/**
* Divisor for converting coordinates stored as integers to double values.
*/
private static final double COORDINATES_DIVISOR = 1000000d;
/**
* Base zoom level of the sub-file, which equals to one block.
*/
public final byte baseZoomLevel;
/**
* Size of the entries table at the beginning of each block in bytes.
*/
public final int blockEntriesTableSize;
/**
* Vertical amount of blocks in the grid.
*/
public final long blocksHeight;
/**
* Horizontal amount of blocks in the grid.
*/
public final long blocksWidth;
/**
* Y number of the tile at the bottom boundary in the grid.
*/
public final long boundaryTileBottom;
/**
* X number of the tile at the left boundary in the grid.
*/
public final long boundaryTileLeft;
/**
* X number of the tile at the right boundary in the grid.
*/
public final long boundaryTileRight;
/**
* Y number of the tile at the top boundary in the grid.
*/
public final long boundaryTileTop;
/**
* Absolute end address of the index in the enclosing file.
*/
public final long indexEndAddress;
/**
* Absolute start address of the index in the enclosing file.
*/
public final long indexStartAddress;
/**
* Total number of blocks in the grid.
*/
public final long numberOfBlocks;
/**
* Absolute start address of the sub-file in the enclosing file.
*/
public final long startAddress;
/**
* Size of the sub-file in bytes.
*/
public final long subFileSize;
/**
* Maximum zoom level for which the block entries tables are made.
*/
public final byte zoomLevelMax;
/**
* Minimum zoom level for which the block entries tables are made.
*/
public final byte zoomLevelMin;
/**
* Stores the hash code of this object.
*/
private final int hashCodeValue;
SubFileParameter(SubFileParameterBuilder subFileParameterBuilder) {
this.startAddress = subFileParameterBuilder.startAddress;
this.indexStartAddress = subFileParameterBuilder.indexStartAddress;
this.subFileSize = subFileParameterBuilder.subFileSize;
this.baseZoomLevel = subFileParameterBuilder.baseZoomLevel;
this.zoomLevelMin = subFileParameterBuilder.zoomLevelMin;
this.zoomLevelMax = subFileParameterBuilder.zoomLevelMax;
this.hashCodeValue = calculateHashCode();
// calculate the XY numbers of the boundary tiles in this sub-file
this.boundaryTileBottom = MercatorProjection.latitudeToTileY(subFileParameterBuilder.boundingBox.minLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileLeft = MercatorProjection.longitudeToTileX(subFileParameterBuilder.boundingBox.minLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileTop = MercatorProjection.latitudeToTileY(subFileParameterBuilder.boundingBox.maxLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileRight = MercatorProjection.longitudeToTileX(subFileParameterBuilder.boundingBox.maxLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
// calculate the horizontal and vertical amount of blocks in this sub-file
this.blocksWidth = this.boundaryTileRight - this.boundaryTileLeft + 1;
this.blocksHeight = this.boundaryTileBottom - this.boundaryTileTop + 1;
// calculate the total amount of blocks in this sub-file
this.numberOfBlocks = this.blocksWidth * this.blocksHeight;
this.indexEndAddress = this.indexStartAddress + this.numberOfBlocks * BYTES_PER_INDEX_ENTRY;
// calculate the size of the tile entries table
this.blockEntriesTableSize = 2 * (this.zoomLevelMax - this.zoomLevelMin + 1) * 2;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof SubFileParameter)) {
return false;
}
SubFileParameter other = (SubFileParameter) obj;
if (this.startAddress != other.startAddress) {
return false;
} else if (this.subFileSize != other.subFileSize) {
return false;
} else if (this.baseZoomLevel != other.baseZoomLevel) {
return false;
}
return true;
}
@Override
public int hashCode() {
return this.hashCodeValue;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("SubFileParameter [baseZoomLevel=");
stringBuilder.append(this.baseZoomLevel);
stringBuilder.append(", blockEntriesTableSize=");
stringBuilder.append(this.blockEntriesTableSize);
stringBuilder.append(", blocksHeight=");
stringBuilder.append(this.blocksHeight);
stringBuilder.append(", blocksWidth=");
stringBuilder.append(this.blocksWidth);
stringBuilder.append(", boundaryTileBottom=");
stringBuilder.append(this.boundaryTileBottom);
stringBuilder.append(", boundaryTileLeft=");
stringBuilder.append(this.boundaryTileLeft);
stringBuilder.append(", boundaryTileRight=");
stringBuilder.append(this.boundaryTileRight);
stringBuilder.append(", boundaryTileTop=");
stringBuilder.append(this.boundaryTileTop);
stringBuilder.append(", indexStartAddress=");
stringBuilder.append(this.indexStartAddress);
stringBuilder.append(", numberOfBlocks=");
stringBuilder.append(this.numberOfBlocks);
stringBuilder.append(", startAddress=");
stringBuilder.append(this.startAddress);
stringBuilder.append(", subFileSize=");
stringBuilder.append(this.subFileSize);
stringBuilder.append(", zoomLevelMax=");
stringBuilder.append(this.zoomLevelMax);
stringBuilder.append(", zoomLevelMin=");
stringBuilder.append(this.zoomLevelMin);
stringBuilder.append("]");
return stringBuilder.toString();
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + (int) (this.startAddress ^ (this.startAddress >>> 32));
result = 31 * result + (int) (this.subFileSize ^ (this.subFileSize >>> 32));
result = 31 * result + this.baseZoomLevel;
return result;
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.BoundingBox;
class SubFileParameterBuilder {
byte baseZoomLevel;
BoundingBox boundingBox;
long indexStartAddress;
long startAddress;
long subFileSize;
byte zoomLevelMax;
byte zoomLevelMin;
SubFileParameter build() {
return new SubFileParameter(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,958 @@
/*
* Copyright 2012 Hannes Janetzek
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.pbmap;
import org.oscim.core.Tag;
public class Tags {
public final static int MAX = 654;
public final static int LIMIT = 1024;
private static final String s_limited = "limited".intern();
private static final String s_chain = "chain".intern();
private static final String s_viaduct = "viaduct".intern();
private static final String s_department_store = "department_store".intern();
private static final String s_factory = "factory".intern();
private static final String s_recreation_ground = "recreation_ground".intern();
private static final String s_nature_reserve = "nature_reserve".intern();
private static final String s_apartment = "apartment".intern();
private static final String s_preserved = "preserved".intern();
private static final String s_stationery = "stationery".intern();
private static final String s_gravel = "gravel".intern();
private static final String s_hill = "hill".intern();
private static final String s_water_well = "water_well".intern();
private static final String s_garden = "garden".intern();
private static final String s_permissive = "permissive".intern();
private static final String s_deli = "deli".intern();
private static final String s_industrial_retail = "industrial;retail".intern();
private static final String s_city_wall = "city_wall".intern();
private static final String s_artwork = "artwork".intern();
private static final String s_chapel = "chapel".intern();
private static final String s_school = "school".intern();
private static final String s_caravan_site = "caravan_site".intern();
private static final String s_reservoir_watershed = "reservoir_watershed".intern();
private static final String s_local_authority = "local_authority".intern();
private static final String s_miniature_golf = "miniature_golf".intern();
private static final String s_bus_stop = "bus_stop".intern();
private static final String s_convenience = "convenience".intern();
private static final String s_kissing_gate = "kissing_gate".intern();
private static final String s_subway = "subway".intern();
private static final String s_cutline = "cutline".intern();
private static final String s_disused = "disused".intern();
private static final String s_clothes = "clothes".intern();
private static final String s_bicycle = "bicycle".intern();
private static final String s_meadow = "meadow".intern();
private static final String s_fence = "fence".intern();
private static final String s_video = "video".intern();
private static final String s_monorail = "monorail".intern();
private static final String s_clock = "clock".intern();
private static final String s_dirt = "dirt".intern();
private static final String s_border_control = "border_control".intern();
private static final String s_access = "access".intern();
private static final String s_public = "public".intern();
private static final String s_fast_food = "fast_food".intern();
private static final String s_transportation = "transportation".intern();
private static final String s_commercial = "commercial".intern();
private static final String s_water = "water".intern();
private static final String s_beacon = "beacon".intern();
private static final String s_trunk = "trunk".intern();
private static final String s_path = "path".intern();
private static final String s_bicycle_rental = "bicycle_rental".intern();
private static final String s_miniature = "miniature".intern();
private static final String s_car_parts = "car_parts".intern();
private static final String s_light_rail = "light_rail".intern();
private static final String s_military = "military".intern();
private static final String s_bog = "bog".intern();
private static final String s_hiking = "hiking".intern();
private static final String s_lift_gate = "lift_gate".intern();
private static final String s_private = "private".intern();
private static final String s_county = "county".intern();
private static final String s_secondary_link = "secondary_link".intern();
private static final String s_marker = "marker".intern();
private static final String s_islet = "islet".intern();
private static final String s_holding_position = "holding_position".intern();
private static final String s_tertiary = "tertiary".intern();
private static final String s_water_park = "water_park".intern();
private static final String s_stream = "stream".intern();
private static final String s_hospital = "hospital".intern();
private static final String s_destination = "destination".intern();
private static final String s_MDF = "MDF".intern();
private static final String s_sports = "sports".intern();
private static final String s_vineyard = "vineyard".intern();
private static final String s_music = "music".intern();
private static final String s_6 = "6".intern();
private static final String s_entrance = "entrance".intern();
private static final String s_beauty = "beauty".intern();
private static final String s_give_way = "give_way".intern();
private static final String s_kiosk = "kiosk".intern();
private static final String s_stone = "stone".intern();
private static final String s_grass_paver = "grass_paver".intern();
private static final String s_deciduous = "deciduous".intern();
private static final String s_train = "train".intern();
private static final String s_organic = "organic".intern();
private static final String s_farmyard = "farmyard".intern();
private static final String s_riverbank = "riverbank".intern();
private static final String s_doityourself = "doityourself".intern();
private static final String s_town = "town".intern();
private static final String s_dog_park = "dog_park".intern();
private static final String s_village_green = "village_green".intern();
private static final String s_tunnel = "tunnel".intern();
private static final String s_car = "car".intern();
private static final String s_roof = "roof".intern();
private static final String s_mall = "mall".intern();
private static final String s_ferry_terminal = "ferry_terminal".intern();
private static final String s_cave_entrance = "cave_entrance".intern();
private static final String s_detached = "detached".intern();
private static final String s_concrete_plates = "concrete:plates".intern();
private static final String s_public_building = "public_building".intern();
private static final String s_buffer_stop = "buffer_stop".intern();
private static final String s_lock = "lock".intern();
private static final String s_dolphin = "dolphin".intern();
private static final String s_taxiway = "taxiway".intern();
private static final String s_hunting_stand = "hunting_stand".intern();
private static final String s_estate_agent = "estate_agent".intern();
private static final String s_station = "station".intern();
private static final String s_car_repair = "car_repair".intern();
private static final String s_dyke = "dyke".intern();
private static final String s_hangar = "hangar".intern();
private static final String s_information = "information".intern();
private static final String s_1 = "1".intern();
private static final String s_forest = "forest".intern();
private static final String s_gate = "gate".intern();
private static final String s_beach = "beach".intern();
private static final String s_laundry = "laundry".intern();
private static final String s_speed_camera = "speed_camera".intern();
private static final String s_staircase = "staircase".intern();
private static final String s_farm = "farm".intern();
private static final String s_stop = "stop".intern();
private static final String s_bump_gate = "bump_gate".intern();
private static final String s_motorway = "motorway".intern();
private static final String s_water_tower = "water_tower".intern();
private static final String s_abutters = "abutters".intern();
private static final String s_driving_school = "driving_school".intern();
private static final String s_natural = "natural".intern();
private static final String s_orchard = "orchard".intern();
private static final String s_wheelchair = "wheelchair".intern();
private static final String s_swimming_pool = "swimming_pool".intern();
private static final String s_switch = "switch".intern();
private static final String s_block = "block".intern();
private static final String s_turnstile = "turnstile".intern();
private static final String s_camp_site = "camp_site".intern();
private static final String s_shoes = "shoes".intern();
private static final String s_reservoir = "reservoir".intern();
private static final String s_pebblestone = "pebblestone".intern();
private static final String s_stile = "stile".intern();
private static final String s_embassy = "embassy".intern();
private static final String s_postal_code = "postal_code".intern();
private static final String s_retaining_wall = "retaining_wall".intern();
private static final String s_bridleway = "bridleway".intern();
private static final String s_pitch = "pitch".intern();
private static final String s_agricultural = "agricultural".intern();
private static final String s_post_office = "post_office".intern();
private static final String s_parking_fuel = "parking;fuel".intern();
private static final String s_bureau_de_change = "bureau_de_change".intern();
private static final String s_mini_roundabout = "mini_roundabout".intern();
private static final String s_hov = "hov".intern();
private static final String s_police = "police".intern();
private static final String s_courthouse = "courthouse".intern();
private static final String s_raceway = "raceway".intern();
private static final String s_kindergarten = "kindergarten".intern();
private static final String s_attraction = "attraction".intern();
private static final String s_marsh = "marsh".intern();
private static final String s_reservoir_covered = "reservoir_covered".intern();
private static final String s_petroleum_well = "petroleum_well".intern();
private static final String s_silo = "silo".intern();
private static final String s_toys = "toys".intern();
private static final String s_apron = "apron".intern();
private static final String s_halt = "halt".intern();
private static final String s_dam = "dam".intern();
private static final String s_golf_course = "golf_course".intern();
private static final String s_detour = "detour".intern();
private static final String s_tree_row = "tree_row".intern();
private static final String s_copyshop = "copyshop".intern();
private static final String s_milestone = "milestone".intern();
private static final String s_foot = "foot".intern();
private static final String s_tourism = "tourism".intern();
private static final String s_bank = "bank".intern();
private static final String s_dry_cleaning = "dry_cleaning".intern();
private static final String s_tram = "tram".intern();
private static final String s_trolleybus = "trolleybus".intern();
private static final String s_university = "university".intern();
private static final String s_hampshire_gate = "hampshire_gate".intern();
private static final String s_embankment = "embankment".intern();
private static final String s_rock = "rock".intern();
private static final String s_crossing = "crossing".intern();
private static final String s_volcano = "volcano".intern();
private static final String s_greengrocer = "greengrocer".intern();
private static final String s_kerb = "kerb".intern();
private static final String s_waste_disposal = "waste_disposal".intern();
private static final String s_grave_yard = "grave_yard".intern();
private static final String s_coniferous = "coniferous".intern();
private static final String s_house = "house".intern();
private static final String s_books = "books".intern();
private static final String s_neighbourhood = "neighbourhood".intern();
private static final String s_hostel = "hostel".intern();
private static final String s_alcohol = "alcohol".intern();
private static final String s_restricted = "restricted".intern();
private static final String s_motel = "motel".intern();
private static final String s_sand = "sand".intern();
private static final String s_fishmonger = "fishmonger".intern();
private static final String s_fountain = "fountain".intern();
private static final String s_playground = "playground".intern();
private static final String s_7 = "7".intern();
private static final String s_parking_aisle = "parking_aisle".intern();
private static final String s_protected_area = "protected_area".intern();
private static final String s_electronics = "electronics".intern();
private static final String s_Paved = "Paved".intern();
private static final String s_highway = "highway".intern();
private static final String s_fine_gravel = "fine_gravel".intern();
private static final String s_barrier = "barrier".intern();
private static final String s_hairdresser = "hairdresser".intern();
private static final String s_post_box = "post_box".intern();
private static final String s_pub = "pub".intern();
private static final String s_coastline = "coastline".intern();
private static final String s_marina = "marina".intern();
private static final String s_reedbed = "reedbed".intern();
private static final String s_biergarten = "biergarten".intern();
private static final String s_dismantled = "dismantled".intern();
private static final String s_farmland = "farmland".intern();
private static final String s_yard = "yard".intern();
private static final String s_route = "route".intern();
private static final String s_atm = "atm".intern();
private static final String s_place = "place".intern();
private static final String s_bus_station = "bus_station".intern();
private static final String s_retail = "retail".intern();
private static final String s_industrial = "industrial".intern();
private static final String s_municipality = "municipality".intern();
private static final String s_primary = "primary".intern();
private static final String s_nursing_home = "nursing_home".intern();
private static final String s_florist = "florist".intern();
private static final String s_ditch = "ditch".intern();
private static final String s_national_park = "national_park".intern();
private static final String s_city = "city".intern();
private static final String s_confectionery = "confectionery".intern();
private static final String s_service = "service".intern();
private static final String s_unknown = "unknown".intern();
private static final String s_cycle_barrier = "cycle_barrier".intern();
private static final String s_elevator = "elevator".intern();
private static final String s_2 = "2".intern();
private static final String s_car_rental = "car_rental".intern();
private static final String s_flagpole = "flagpole".intern();
private static final String s_cabin = "cabin".intern();
private static final String s_paved = "paved".intern();
private static final String s_guest_house = "guest_house".intern();
private static final String s_mobile_phone = "mobile_phone".intern();
private static final String s_lot = "lot".intern();
private static final String s_quarry = "quarry".intern();
private static final String s_train_station = "train_station".intern();
private static final String s_hotel = "hotel".intern();
private static final String s_park = "park".intern();
private static final String s_hut = "hut".intern();
private static final String s_dentist = "dentist".intern();
private static final String s_doctors = "doctors".intern();
private static final String s_greenhouse = "greenhouse".intern();
private static final String s_11 = "11".intern();
private static final String s_10 = "10".intern();
private static final String s_theme_park = "theme_park".intern();
private static final String s_tree = "tree".intern();
private static final String s_shower = "shower".intern();
private static final String s_siding = "siding".intern();
private static final String s_aeroway = "aeroway".intern();
private static final String s_emergency_access_point = "emergency_access_point"
.intern();
private static final String s_watermill = "watermill".intern();
private static final String s_college = "college".intern();
private static final String s_landuse = "landuse".intern();
private static final String s_tracktype = "tracktype".intern();
private static final String s_ferry = "ferry".intern();
private static final String s_bridge = "bridge".intern();
private static final String s_vacant = "vacant".intern();
private static final String s_cattle_grid = "cattle_grid".intern();
private static final String s_brownfield = "brownfield".intern();
private static final String s_allotments = "allotments".intern();
private static final String s_alley = "alley".intern();
private static final String s_pedestrian = "pedestrian".intern();
private static final String s_borough = "borough".intern();
private static final String s_bare_rock = "bare_rock".intern();
private static final String s_motorcycle = "motorcycle".intern();
private static final String s_bakery = "bakery".intern();
private static final String s_zoo = "zoo".intern();
private static final String s_scree = "scree".intern();
private static final String s_fire_station = "fire_station".intern();
private static final String s_theatre = "theatre".intern();
private static final String s_track = "track".intern();
private static final String s_reinforced_slope = "reinforced_slope".intern();
private static final String s_slipway = "slipway".intern();
private static final String s_mangrove = "mangrove".intern();
private static final String s_aerodrome = "aerodrome".intern();
private static final String s_byway = "byway".intern();
private static final String s_metal = "metal".intern();
private static final String s_swamp = "swamp".intern();
private static final String s_construction = "construction".intern();
private static final String s_grassland = "grassland".intern();
private static final String s_shop = "shop".intern();
private static final String s_soakhole = "soakhole".intern();
private static final String s_asphalt = "asphalt".intern();
private static final String s_social_facility = "social_facility".intern();
private static final String s_isolated_dwelling = "isolated_dwelling".intern();
private static final String s_hamlet = "hamlet".intern();
private static final String s_picnic_table = "picnic_table".intern();
private static final String s_artificial = "artificial".intern();
private static final String s_earth = "earth".intern();
private static final String s_grit_bin = "grit_bin".intern();
private static final String s_ground = "ground".intern();
private static final String s_groyne = "groyne".intern();
private static final String s_office = "office".intern();
private static final String s_state = "state".intern();
private static final String s_terminal = "terminal".intern();
private static final String s_wood = "wood".intern();
private static final String s_fuel = "fuel".intern();
private static final String s_8 = "8".intern();
private static final String s_garden_centre = "garden_centre".intern();
private static final String s_horse_riding = "horse_riding".intern();
private static final String s_viewpoint = "viewpoint".intern();
private static final String s_designated = "designated".intern();
private static final String s_leisure = "leisure".intern();
private static final String s_waste_basket = "waste_basket".intern();
private static final String s_hifi = "hifi".intern();
private static final String s_hedge = "hedge".intern();
private static final String s_spur = "spur".intern();
private static final String s_chimney = "chimney".intern();
private static final String s_secondary = "secondary".intern();
private static final String s_rest_area = "rest_area".intern();
private static final String s_bar = "bar".intern();
private static final String s_bay = "bay".intern();
private static final String s_common = "common".intern();
private static final String s_river = "river".intern();
private static final String s_ruins = "ruins".intern();
private static final String s_terrace = "terrace".intern();
private static final String s_art = "art".intern();
private static final String s_residental = "residental".intern();
private static final String s_newsagent = "newsagent".intern();
private static final String s_turntable = "turntable".intern();
private static final String s_computer = "computer".intern();
private static final String s_wetland = "wetland".intern();
private static final String s_driveway = "driveway".intern();
private static final String s_parking = "parking".intern();
private static final String s_compacted = "compacted".intern();
private static final String s_barn = "barn".intern();
private static final String s_alpine_hut = "alpine_hut".intern();
private static final String s_wire_fence = "wire_fence".intern();
private static final String s_unpaved = "unpaved".intern();
private static final String s_dormitory = "dormitory".intern();
private static final String s_mud = "mud".intern();
private static final String s_3 = "3".intern();
private static final String s_semi = "semi".intern();
private static final String s_boundary = "boundary".intern();
private static final String s_field_boundary = "field_boundary".intern();
private static final String s_beverages = "beverages".intern();
private static final String s_supermarket = "supermarket".intern();
private static final String s_store = "store".intern();
private static final String s_restaurant = "restaurant".intern();
private static final String s_region = "region".intern();
private static final String s_variety_store = "variety_store".intern();
private static final String s_saltmarsh = "saltmarsh".intern();
private static final String s_landform = "landform".intern();
private static final String s_helipad = "helipad".intern();
private static final String s_railway = "railway".intern();
private static final String s_greenhouse_horticulture = "greenhouse_horticulture"
.intern();
private static final String s_wall = "wall".intern();
private static final String s_recycling = "recycling".intern();
private static final String s_passing_place = "passing_place".intern();
private static final String s_church = "church".intern();
private static final String s_pharmacy = "pharmacy".intern();
private static final String s_lighthouse = "lighthouse".intern();
private static final String s_platform = "platform".intern();
private static final String s_cinema = "cinema".intern();
private static final String s_political = "political".intern();
private static final String s_stadium = "stadium".intern();
private static final String s_basin = "basin".intern();
private static final String s_gasometer = "gasometer".intern();
private static final String s_bicycle_parking = "bicycle_parking".intern();
private static final String s_bbq = "bbq".intern();
private static final String s_incline_steep = "incline_steep".intern();
private static final String s_drinking_water = "drinking_water".intern();
private static final String s_living_street = "living_street".intern();
private static final String s_chalet = "chalet".intern();
private static final String s_narrow_gauge = "narrow_gauge".intern();
private static final String s_prison = "prison".intern();
private static final String s_mine = "mine".intern();
private static final String s_level_crossing = "level_crossing".intern();
private static final String s_water_works = "water_works".intern();
private static final String s_street_lamp = "street_lamp".intern();
private static final String s_main = "main".intern();
private static final String s_tank = "tank".intern();
private static final String s_abandoned = "abandoned".intern();
private static final String s_ski = "ski".intern();
private static final String s_runway = "runway".intern();
private static final String s_parking_space = "parking_space".intern();
private static final String s_dirt_sand = "dirt/sand".intern();
private static final String s_salt_pond = "salt_pond".intern();
private static final String s_hedge_bank = "hedge_bank".intern();
private static final String s_amenity = "amenity".intern();
private static final String s_telephone = "telephone".intern();
private static final String s_surface = "surface".intern();
private static final String s_travel_agency = "travel_agency".intern();
private static final String s_hardware = "hardware".intern();
private static final String s_wastewater_plant = "wastewater_plant".intern();
private static final String s_waterway = "waterway".intern();
private static final String s_butcher = "butcher".intern();
private static final String s_surveillance = "surveillance".intern();
private static final String s_Dirt_Sand = "Dirt/Sand".intern();
private static final String s_9 = "9".intern();
private static final String s_windmill = "windmill".intern();
private static final String s_picnic_site = "picnic_site".intern();
private static final String s_rail = "rail".intern();
private static final String s_cement = "cement".intern();
private static final String s_sauna = "sauna".intern();
private static final String s_suburb = "suburb".intern();
private static final String s_waterfall = "waterfall".intern();
private static final String s_bunker = "bunker".intern();
private static final String s_ice_cream = "ice_cream".intern();
private static final String s_culvert = "culvert".intern();
private static final String s_drain = "drain".intern();
private static final String s_dock = "dock".intern();
private static final String s_glasshouse = "glasshouse".intern();
private static final String s_no = "no".intern();
private static final String s_well = "well".intern();
private static final String s_wet_meadow = "wet_meadow".intern();
private static final String s_concrete = "concrete".intern();
private static final String s_dismount = "dismount".intern();
private static final String s_vending_machine = "vending_machine".intern();
private static final String s_oneway = "oneway".intern();
private static final String s_taxi = "taxi".intern();
private static final String s_outdoor = "outdoor".intern();
private static final String s_proposed = "proposed".intern();
private static final String s_sally_port = "sally_port".intern();
private static final String s_photo = "photo".intern();
private static final String s_plant_nursery = "plant_nursery".intern();
private static final String s_clinic = "clinic".intern();
private static final String s_fishing = "fishing".intern();
private static final String s_yes = "yes".intern();
private static final String s_turning_circle = "turning_circle".intern();
private static final String s_toilets = "toilets".intern();
private static final String s_guard_rail = "guard_rail".intern();
private static final String s_townhall = "townhall".intern();
private static final String s_community_centre = "community_centre".intern();
private static final String s_residential = "residential".intern();
private static final String s_cemetery = "cemetery".intern();
private static final String s_survey_point = "survey_point".intern();
private static final String s_bench = "bench".intern();
private static final String s_4 = "4".intern();
private static final String s_bollard = "bollard".intern();
private static final String s_sports_centre = "sports_centre".intern();
private static final String s_paving_stones_30 = "paving_stones:30".intern();
private static final String s_administrative = "administrative".intern();
private static final String s_Building = "Building".intern();
private static final String s_customers = "customers".intern();
private static final String s_emergency = "emergency".intern();
private static final String s_motorway_junction = "motorway_junction".intern();
private static final String s_grade1 = "grade1".intern();
private static final String s_grade3 = "grade3".intern();
private static final String s_grade2 = "grade2".intern();
private static final String s_grade5 = "grade5".intern();
private static final String s_grade4 = "grade4".intern();
private static final String s_lock_gate = "lock_gate".intern();
private static final String s_furniture = "furniture".intern();
private static final String s_place_of_worship = "place_of_worship".intern();
private static final String s_optician = "optician".intern();
private static final String s_gift = "gift".intern();
private static final String s_parking_entrance = "parking_entrance".intern();
private static final String s_garage = "garage".intern();
private static final String s_tram_stop = "tram_stop".intern();
private static final String s_steps = "steps".intern();
private static final String s_tower = "tower".intern();
private static final String s_works = "works".intern();
private static final String s_shed = "shed".intern();
private static final String s_car_sharing = "car_sharing".intern();
private static final String s_apartments = "apartments".intern();
private static final String s_spring = "spring".intern();
private static final String s_village = "village".intern();
private static final String s_library = "library".intern();
private static final String s_emergency_access = "emergency_access".intern();
private static final String s_home = "home".intern();
private static final String s_farm_auxiliary = "farm_auxiliary".intern();
private static final String s_primary_link = "primary_link".intern();
private static final String s_toll_booth = "toll_booth".intern();
private static final String s_jewelry = "jewelry".intern();
private static final String s_pet = "pet".intern();
private static final String s_veterinary = "veterinary".intern();
private static final String s_man_made = "man_made".intern();
private static final String s_motorway_link = "motorway_link".intern();
private static final String s_offices = "offices".intern();
private static final String s_power = "power".intern();
private static final String s_weir = "weir".intern();
private static final String s_unsurfaced = "unsurfaced".intern();
private static final String s_tertiary_link = "tertiary_link".intern();
private static final String s_trunk_link = "trunk_link".intern();
private static final String s_tyres = "tyres".intern();
private static final String s_paving_stones = "paving_stones".intern();
private static final String s_pipeline = "pipeline".intern();
private static final String s_census = "census".intern();
private static final String s_incline = "incline".intern();
private static final String s_footway = "footway".intern();
private static final String s_drive_through = "drive-through".intern();
private static final String s_island = "island".intern();
private static final String s_monitoring_station = "monitoring_station".intern();
private static final String s_nightclub = "nightclub".intern();
private static final String s_unclassified = "unclassified".intern();
private static final String s_aquaculture = "aquaculture".intern();
private static final String s_mixed = "mixed".intern();
private static final String s_road = "road".intern();
private static final String s_greenfield = "greenfield".intern();
private static final String s_breakwater = "breakwater".intern();
private static final String s_services = "services".intern();
private static final String s_railway_crossing = "railway_crossing".intern();
private static final String s_residentiel1 = "residentiel1".intern();
private static final String s_canal = "canal".intern();
private static final String s__1 = "-1".intern();
private static final String s_ridge = "ridge".intern();
private static final String s_fabric = "fabric".intern();
private static final String s_museum = "museum".intern();
private static final String s_communications_tower = "communications_tower".intern();
private static final String s_semi_detached = "semi-detached".intern();
private static final String s_conservation = "conservation".intern();
private static final String s_way = "way".intern();
private static final String s_wood_fence = "wood_fence".intern();
private static final String s_manufacture = "manufacture".intern();
private static final String s_admin_level = "admin_level".intern();
private static final String s_building_concrete = "building_concrete".intern();
private static final String s_bus = "bus".intern();
private static final String s_collapsed = "collapsed".intern();
private static final String s_ford = "ford".intern();
private static final String s_delivery = "delivery".intern();
private static final String s_garages = "garages".intern();
private static final String s_funeral_directors = "funeral_directors".intern();
private static final String s_land = "land".intern();
private static final String s_interlock = "interlock".intern();
private static final String s_reef = "reef".intern();
private static final String s_crane = "crane".intern();
private static final String s_true = "true".intern();
private static final String s_storage_tank = "storage_tank".intern();
private static final String s_official = "official".intern();
private static final String s_subway_entrance = "subway_entrance".intern();
private static final String s_mtb = "mtb".intern();
private static final String s_grass = "grass".intern();
private static final String s_marketplace = "marketplace".intern();
private static final String s_rapids = "rapids".intern();
private static final String s_car_wash = "car_wash".intern();
private static final String s_general = "general".intern();
private static final String s_cafe = "cafe".intern();
private static final String s_locality = "locality".intern();
private static final String s_glacier = "glacier".intern();
private static final String s_storage = "storage".intern();
private static final String s_cycleway = "cycleway".intern();
private static final String s_forestry = "forestry".intern();
private static final String s_field = "field".intern();
private static final String s_5 = "5".intern();
private static final String s_arts_centre = "arts_centre".intern();
private static final String s_warehouse = "warehouse".intern();
private static final String s_chemist = "chemist".intern();
private static final String s_pier = "pier".intern();
private static final String s_scrub = "scrub".intern();
private static final String s_shelter = "shelter".intern();
private static final String s_emergency_phone = "emergency_phone".intern();
private static final String s_tidalflat = "tidalflat".intern();
private static final String s_cobblestone = "cobblestone".intern();
private static final String s_fell = "fell".intern();
private static final String s_peak = "peak".intern();
private static final String s_charging_station = "charging_station".intern();
private static final String s_cliff = "cliff".intern();
private static final String s_building = "building".intern();
private static final String s_fire_hydrant = "fire_hydrant".intern();
private static final String s_traffic_signals = "traffic_signals".intern();
private static final String s_heath = "heath".intern();
private static final String s_landfill = "landfill".intern();
private static final String s_mast = "mast".intern();
private static final String s_boutique = "boutique".intern();
private static final String s_boat_storage = "boat_storage".intern();
public final static Tag[] tags = {
new Tag(s_building, s_yes, true), new Tag(s_highway, s_residential, true),
new Tag(s_highway, s_service, true), new Tag(s_waterway, s_stream, true),
new Tag(s_highway, s_unclassified, true), new Tag(s_highway, s_track, true),
new Tag(s_oneway, s_yes, true), new Tag(s_natural, s_water, true),
new Tag(s_highway, s_footway, true), new Tag(s_access, s_private, true),
new Tag(s_highway, s_tertiary, true), new Tag(s_highway, s_path, true),
new Tag(s_highway, s_secondary, true), new Tag(s_landuse, s_forest, true),
new Tag(s_bridge, s_yes, true), new Tag(s_natural, s_tree, true),
new Tag(s_surface, s_paved, true), new Tag(s_natural, s_wood, true),
new Tag(s_highway, s_primary, true), new Tag(s_landuse, s_grass, true),
new Tag(s_landuse, s_residential, true), new Tag(s_surface, s_unpaved, true),
new Tag(s_highway, s_bus_stop, true), new Tag(s_surface, s_asphalt, true),
new Tag(s_bicycle, s_yes, true), new Tag(s_amenity, s_parking, true),
new Tag(s_place, s_locality, true), new Tag(s_railway, s_rail, true),
new Tag(s_service, s_parking_aisle, true),
new Tag(s_boundary, s_administrative, true),
new Tag(s_building, s_house, true), new Tag(s_place, s_village, true),
new Tag(s_natural, s_coastline, true), new Tag(s_tracktype, s_grade2, true),
new Tag(s_oneway, s_no, true), new Tag(s_service, s_driveway, true),
new Tag(s_highway, s_turning_circle, true), new Tag(s_place, s_hamlet, true),
new Tag(s_natural, s_wetland, true), new Tag(s_tracktype, s_grade3, true),
new Tag(s_waterway, s_river, true), new Tag(s_highway, s_cycleway, true),
new Tag(s_barrier, s_fence, true), new Tag(s_building, s_residential, true),
new Tag(s_amenity, s_school, true), new Tag(s_highway, s_crossing, true),
new Tag(s_admin_level, s_8, true), new Tag(s_highway, s_trunk, true),
new Tag(s_amenity, s_place_of_worship, true),
new Tag(s_landuse, s_farmland, true), new Tag(s_tracktype, s_grade1, true),
new Tag(s_highway, s_road, true), new Tag(s_landuse, s_farm, true),
new Tag(s_surface, s_gravel, true), new Tag(s_landuse, s_meadow, true),
new Tag(s_highway, s_motorway, true),
new Tag(s_highway, s_traffic_signals, true),
new Tag(s_building, s_hut, true), new Tag(s_highway, s_motorway_link, true),
new Tag(s_tracktype, s_grade4, true), new Tag(s_barrier, s_gate, true),
new Tag(s_highway, s_living_street, true), new Tag(s_bicycle, s_no, true),
new Tag(s_leisure, s_pitch, true), new Tag(s_tunnel, s_yes, true),
new Tag(s_surface, s_ground, true), new Tag(s_highway, s_steps, true),
new Tag(s_natural, s_land, true), new Tag(s_man_made, s_survey_point, true),
new Tag(s_tracktype, s_grade5, true), new Tag(s_waterway, s_ditch, true),
new Tag(s_leisure, s_park, true), new Tag(s_amenity, s_restaurant, true),
new Tag(s_barrier, s_wall, true), new Tag(s_waterway, s_riverbank, true),
new Tag(s_amenity, s_bench, true), new Tag(s_building, s_garage, true),
new Tag(s_natural, s_scrub, true), new Tag(s_highway, s_pedestrian, true),
new Tag(s_natural, s_peak, true), new Tag(s_building, s_entrance, true),
new Tag(s_landuse, s_reservoir, true), new Tag(s_access, s_yes, true),
new Tag(s_bicycle, s_designated, true),
new Tag(s_leisure, s_swimming_pool, true),
new Tag(s_landuse, s_farmyard, true),
new Tag(s_railway, s_level_crossing, true),
new Tag(s_building, s_apartments, true), new Tag(s_surface, s_grass, true),
new Tag(s_wheelchair, s_yes, true), new Tag(s_service, s_alley, true),
new Tag(s_landuse, s_industrial, true), new Tag(s_amenity, s_fuel, true),
new Tag(s_surface, s_dirt, true), new Tag(s_highway, s_trunk_link, true),
new Tag(s_waterway, s_drain, true), new Tag(s_barrier, s_hedge, true),
new Tag(s_amenity, s_grave_yard, true),
new Tag(s_tourism, s_information, true),
new Tag(s_shop, s_supermarket, true),
new Tag(s_highway, s_primary_link, true), new Tag(s_wood, s_deciduous, true),
new Tag(s_leisure, s_playground, true), new Tag(s_building, s_roof, true),
new Tag(s_building, s_industrial, true),
new Tag(s_amenity, s_post_box, true), new Tag(s_waterway, s_canal, true),
new Tag(s_barrier, s_bollard, true), new Tag(s_leisure, s_garden, true),
new Tag(s_wood, s_mixed, true), new Tag(s_landuse, s_cemetery, true),
new Tag(s_landuse, s_orchard, true), new Tag(s_shop, s_convenience, true),
new Tag(s_access, s_permissive, true), new Tag(s_surface, s_concrete, true),
new Tag(s_surface, s_paving_stones, true), new Tag(s_service, s_spur, true),
new Tag(s_building, s_garages, true), new Tag(s_amenity, s_bank, true),
new Tag(s_tourism, s_hotel, true), new Tag(s_access, s_no, true),
new Tag(s_amenity, s_fast_food, true), new Tag(s_man_made, s_pier, true),
new Tag(s_amenity, s_kindergarten, true),
new Tag(s_access, s_agricultural, true),
new Tag(s_surface, s_cobblestone, true), new Tag(s_wheelchair, s_no, true),
new Tag(s_amenity, s_cafe, true), new Tag(s_amenity, s_hospital, true),
new Tag(s_amenity, s_post_office, true),
new Tag(s_amenity, s_public_building, true),
new Tag(s_amenity, s_recycling, true),
new Tag(s_highway, s_street_lamp, true), new Tag(s_man_made, s_tower, true),
new Tag(s_waterway, s_dam, true), new Tag(s_amenity, s_pub, true),
new Tag(s_wood, s_coniferous, true), new Tag(s_access, s_destination, true),
new Tag(s_admin_level, s_6, true), new Tag(s_landuse, s_commercial, true),
new Tag(s_amenity, s_pharmacy, true), new Tag(s_railway, s_abandoned, true),
new Tag(s_service, s_yard, true), new Tag(s_place, s_island, true),
new Tag(s_oneway, s__1, true), new Tag(s_landuse, s_quarry, true),
new Tag(s_landuse, s_vineyard, true),
new Tag(s_highway, s_motorway_junction, true),
new Tag(s_railway, s_station, true), new Tag(s_landuse, s_allotments, true),
new Tag(s_barrier, s_lift_gate, true), new Tag(s_admin_level, s_10, true),
new Tag(s_amenity, s_telephone, true), new Tag(s_place, s_town, true),
new Tag(s_man_made, s_cutline, true), new Tag(s_place, s_suburb, true),
new Tag(s_aeroway, s_taxiway, true), new Tag(s_wheelchair, s_limited, true),
new Tag(s_highway, s_secondary_link, true),
new Tag(s_leisure, s_sports_centre, true),
new Tag(s_amenity, s_bicycle_parking, true),
new Tag(s_surface, s_sand, true), new Tag(s_highway, s_stop, true),
new Tag(s_man_made, s_works, true), new Tag(s_landuse, s_retail, true),
new Tag(s_amenity, s_fire_station, true), new Tag(s_service, s_siding, true),
new Tag(s_amenity, s_toilets, true), new Tag(s_bench, s_yes, true),
new Tag(s_oneway, s_1, true), new Tag(s_surface, s_compacted, true),
new Tag(s_landuse, s_basin, true), new Tag(s_amenity, s_police, true),
new Tag(s_railway, s_tram, true), new Tag(s_route, s_road, true),
new Tag(s_natural, s_cliff, true), new Tag(s_highway, s_construction, true),
new Tag(s_aeroway, s_aerodrome, true), new Tag(s_entrance, s_yes, true),
new Tag(s_man_made, s_storage_tank, true), new Tag(s_amenity, s_atm, true),
new Tag(s_tourism, s_attraction, true), new Tag(s_route, s_bus, true),
new Tag(s_shop, s_bakery, true), new Tag(s_tourism, s_viewpoint, true),
new Tag(s_amenity, s_swimming_pool, true), new Tag(s_natural, s_beach, true),
new Tag(s_tourism, s_picnic_site, true), new Tag(s_oneway, s_true, true),
new Tag(s_highway, s_bridleway, true), new Tag(s_tourism, s_camp_site, true),
new Tag(s_abutters, s_residential, true),
new Tag(s_leisure, s_nature_reserve, true),
new Tag(s_amenity, s_drinking_water, true), new Tag(s_shop, s_clothes, true),
new Tag(s_natural, s_heath, true),
new Tag(s_highway, s_mini_roundabout, true),
new Tag(s_landuse, s_construction, true),
new Tag(s_amenity, s_waste_basket, true),
new Tag(s_railway, s_platform, true), new Tag(s_amenity, s_townhall, true),
new Tag(s_shop, s_hairdresser, true), new Tag(s_amenity, s_shelter, true),
new Tag(s_admin_level, s_9, true),
new Tag(s_building, s_farm_auxiliary, true),
new Tag(s_amenity, s_library, true), new Tag(s_building, s_detached, true),
new Tag(s_admin_level, s_4, true), new Tag(s_landuse, s_village_green, true),
new Tag(s_barrier, s_stile, true), new Tag(s_landuse, s_garages, true),
new Tag(s_amenity, s_bar, true), new Tag(s_railway, s_buffer_stop, true),
new Tag(s_wetland, s_marsh, true), new Tag(s_tourism, s_museum, true),
new Tag(s_barrier, s_cycle_barrier, true), new Tag(s_route, s_bicycle, true),
new Tag(s_railway, s_tram_stop, true),
new Tag(s_amenity, s_parking_space, true),
new Tag(s_barrier, s_retaining_wall, true),
new Tag(s_landuse, s_recreation_ground, true),
new Tag(s_amenity, s_university, true),
new Tag(s_highway, s_tertiary_link, true),
new Tag(s_building, s_terrace, true), new Tag(s_shop, s_car_repair, true),
new Tag(s_amenity, s_hunting_stand, true),
new Tag(s_amenity, s_fountain, true), new Tag(s_man_made, s_pipeline, true),
new Tag(s_wetland, s_swamp, true), new Tag(s_shop, s_car, true),
new Tag(s_bench, s_no, true), new Tag(s_tunnel, s_culvert, true),
new Tag(s_building, s_school, true), new Tag(s_barrier, s_entrance, true),
new Tag(s_railway, s_disused, true), new Tag(s_railway, s_crossing, true),
new Tag(s_building, s_church, true),
new Tag(s_amenity, s_social_facility, true), new Tag(s_natural, s_bay, true),
new Tag(s_shop, s_kiosk, true), new Tag(s_amenity, s_vending_machine, true),
new Tag(s_route, s_hiking, true), new Tag(s_natural, s_spring, true),
new Tag(s_leisure, s_common, true), new Tag(s_railway, s_switch, true),
new Tag(s_waterway, s_rapids, true), new Tag(s_admin_level, s_7, true),
new Tag(s_leisure, s_stadium, true), new Tag(s_leisure, s_track, true),
new Tag(s_place, s_isolated_dwelling, true), new Tag(s_place, s_islet, true),
new Tag(s_waterway, s_weir, true), new Tag(s_amenity, s_doctors, true),
new Tag(s_access, s_designated, true),
new Tag(s_landuse, s_conservation, true),
new Tag(s_waterway, s_artificial, true),
new Tag(s_amenity, s_bus_station, true),
new Tag(s_leisure, s_golf_course, true),
new Tag(s_shop, s_doityourself, true), new Tag(s_building, s_service, true),
new Tag(s_tourism, s_guest_house, true), new Tag(s_aeroway, s_runway, true),
new Tag(s_place, s_city, true), new Tag(s_railway, s_subway, true),
new Tag(s_man_made, s_wastewater_plant, true),
new Tag(s_building, s_commercial, true), new Tag(s_railway, s_halt, true),
new Tag(s_amenity, s_emergency_phone, true),
new Tag(s_building, s_retail, true), new Tag(s_barrier, s_block, true),
new Tag(s_leisure, s_recreation_ground, true),
new Tag(s_access, s_forestry, true), new Tag(s_amenity, s_college, true),
new Tag(s_highway, s_platform, true), new Tag(s_access, s_unknown, true),
new Tag(s_man_made, s_water_tower, true),
new Tag(s_surface, s_pebblestone, true), new Tag(s_bridge, s_viaduct, true),
new Tag(s_shop, s_butcher, true), new Tag(s_shop, s_florist, true),
new Tag(s_boundary, s_landuse, true), new Tag(s_aeroway, s_helipad, true),
new Tag(s_building, s_hangar, true), new Tag(s_natural, s_glacier, true),
new Tag(s_highway, s_proposed, true), new Tag(s_shop, s_mall, true),
new Tag(s_barrier, s_toll_booth, true),
new Tag(s_amenity, s_fire_hydrant, true),
new Tag(s_building, s_manufacture, true), new Tag(s_building, s_farm, true),
new Tag(s_surface, s_wood, true), new Tag(s_amenity, s_car_wash, true),
new Tag(s_amenity, s_dentist, true), new Tag(s_natural, s_marsh, true),
new Tag(s_man_made, s_surveillance, true), new Tag(s_shop, s_bicycle, true),
new Tag(s_route, s_foot, true), new Tag(s_amenity, s_theatre, true),
new Tag(s_building, s_office, true), new Tag(s_railway, s_light_rail, true),
new Tag(s_man_made, s_petroleum_well, true),
new Tag(s_amenity, s_taxi, true), new Tag(s_building, s_greenhouse, true),
new Tag(s_landuse, s_brownfield, true),
new Tag(s_bicycle, s_permissive, true), new Tag(s_admin_level, s_2, true),
new Tag(s_aeroway, s_apron, true), new Tag(s_building, s_cabin, true),
new Tag(s_amenity, s_cinema, true), new Tag(s_access, s_customers, true),
new Tag(s_tourism, s_motel, true), new Tag(s_railway, s_narrow_gauge, true),
new Tag(s_amenity, s_marketplace, true), new Tag(s_shop, s_furniture, true),
new Tag(s_entrance, s_staircase, true), new Tag(s_tourism, s_artwork, true),
new Tag(s_natural, s_grassland, true), new Tag(s_shop, s_books, true),
new Tag(s_admin_level, s_5, true), new Tag(s_man_made, s_groyne, true),
new Tag(s_waterway, s_lock_gate, true),
new Tag(s_highway, s_emergency_access_point, true),
new Tag(s_natural, s_sand, true), new Tag(s_landuse, s_military, true),
new Tag(s_boundary, s_protected_area, true),
new Tag(s_amenity, s_community_centre, true),
new Tag(s_barrier, s_kissing_gate, true),
new Tag(s_highway, s_speed_camera, true),
new Tag(s_boundary, s_national_park, true),
new Tag(s_railway, s_subway_entrance, true),
new Tag(s_man_made, s_silo, true), new Tag(s_shop, s_alcohol, true),
new Tag(s_highway, s_give_way, true), new Tag(s_leisure, s_slipway, true),
new Tag(s_shop, s_electronics, true), new Tag(s_bicycle, s_dismount, true),
new Tag(s_leisure, s_marina, true), new Tag(s_entrance, s_main, true),
new Tag(s_boundary, s_postal_code, true),
new Tag(s_landuse, s_greenhouse_horticulture, true),
new Tag(s_highway, s_milestone, true),
new Tag(s_natural, s_cave_entrance, true),
new Tag(s_landuse, s_landfill, true), new Tag(s_shop, s_chemist, true),
new Tag(s_shop, s_shoes, true), new Tag(s_barrier, s_cattle_grid, true),
new Tag(s_landuse, s_railway, true), new Tag(s_tourism, s_hostel, true),
new Tag(s_tourism, s_chalet, true), new Tag(s_place, s_county, true),
new Tag(s_shop, s_department_store, true), new Tag(s_highway, s_ford, true),
new Tag(s_natural, s_scree, true), new Tag(s_landuse, s_greenfield, true),
new Tag(s_amenity, s_nursing_home, true),
new Tag(s_barrier, s_wire_fence, true),
new Tag(s_access, s_restricted, true),
new Tag(s_man_made, s_reservoir_covered, true),
new Tag(s_amenity, s_bicycle_rental, true), new Tag(s_man_made, s_MDF, true),
new Tag(s_man_made, s_water_well, true), new Tag(s_landuse, s_field, true),
new Tag(s_landuse, s_wood, true), new Tag(s_shop, s_hardware, true),
new Tag(s_tourism, s_alpine_hut, true), new Tag(s_natural, s_tree_row, true),
new Tag(s_tourism, s_caravan_site, true), new Tag(s_bridge, s_no, true),
new Tag(s_wetland, s_bog, true), new Tag(s_amenity, s_courthouse, true),
new Tag(s_route, s_ferry, true), new Tag(s_barrier, s_city_wall, true),
new Tag(s_amenity, s_veterinary, true), new Tag(s_shop, s_jewelry, true),
new Tag(s_building, s_transportation, true),
new Tag(s_amenity, s_arts_centre, true),
new Tag(s_bicycle, s_official, true), new Tag(s_shop, s_optician, true),
new Tag(s_shop, s_yes, true), new Tag(s_building, s_collapsed, true),
new Tag(s_shop, s_garden_centre, true), new Tag(s_man_made, s_chimney, true),
new Tag(s_man_made, s_mine, true), new Tag(s_bench, s_unknown, true),
new Tag(s_railway, s_preserved, true), new Tag(s_building, s_public, true),
new Tag(s_amenity, s_ferry_terminal, true),
new Tag(s_highway, s_raceway, true), new Tag(s_natural, s_rock, true),
new Tag(s_tunnel, s_no, true), new Tag(s_building, s_university, true),
new Tag(s_shop, s_beverages, true),
new Tag(s_amenity, s_waste_disposal, true),
new Tag(s_building, s_warehouse, true),
new Tag(s_leisure, s_water_park, true), new Tag(s_shop, s_gift, true),
new Tag(s_place, s_farm, true), new Tag(s_wetland, s_tidalflat, true),
new Tag(s_waterway, s_waterfall, true), new Tag(s_man_made, s_dolphin, true),
new Tag(s_service, s_drive_through, true),
new Tag(s_amenity, s_nightclub, true), new Tag(s_building, s_shed, true),
new Tag(s_shop, s_greengrocer, true), new Tag(s_natural, s_fell, true),
new Tag(s_wetland, s_wet_meadow, true), new Tag(s_aeroway, s_gate, true),
new Tag(s_shop, s_computer, true), new Tag(s_man_made, s_lighthouse, true),
new Tag(s_wetland, s_reedbed, true), new Tag(s_man_made, s_breakwater, true),
new Tag(s_surface, s_Dirt_Sand, true), new Tag(s_barrier, s_ditch, true),
new Tag(s_barrier, s_yes, true), new Tag(s_amenity, s_biergarten, true),
new Tag(s_shop, s_mobile_phone, true), new Tag(s_route, s_mtb, true),
new Tag(s_amenity, s_grit_bin, true), new Tag(s_amenity, s_bbq, true),
new Tag(s_shop, s_sports, true), new Tag(s_barrier, s_wood_fence, true),
new Tag(s_entrance, s_home, true), new Tag(s_shop, s_laundry, true),
new Tag(s_man_made, s_gasometer, true),
new Tag(s_barrier, s_embankment, true), new Tag(s_shop, s_toys, true),
new Tag(s_wetland, s_saltmarsh, true), new Tag(s_waterway, s_soakhole, true),
new Tag(s_shop, s_travel_agency, true),
new Tag(s_man_made, s_water_works, true), new Tag(s_route, s_railway, true),
new Tag(s_amenity, s_prison, true), new Tag(s_highway, s_rest_area, true),
new Tag(s_shop, s_stationery, true), new Tag(s_admin_level, s_11, true),
new Tag(s_building, s_train_station, true),
new Tag(s_building, s_storage_tank, true),
new Tag(s_man_made, s_windmill, true), new Tag(s_shop, s_beauty, true),
new Tag(s_building, s_semi, true), new Tag(s_highway, s_services, true),
new Tag(s_bicycle, s_private, true), new Tag(s_route, s_ski, true),
new Tag(s_service, s_emergency_access, true),
new Tag(s_building, s_factory, true),
new Tag(s_man_made, s_reinforced_slope, true),
new Tag(s_amenity, s_car_sharing, true), new Tag(s_surface, s_earth, true),
new Tag(s_shop, s_hifi, true), new Tag(s_amenity, s_car_rental, true),
new Tag(s_barrier, s_hedge_bank, true),
new Tag(s_shop, s_confectionery, true), new Tag(s_aeroway, s_terminal, true),
new Tag(s_highway, s_passing_place, true),
new Tag(s_building, s_building, true), new Tag(s_man_made, s_dyke, true),
new Tag(s_building, s_construction, true), new Tag(s_building, s_shop, true),
new Tag(s_natural, s_reef, true), new Tag(s_landuse, s_aquaculture, true),
new Tag(s_shop, s_dry_cleaning, true), new Tag(s_amenity, s_embassy, true),
new Tag(s_shop, s_newsagent, true), new Tag(s_landuse, s_salt_pond, true),
new Tag(s_railway, s_spur, true), new Tag(s_wheelchair, s_unknown, true),
new Tag(s_tourism, s_zoo, true), new Tag(s_man_made, s_waterway, true),
new Tag(s_surface, s_fine_gravel, true), new Tag(s_shop, s_motorcycle, true),
new Tag(s_building, s_Building, true),
new Tag(s_railway, s_construction, true),
new Tag(s_place, s_neighbourhood, true), new Tag(s_route, s_train, true),
new Tag(s_building, s_no, true), new Tag(s_natural, s_mud, true),
new Tag(s_place, s_region, true),
new Tag(s_landuse, s_reservoir_watershed, true),
new Tag(s_boundary, s_marker, true), new Tag(s_man_made, s_beacon, true),
new Tag(s_shop, s_outdoor, true), new Tag(s_access, s_public, true),
new Tag(s_abutters, s_industrial, true), new Tag(s_building, s_barn, true),
new Tag(s_leisure, s_picnic_table, true),
new Tag(s_building, s_hospital, true), new Tag(s_access, s_official, true),
new Tag(s_shop, s_variety_store, true), new Tag(s_man_made, s_crane, true),
new Tag(s_amenity, s_parking_fuel, true), new Tag(s_route, s_tram, true),
new Tag(s_tourism, s_theme_park, true), new Tag(s_shop, s_pet, true),
new Tag(s_building, s_kindergarten, true),
new Tag(s_man_made, s_storage, true), new Tag(s_man_made, s_mast, true),
new Tag(s_amenity, s_parking_entrance, true),
new Tag(s_amenity, s_clock, true),
new Tag(s_landuse, s_industrial_retail, true),
new Tag(s_shop, s_video, true), new Tag(s_access, s_delivery, true),
new Tag(s_amenity, s_driving_school, true), new Tag(s_service, s_yes, true),
new Tag(s_natural, s_bare_rock, true), new Tag(s_building, s_chapel, true),
new Tag(s_natural, s_volcano, true), new Tag(s_waterway, s_dock, true),
new Tag(s_building, s_dormitory, true),
new Tag(s_amenity, s_boat_storage, true), new Tag(s_man_made, s_tank, true),
new Tag(s_man_made, s_flagpole, true),
new Tag(s_surface, s_grass_paver, true), new Tag(s_shop, s_organic, true),
new Tag(s_natural, s_landform, true), new Tag(s_highway, s_unsurfaced, true),
new Tag(s_route, s_power, true), new Tag(s_surface, s_mud, true),
new Tag(s_building, s_building_concrete, true),
new Tag(s_abutters, s_retail, true), new Tag(s_building, s_store, true),
new Tag(s_shop, s_vacant, true), new Tag(s_leisure, s_miniature_golf, true),
new Tag(s_man_made, s_monitoring_station, true),
new Tag(s_natural, s_waterfall, true), new Tag(s_aeroway, s_hangar, true),
new Tag(s_shop, s_boutique, true), new Tag(s_route, s_detour, true),
new Tag(s_building, s_way, true), new Tag(s_railway, s_stop, true),
new Tag(s_amenity, s_ice_cream, true), new Tag(s_building, s_storage, true),
new Tag(s_shop, s_car_parts, true), new Tag(s_natural, s_ridge, true),
new Tag(s_shop, s_tyres, true), new Tag(s_railway, s_dismantled, true),
new Tag(s_amenity, s_shop, true), new Tag(s_landuse, s_plant_nursery, true),
new Tag(s_building, s_residentiel1, true),
new Tag(s_barrier, s_field_boundary, true),
new Tag(s_barrier, s_border_control, true),
new Tag(s_surface, s_Paved, true), new Tag(s_barrier, s_sally_port, true),
new Tag(s_amenity, s_bureau_de_change, true),
new Tag(s_leisure, s_fishing, true),
new Tag(s_amenity, s_charging_station, true),
new Tag(s_building, s_supermarket, true), new Tag(s_highway, s_stile, true),
new Tag(s_amenity, s_sauna, true), new Tag(s_place, s_municipality, true),
new Tag(s_building, s_hotel, true), new Tag(s_surface, s_metal, true),
new Tag(s_highway, s_incline_steep, true),
new Tag(s_shop, s_estate_agent, true), new Tag(s_natural, s_grass, true),
new Tag(s_shop, s_pharmacy, true),
new Tag(s_surface, s_concrete_plates, true),
new Tag(s_shop, s_copyshop, true),
new Tag(s_surface, s_paving_stones_30, true),
new Tag(s_surface, s_interlock, true), new Tag(s_access, s_hov, true),
new Tag(s_highway, s_elevator, true),
new Tag(s_boundary, s_local_authority, true),
new Tag(s_man_made, s_communications_tower, true),
new Tag(s_shop, s_deli, true), new Tag(s_barrier, s_turnstile, true),
new Tag(s_building, s_offices, true), new Tag(s_building, s_bunker, true),
new Tag(s_natural, s_stone, true),
new Tag(s_railway, s_railway_crossing, true),
new Tag(s_leisure, s_dog_park, true),
new Tag(s_building, s_semi_detached, true),
new Tag(s_man_made, s_watermill, true), new Tag(s_route, s_trolleybus, true),
new Tag(s_admin_level, s_3, true), new Tag(s_building, s_block, true),
new Tag(s_barrier, s_guard_rail, true), new Tag(s_bicycle, s_unknown, true),
new Tag(s_highway, s_abandoned, true), new Tag(s_surface, s_dirt_sand, true),
new Tag(s_barrier, s_chain, true), new Tag(s_barrier, s_bump_gate, true),
new Tag(s_building, s_residental, true), new Tag(s_surface, s_cement, true),
new Tag(s_man_made, s_embankment, true), new Tag(s_building, s_ruins, true),
new Tag(s_highway, s_incline, true), new Tag(s_abutters, s_commercial, true),
new Tag(s_barrier, s_hampshire_gate, true), new Tag(s_shop, s_music, true),
new Tag(s_shop, s_funeral_directors, true),
new Tag(s_wetland, s_mangrove, true), new Tag(s_place, s_borough, true),
new Tag(s_building, s_apartment, true), new Tag(s_boundary, s_census, true),
new Tag(s_barrier, s_kerb, true), new Tag(s_building, s_glasshouse, true),
new Tag(s_aeroway, s_holding_position, true),
new Tag(s_shop, s_general, true), new Tag(s_building, s_tank, true),
new Tag(s_railway, s_monorail, true), new Tag(s_service, s_parking, true),
new Tag(s_place, s_state, true), new Tag(s_railway, s_proposed, true),
new Tag(s_shop, s_art, true), new Tag(s_natural, s_hill, true),
new Tag(s_railway, s_turntable, true), new Tag(s_tourism, s_cabin, true),
new Tag(s_shop, s_photo, true), new Tag(s_boundary, s_lot, true),
new Tag(s_shop, s_fishmonger, true), new Tag(s_amenity, s_clinic, true),
new Tag(s_boundary, s_political, true), new Tag(s_man_made, s_well, true),
new Tag(s_highway, s_byway, true), new Tag(s_leisure, s_horse_riding, true),
new Tag(s_service, s_bus, true), new Tag(s_building, s_tower, true),
new Tag(s_entrance, s_service, true), new Tag(s_shop, s_fabric, true),
new Tag(s_railway, s_miniature, true), new Tag(s_abutters, s_mixed, true),
new Tag(s_surface, s_stone, true), new Tag(s_access, s_emergency, true),
new Tag(s_landuse, s_mine, true), new Tag(s_amenity, s_shower, true),
new Tag(s_waterway, s_lock, true)
};
}

View File

@@ -0,0 +1,372 @@
/*
* Geometry.java
*
* PostGIS extension for PostgreSQL JDBC driver - geometry model
*
* (C) 2004 Paul Ramsey, pramsey@refractions.net
*
* (C) 2005 Markus Schaber, markus.schaber@logix-tt.com
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General License as published by the Free
* Software Foundation, either version 2.1 of the License.
*
* This library 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 License for more
* details.
*
* You should have received a copy of the GNU Lesser General License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
* http://www.gnu.org.
*
* $Id: Geometry.java 9324 2012-02-27 22:08:12Z pramsey $
*/
package org.oscim.database.postgis;
import java.io.Serializable;
/** The base class of all geometries */
abstract class Geometry implements Serializable {
/* JDK 1.5 Serialization */
private static final long serialVersionUID = 0x100;
// OpenGIS Geometry types as defined in the OGC WKB Spec
// (May we replace this with an ENUM as soon as JDK 1.5
// has gained widespread usage?)
/** Fake type for linear ring */
static final int LINEARRING = 0;
/**
* The OGIS geometry type number for points.
*/
static final int POINT = 1;
/**
* The OGIS geometry type number for lines.
*/
static final int LINESTRING = 2;
/**
* The OGIS geometry type number for polygons.
*/
static final int POLYGON = 3;
/**
* The OGIS geometry type number for aggregate points.
*/
static final int MULTIPOINT = 4;
/**
* The OGIS geometry type number for aggregate lines.
*/
static final int MULTILINESTRING = 5;
/**
* The OGIS geometry type number for aggregate polygons.
*/
static final int MULTIPOLYGON = 6;
/**
* The OGIS geometry type number for feature collections.
*/
static final int GEOMETRYCOLLECTION = 7;
static final String[] ALLTYPES = new String[] {
"", // internally used LinearRing does not have any text in front of
// it
"POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING",
"MULTIPOLYGON", "GEOMETRYCOLLECTION" };
/**
* The Text representations of the geometry types
*
* @param type
* ...
* @return ...
*/
static String getTypeString(int type) {
if (type >= 0 && type <= 7)
return ALLTYPES[type];
throw new IllegalArgumentException("Unknown Geometry type" + type);
}
// Properties common to all geometries
/**
* The dimensionality of this feature (2,3)
*/
int dimension;
/**
* Do we have a measure (4th dimension)
*/
boolean haveMeasure = false;
/**
* The OGIS geometry type of this feature. this is final as it never changes, it is bound to the subclass of the
* instance.
*/
final int type;
/**
* Official UNKNOWN srid value
*/
final static int UNKNOWN_SRID = 0;
/**
* The spacial reference system id of this geometry, default is no srid
*/
int srid = UNKNOWN_SRID;
/**
* Parse a SRID value, anything <= 0 is unknown
*
* @param srid
* ...
* @return ...
*/
static int parseSRID(int srid) {
if (srid < 0) {
/* TODO: raise a warning ? */
return 0;
}
return srid;
}
/**
* Constructor for subclasses
*
* @param type
* has to be given by all subclasses.
*/
protected Geometry(int type) {
this.type = type;
}
/**
* java.lang.Object hashCode implementation
*/
@Override
public int hashCode() {
return dimension | (type * 4) | (srid * 32);
}
/**
* java.lang.Object equals implementation
*/
@Override
public boolean equals(Object other) {
return (other != null) && (other instanceof Geometry)
&& equals((Geometry) other);
}
/**
* geometry specific equals implementation - only defined for non-null values
*
* @param other
* ...
* @return ...
*/
public boolean equals(Geometry other) {
return (other != null) && (this.dimension == other.dimension)
&& (this.type == other.type) && (this.srid == other.srid)
&& (this.haveMeasure == other.haveMeasure)
&& other.getClass().equals(this.getClass())
&& this.equalsintern(other);
}
/**
* Whether test coordinates for geometry - subclass specific code Implementors can assume that dimensin, type, srid
* and haveMeasure are equal, other != null and other is the same subclass.
*
* @param other
* ...
* @return ...
*/
protected abstract boolean equalsintern(Geometry other);
/**
* Return the number of Points of the geometry
*
* @return ...
*/
abstract int numPoints();
/**
* Get the nth Point of the geometry
*
* @param n
* the index of the point, from 0 to numPoints()-1;
* @throws ArrayIndexOutOfBoundsException
* in case of an emtpy geometry or bad index.
*/
// abstract Point getPoint(int n);
//
// /**
// * Same as getPoint(0);
// */
// abstract Point getFirstPoint();
//
// /**
// * Same as getPoint(numPoints()-1);
// */
// abstract Point getLastPoint();
/**
* The OGIS geometry type number of this geometry.
*
* @return ...
*/
int getType() {
return this.type;
}
/**
* Return the Type as String
*
* @return ...
*/
String getTypeString() {
return getTypeString(this.type);
}
/**
* Returns whether we have a measure
*
* @return ....
*/
boolean isMeasured() {
return haveMeasure;
}
/**
* Queries the number of geometric dimensions of this geometry. This does not include measures, as opposed to the
* server.
*
* @return The dimensionality (eg, 2D or 3D) of this geometry.
*/
int getDimension() {
return this.dimension;
}
/**
* The OGIS geometry type number of this geometry.
*
* @return ...
*/
int getSrid() {
return this.srid;
}
/**
* Recursively sets the srid on this geometry and all contained subgeometries
*
* @param srid
* ...
*/
void setSrid(int srid) {
this.srid = srid;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
if (srid != UNKNOWN_SRID) {
sb.append("SRID=");
sb.append(srid);
sb.append(';');
}
outerWKT(sb, true);
return sb.toString();
}
/**
* Render the WKT version of this Geometry (without SRID) into the given StringBuffer.
*
* @param sb
* ...
* @param putM
* ...
*/
void outerWKT(StringBuffer sb, boolean putM) {
sb.append(getTypeString());
if (putM && haveMeasure && dimension == 2) {
sb.append('M');
}
mediumWKT(sb);
}
final void outerWKT(StringBuffer sb) {
outerWKT(sb, true);
}
/**
* Render the WKT without the type name, but including the brackets into the StringBuffer
*
* @param sb
* ...
*/
protected void mediumWKT(StringBuffer sb) {
sb.append('(');
innerWKT(sb);
sb.append(')');
}
/**
* Render the "inner" part of the WKT (inside the brackets) into the StringBuffer.
*
* @param SB
* ...
*/
protected abstract void innerWKT(StringBuffer SB);
/**
* backwards compatibility method
*
* @return ...
*/
String getValue() {
StringBuffer sb = new StringBuffer();
mediumWKT(sb);
return sb.toString();
}
/**
* Do some internal consistency checks on the geometry. Currently, all Geometries must have a valid dimension (2 or
* 3) and a valid type. 2-dimensional Points must have Z=0.0, as well as non-measured Points must have m=0.0.
* Composed geometries must have all equal SRID, dimensionality and measures, as well as that they do not contain
* NULL or inconsistent subgeometries. BinaryParser and WKTParser should only generate consistent geometries.
* BinaryWriter may produce invalid results on inconsistent geometries.
*
* @return true if all checks are passed.
*/
boolean checkConsistency() {
return (dimension >= 2 && dimension <= 3) && (type >= 0 && type <= 7);
}
/**
* Splits the SRID=4711; part of a EWKT rep if present and sets the srid.
*
* @param value
* ...
* @return value without the SRID=4711; part
*/
protected String initSRID(String value) {
String v = value.trim();
if (v.startsWith("SRID=")) {
int index = v.indexOf(';', 5); // sridprefix length is 5
if (index == -1) {
throw new IllegalArgumentException(
"Error parsing Geometry - SRID not delimited with ';' ");
}
this.srid = Integer.parseInt(v.substring(5, index));
return v.substring(index + 1).trim();
}
return v;
}
}

View File

@@ -0,0 +1,397 @@
/*
* Copyright 2012 Hannes Janetzek
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.postgis;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.oscim.core.BoundingBox;
import org.oscim.core.GeoPoint;
import org.oscim.core.Tag;
import org.oscim.core.WebMercator;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.view.mapgenerator.JobTile;
import org.postgresql.PGConnection;
import android.util.Log;
/**
*
*
*/
public class MapDatabase implements IMapDatabase {
private final static String TAG = "MapDatabase";
private static final String QUERY = "SELECT tags, geom FROM __get_tile(?,?,?)";
private final float mScale = 1;
private int mCoordPos = 0;
private int mIndexPos = 0;
private float[] mCoords;
private short[] mIndex;
private Tag[] mTags;
private final MapInfo mMapInfo =
new MapInfo(new BoundingBox(-180, -85, 180, 85),
new Byte((byte) 14), new GeoPoint(53.11, 8.85),
WebMercator.NAME,
0, 0, 0, "de", "comment", "author");
private boolean mOpenFile = false;
private Connection connection = null;
private static volatile HashMap<Entry<String, String>, Tag> tagHash =
new HashMap<Entry<String, String>, Tag>(100);
private PreparedStatement prepQuery = null;
private boolean connect() {
Connection conn = null;
String dburl = "jdbc:postgresql://city.informatik.uni-bremen.de:5432/gis-2.0";
Properties dbOpts = new Properties();
dbOpts.setProperty("user", "osm");
dbOpts.setProperty("password", "osm");
dbOpts.setProperty("socketTimeout", "50");
dbOpts.setProperty("tcpKeepAlive", "true");
try {
DriverManager.setLoginTimeout(20);
System.out.println("Creating JDBC connection...");
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(dburl, dbOpts);
connection = conn;
prepQuery = conn.prepareStatement(QUERY);
PGConnection pgconn = (PGConnection) conn;
pgconn.addDataType("hstore", PGHStore.class);
conn.createStatement().execute("set statement_timeout to 60000");
} catch (Exception e) {
System.err.println("Aborted due to error:");
e.printStackTrace();
return false;
}
return true;
}
@Override
public QueryResult executeQuery(JobTile tile, IMapDatabaseCallback mapDatabaseCallback) {
if (connection == null) {
if (!connect())
return QueryResult.FAILED;
}
ResultSet r;
try {
prepQuery.setLong(1, tile.tileX * 256);
prepQuery.setLong(2, tile.tileY * 256);
prepQuery.setInt(3, tile.zoomLevel);
Log.d(TAG, "" + prepQuery.toString());
prepQuery.execute();
r = prepQuery.getResultSet();
} catch (SQLException e) {
e.printStackTrace();
connection = null;
return QueryResult.FAILED;
}
byte[] b = null;
PGHStore h = null;
// int cnt = 0;
try {
while (r != null && r.next()) {
mIndexPos = 0;
mCoordPos = 0;
// cnt++;
try {
Object obj = r.getObject(1);
h = null;
if (obj instanceof PGHStore)
h = (PGHStore) obj;
else {
Log.d(TAG, "no tags: skip way");
continue;
}
b = r.getBytes(2);
} catch (SQLException e) {
e.printStackTrace();
continue;
}
if (b == null) {
// Log.d(TAG, "no geometry: skip way");
continue;
}
mTags = new Tag[h.size()];
int i = 0;
for (Entry<String, String> t : h.entrySet()) {
if (t.getKey() == null) {
Log.d(TAG, "no KEY !!! ");
break;
}
Tag tag = tagHash.get(t);
if (tag == null) {
tag = new Tag(t.getKey(), t.getValue());
tagHash.put(t, tag);
}
mTags[i++] = tag;
}
if (i < mTags.length)
continue;
boolean polygon = parse(b);
if (mIndexPos == 0) {
Log.d(TAG, "no index: skip way");
continue;
} else if (mIndexPos == 1) {
mapDatabaseCallback.renderPointOfInterest((byte) 0, mCoords[1],
mCoords[0], mTags);
} else {
short[] idx = new short[mIndexPos];
System.arraycopy(mIndex, 0, idx, 0, mIndexPos);
mapDatabaseCallback.renderWay((byte) 0, mTags, mCoords, idx, polygon);
}
}
} catch (SQLException e) {
e.printStackTrace();
connection = null;
return QueryResult.FAILED;
}
// Log.d(TAG, "rows: " + cnt);
return QueryResult.SUCCESS;
}
@Override
public String getMapProjection() {
return WebMercator.NAME;
}
@Override
public MapInfo getMapInfo() {
return mMapInfo;
}
@Override
public boolean isOpen() {
return mOpenFile;
}
@Override
public OpenResult open(Map<String, String> options) {
mOpenFile = true;
if (mCoords == null) {
mCoords = new float[100000];
mIndex = new short[100000];
}
return OpenResult.SUCCESS;
}
@Override
public void close() {
if (connection != null) {
try {
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
connection = null;
}
}
mCoords = null;
mIndex = null;
mOpenFile = false;
}
// taken from postgis-java
private static ValueGetter valueGetterForEndian(byte[] bytes) {
if (bytes[0] == ValueGetter.XDR.NUMBER) { // XDR
return new ValueGetter.XDR(bytes);
} else if (bytes[0] == ValueGetter.NDR.NUMBER) {
return new ValueGetter.NDR(bytes);
} else {
throw new IllegalArgumentException("Unknown Endian type:" + bytes[0]);
}
}
/**
* Parse a binary encoded geometry. Is synchronized to protect offset counter. (Unfortunately, Java does not have
* neither call by reference nor multiple return values.)
*
* @param value
* ...
* @return ...
*/
private boolean parse(byte[] value) {
return parseGeometry(valueGetterForEndian(value));
}
private boolean parseGeometry(ValueGetter data) {
byte endian = data.getByte(); // skip and test endian flag
if (endian != data.endian) {
throw new IllegalArgumentException("Endian inconsistency!");
}
int typeword = data.getInt();
int realtype = typeword & 0x1FFFFFFF; // cut off high flag bits
boolean haveZ = (typeword & 0x80000000) != 0;
boolean haveM = (typeword & 0x40000000) != 0;
boolean haveS = (typeword & 0x20000000) != 0;
// int srid = Geometry.UNKNOWN_SRID;
boolean polygon = false;
if (haveS) {
// srid = Geometry.parseSRID(data.getInt());
data.getInt();
}
switch (realtype) {
case Geometry.POINT:
parsePoint(data, haveZ, haveM);
break;
case Geometry.LINESTRING:
parseLineString(data, haveZ, haveM);
break;
case Geometry.POLYGON:
parsePolygon(data, haveZ, haveM);
polygon = true;
break;
case Geometry.MULTIPOINT:
parseMultiPoint(data);
break;
case Geometry.MULTILINESTRING:
parseMultiLineString(data);
break;
case Geometry.MULTIPOLYGON:
parseMultiPolygon(data);
polygon = true;
break;
case Geometry.GEOMETRYCOLLECTION:
parseCollection(data);
break;
default:
throw new IllegalArgumentException("Unknown Geometry Type: " + realtype);
}
// if (srid != Geometry.UNKNOWN_SRID) {
// result.setSrid(srid);
// }
return polygon;
}
private void parsePoint(ValueGetter data, boolean haveZ, boolean haveM) {
// double X = data.getDouble();
// double Y = data.getDouble();
mCoords[0] = (float) (data.getDouble() * mScale);
mCoords[1] = (float) (data.getDouble() * mScale);
mIndex[0] = 2;
mIndexPos = 1;
if (haveZ)
data.getDouble();
if (haveM)
data.getDouble();
}
/**
* Parse an Array of "full" Geometries
*
* @param data
* ...
* @param count
* ...
*/
private void parseGeometryArray(ValueGetter data, int count) {
for (int i = 0; i < count; i++) {
parseGeometry(data);
mIndex[mIndexPos++] = 0;
}
}
//
// private void parsePointArray(ValueGetter data, boolean haveZ, boolean haveM) {
// int count = data.getInt();
// for (int i = 0; i < count; i++) {
// parsePoint(data, haveZ, haveM);
// }
// }
private void parseMultiPoint(ValueGetter data) {
parseGeometryArray(data, data.getInt());
}
private void parseLineString(ValueGetter data, boolean haveZ, boolean haveM) {
int count = data.getInt();
for (int i = 0; i < count; i++) {
mCoords[mCoordPos++] = (float) (data.getDouble()) * mScale;
mCoords[mCoordPos++] = (float) (data.getDouble()) * mScale;
if (haveZ)
data.getDouble();
if (haveM)
data.getDouble();
}
mIndex[mIndexPos++] = (short) (count * 2);
}
private void parsePolygon(ValueGetter data, boolean haveZ, boolean haveM) {
int count = data.getInt();
for (int i = 0; i < count; i++) {
parseLineString(data, haveZ, haveM);
}
}
private void parseMultiLineString(ValueGetter data) {
int count = data.getInt();
parseGeometryArray(data, count);
}
private void parseMultiPolygon(ValueGetter data) {
int count = data.getInt();
parseGeometryArray(data, count);
}
private void parseCollection(ValueGetter data) {
int count = data.getInt();
parseGeometryArray(data, count);
}
@Override
public void cancel() {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,416 @@
/*
* This file has been copied from the following location:
* http://archives.postgresql.org/pgsql-jdbc/2009-12/msg00037.php
*
* PostgreSQL code is typically under a BSD licence.
* http://jdbc.postgresql.org/license.html
*/
/*-------------------------------------------------------------------------
*
* A preliminary version of a custom type wrapper for hstore data.
* Once it gets some testing and cleanups it will go into the official
* PG JDBC driver, but stick it here for now because we need it sooner.
*
* Copyright (c) 2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL$
*
*-------------------------------------------------------------------------
*/
package org.oscim.database.postgis;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.postgresql.util.PGobject;
/**
* This implements a class that handles the PostgreSQL contrib/hstore type
*/
public class PGHStore extends PGobject implements Map<String, String>
{
private final static long serialVersionUID = 1;
private Map<String, String> _map;
/**
* required by the driver
*/
public PGHStore()
{
setType("hstore");
_map = new HashMap<String, String>();
}
/**
* Initialize a hstore with a given string representation
*
* @param value
* String representated hstore
* @throws SQLException
* Is thrown if the string representation has an unknown format
* @see #setValue(String)
*/
public PGHStore(String value)
throws SQLException
{
this();
setValue(value);
}
/**
* @param map
* ...
*/
public PGHStore(Map<String, String> map)
{
this();
setValue(map);
}
/**
* @param map
* ...
*/
public void setValue(Map<String, String> map)
{
_map = map;
}
/**
*/
@Override
public void setValue(String value)
throws SQLException
{
Parser p = new Parser();
_map = p.parse(value);
}
/**
* Returns the stored information as a string
*
* @return String represented hstore
*/
@Override
public String getValue()
{
StringBuffer buf = new StringBuffer();
Iterator<String> i = _map.keySet().iterator();
boolean first = true;
while (i.hasNext()) {
Object key = i.next();
Object val = _map.get(key);
if (first) {
first = false;
} else {
buf.append(',');
}
writeValue(buf, key);
buf.append("=>");
writeValue(buf, val);
}
return buf.toString();
}
private static void writeValue(StringBuffer buf, Object o) {
if (o == null) {
buf.append("NULL");
return;
}
String s = o.toString();
buf.append('"');
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '"' || c == '\\') {
buf.append('\\');
}
buf.append(c);
}
buf.append('"');
}
/**
* Returns whether an object is equal to this one or not
*
* @param obj
* Object to compare with
* @return true if the two hstores are identical
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
return false;
if (obj == this)
return true;
if (!(obj instanceof PGHStore))
return false;
return _map.equals(((PGHStore) obj)._map);
}
private static class Parser {
private String value;
private int ptr;
private StringBuffer cur;
private boolean escaped;
private List<String> keys;
private List<String> values;
private final static int GV_WAITVAL = 0;
private final static int GV_INVAL = 1;
private final static int GV_INESCVAL = 2;
private final static int GV_WAITESCIN = 3;
private final static int GV_WAITESCESCIN = 4;
private final static int WKEY = 0;
private final static int WVAL = 1;
private final static int WEQ = 2;
private final static int WGT = 3;
private final static int WDEL = 4;
public Parser() {
}
Map<String, String> parse(String val) throws SQLException {
this.value = val;
ptr = 0;
keys = new ArrayList<String>();
values = new ArrayList<String>();
parseHStore();
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
private boolean getValue(boolean ignoreEqual) throws SQLException {
int state = GV_WAITVAL;
cur = new StringBuffer();
escaped = false;
while (true) {
boolean atEnd = (value.length() == ptr);
char c = '\0';
if (!atEnd) {
c = value.charAt(ptr);
}
if (state == GV_WAITVAL) {
if (c == '"') {
escaped = true;
state = GV_INESCVAL;
} else if (c == '\0') {
return false;
} else if (c == '=' && !ignoreEqual) {
throw new SQLException("KJJ");
} else if (c == '\\') {
state = GV_WAITESCIN;
} else if (!Character.isWhitespace(c)) {
cur.append(c);
state = GV_INVAL;
}
} else if (state == GV_INVAL) {
if (c == '\\') {
state = GV_WAITESCIN;
} else if (c == '=' && !ignoreEqual) {
ptr--;
return true;
} else if (c == ',' && ignoreEqual) {
ptr--;
return true;
} else if (Character.isWhitespace(c)) {
return true;
} else if (c == '\0') {
ptr--;
return true;
} else {
cur.append(c);
}
} else if (state == GV_INESCVAL) {
if (c == '\\') {
state = GV_WAITESCESCIN;
} else if (c == '"') {
return true;
} else if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
} else {
cur.append(c);
}
} else if (state == GV_WAITESCIN) {
if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
}
cur.append(c);
state = GV_INVAL;
} else if (state == GV_WAITESCESCIN) {
if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
}
cur.append(c);
state = GV_INESCVAL;
} else {
throw new SQLException("KJJ");
}
ptr++;
}
}
private void parseHStore() throws SQLException {
int state = WKEY;
escaped = false;
while (true) {
char c = '\0';
if (ptr < value.length()) {
c = value.charAt(ptr);
}
if (state == WKEY) {
if (!getValue(false))
return;
keys.add(cur.toString());
cur = null;
state = WEQ;
} else if (state == WEQ) {
if (c == '=') {
state = WGT;
} else if (state == '\0') {
throw new SQLException("KJJ, unexpected end of string");
} else if (!Character.isWhitespace(c)) {
throw new SQLException("KJJ, syntax err");
}
} else if (state == WGT) {
if (c == '>') {
state = WVAL;
} else if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
} else {
throw new SQLException("KJJ, syntax err [" + c + "] at " + ptr);
}
} else if (state == WVAL) {
if (!getValue(true)) {
throw new SQLException("KJJ, unexpected end of string");
}
String val = cur.toString();
cur = null;
if (!escaped && "null".equalsIgnoreCase(val)) {
val = null;
}
values.add(val);
state = WDEL;
} else if (state == WDEL) {
if (c == ',')
{
state = WKEY;
} else if (c == '\0') {
return;
} else if (!Character.isWhitespace(c)) {
throw new SQLException("KJJ, syntax err");
}
} else {
throw new SQLException("KJJ unknown state");
}
ptr++;
}
}
}
// Farm out all the work to the real underlying map.
@Override
public void clear() {
_map.clear();
}
@Override
public boolean containsKey(Object key) {
return _map.containsKey(key);
}
@Override
public boolean containsValue(Object val) {
return _map.containsValue(val);
}
@Override
public Set<Map.Entry<String, String>> entrySet() {
return _map.entrySet();
}
@Override
public String get(Object key) {
return _map.get(key);
}
@Override
public int hashCode() {
return _map.hashCode();
}
@Override
public boolean isEmpty() {
return _map.isEmpty();
}
@Override
public Set<String> keySet() {
return _map.keySet();
}
@Override
public String put(String key, String val) {
return _map.put(key, val);
}
@Override
public void putAll(Map<? extends String, ? extends String> m) {
_map.putAll(m);
}
@Override
public String remove(Object key) {
return _map.remove(key);
}
@Override
public int size() {
return _map.size();
}
@Override
public Collection<String> values() {
return _map.values();
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.postgis;
import org.oscim.database.IMapTileData;
public class TileData implements IMapTileData {
}

View File

@@ -0,0 +1,132 @@
/*
* ValueGetter.java
*
* PostGIS extension for PostgreSQL JDBC driver - Binary Parser
*
* (C) 2005 Markus Schaber, markus.schaber@logix-tt.com
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General License as published by the Free
* Software Foundation, either version 2.1 of the License.
*
* This library 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 License for more
* details.
*
* You should have received a copy of the GNU Lesser General License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
* http://www.gnu.org.
*
* $Id: ValueGetter.java 9324 2012-02-27 22:08:12Z pramsey $
*/
package org.oscim.database.postgis;
abstract class ValueGetter {
byte[] data;
int position;
final byte endian;
ValueGetter(byte[] data, byte endian) {
this.data = data;
this.endian = endian;
}
/**
* Get a byte, should be equal for all endians
*
* @return ...
*/
byte getByte() {
return data[position++];
}
int getInt() {
int res = getInt(position);
position += 4;
return res;
}
long getLong() {
long res = getLong(position);
position += 8;
return res;
}
/**
* Get a 32-Bit integer
*
* @param index
* ...
* @return ...
*/
protected abstract int getInt(int index);
/**
* Get a long value. This is not needed directly, but as a nice side-effect from GetDouble.
*
* @param index
* ...
* @return ...
*/
protected abstract long getLong(int index);
/**
* Get a double.
*
* @return ...
*/
double getDouble() {
long bitrep = getLong();
return Double.longBitsToDouble(bitrep);
}
static class XDR extends ValueGetter {
static final byte NUMBER = 0;
XDR(byte[] data) {
super(data, NUMBER);
}
@Override
protected int getInt(int index) {
return ((data[index] & 0xFF) << 24) + ((data[index + 1] & 0xFF) << 16)
+ ((data[index + 2] & 0xFF) << 8) + (data[index + 3] & 0xFF);
}
@Override
protected long getLong(int index) {
return ((long) (data[index] & 0xFF) << 56) | ((long) (data[index + 1] & 0xFF) << 48)
| ((long) (data[index + 2] & 0xFF) << 40) | ((long) (data[index + 3] & 0xFF) << 32)
| ((long) (data[index + 4] & 0xFF) << 24) | ((long) (data[index + 5] & 0xFF) << 16)
| ((long) (data[index + 6] & 0xFF) << 8) | ((long) (data[index + 7] & 0xFF) << 0);
}
}
static class NDR extends ValueGetter {
static final byte NUMBER = 1;
NDR(byte[] data) {
super(data, NUMBER);
}
@Override
protected int getInt(int index) {
return ((data[index + 3] & 0xFF) << 24) + ((data[index + 2] & 0xFF) << 16)
+ ((data[index + 1] & 0xFF) << 8) + (data[index] & 0xFF);
}
@Override
protected long getLong(int index) {
return ((long) (data[index + 7] & 0xFF) << 56) | ((long) (data[index + 6] & 0xFF) << 48)
| ((long) (data[index + 5] & 0xFF) << 40) | ((long) (data[index + 4] & 0xFF) << 32)
| ((long) (data[index + 3] & 0xFF) << 24) | ((long) (data[index + 2] & 0xFF) << 16)
| ((long) (data[index + 1] & 0xFF) << 8) | ((long) (data[index] & 0xFF) << 0);
}
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright 2012 Hannes Janetzek
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.test;
import java.util.Map;
import org.oscim.core.BoundingBox;
import org.oscim.core.MercatorProjection;
import org.oscim.core.Tag;
import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.view.mapgenerator.JobTile;
/**
*
*
*/
public class MapDatabase implements IMapDatabase {
private final static String PROJECTION = "Mercator";
private float[] mCoords = new float[20];
private short[] mIndex = new short[2];
// private Tag[] mTags = { new Tag("boundary", "administrative"), new Tag("admin_level", "2") };
private Tag[] mTags = { new Tag("natural", "water") };
private Tag[] mNameTags;
private final MapInfo mMapInfo =
new MapInfo(new BoundingBox(-180, -90, 180, 90),
new Byte((byte) 0), null, PROJECTION, 0, 0, 0, "de", "yo!", "by me");
private boolean mOpenFile = false;
// private static double radius = 6378137;
// private static double D2R = Math.PI / 180;
// private static double HALF_PI = Math.PI / 2;
@Override
public QueryResult executeQuery(JobTile tile, IMapDatabaseCallback mapDatabaseCallback) {
long cx = tile.pixelX + (Tile.TILE_SIZE >> 1);
long cy = tile.pixelY + (Tile.TILE_SIZE >> 1);
// float lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 100, tile.zoomLevel) * 1000000;
// float lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 100, tile.zoomLevel) * 1000000;
// float lat1 = (float) MercatorProjection.pixelYToLatitude(cy - 100, tile.zoomLevel) * 1000000;
// float lat2 = (float) MercatorProjection.pixelYToLatitude(cy + 100, tile.zoomLevel) * 1000000;
float lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 100,
tile.zoomLevel);
float lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 100,
tile.zoomLevel);
float lat1 = (float) MercatorProjection
.pixelYToLatitude(cy - 100, tile.zoomLevel);
float lat2 = (float) MercatorProjection
.pixelYToLatitude(cy + 100, tile.zoomLevel);
// double lonRadians = (D2R * lon1);
// double latRadians = (D2R * lat1);
// spherical mercator projection
// lon1 = (float) (radius * lonRadians);
// lat1 = (float) (radius * Math.log(Math.tan(Math.PI * 0.25 + latRadians * 0.5)));
//
// lonRadians = (D2R * lon2);
// latRadians = (D2R * lat2);
//
// lon2 = (float) (radius * lonRadians);
// lat2 = (float) (radius * Math.log(Math.tan(Math.PI * 0.25 + latRadians * 0.5)));
//
// mCoords[0] = lon1;
// mCoords[1] = lat1;
//
// mCoords[2] = lon2;
// mCoords[3] = lat1;
//
// mCoords[4] = lon2;
// mCoords[5] = lat2;
//
// mCoords[6] = lon1;
// mCoords[7] = lat2;
//
// mCoords[8] = lon1;
// mCoords[9] = lat1;
//
// mIndex[0] = 10;
lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 139, tile.zoomLevel) * 1000000;
lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 139, tile.zoomLevel) * 1000000;
lat1 = (float) MercatorProjection.pixelYToLatitude(cy - 139, tile.zoomLevel) * 1000000;
lat2 = (float) MercatorProjection.pixelYToLatitude(cy + 139, tile.zoomLevel) * 1000000;
mCoords[0] = lon1;
mCoords[1] = lat1;
mCoords[2] = lon2;
mCoords[3] = lat1;
mCoords[4] = lon2;
mCoords[5] = lat2;
mCoords[6] = lon1;
mCoords[7] = lat2;
mCoords[8] = lon1;
mCoords[9] = lat1;
mIndex[0] = 10;
lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 119, tile.zoomLevel) * 1000000;
lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 119, tile.zoomLevel) * 1000000;
lat1 = (float) MercatorProjection.pixelYToLatitude(cy - 119, tile.zoomLevel) * 1000000;
lat2 = (float) MercatorProjection.pixelYToLatitude(cy + 119, tile.zoomLevel) * 1000000;
mCoords[10] = lon1;
mCoords[11] = lat1;
mCoords[12] = lon2;
mCoords[13] = lat1;
mCoords[14] = lon2;
mCoords[15] = lat2;
mCoords[16] = lon1;
mCoords[17] = lat2;
mCoords[18] = lon1;
mCoords[19] = lat1;
mIndex[1] = 10;
mapDatabaseCallback.renderWay((byte) 0, mTags, mCoords, mIndex, true);
lon1 = (float) MercatorProjection.pixelXToLongitude(cx, tile.zoomLevel) * 1000000;
lat1 = (float) MercatorProjection.pixelXToLongitude(cx, tile.zoomLevel) * 1000000;
mNameTags = new Tag[2];
mNameTags[0] = new Tag("place", "city");
mNameTags[1] = new Tag("name", "check one check two, YO!");
mapDatabaseCallback.renderPointOfInterest((byte) 0, (int) lat1, (int) lon1,
mNameTags);
return QueryResult.SUCCESS;
}
@Override
public String getMapProjection() {
return PROJECTION;
}
@Override
public MapInfo getMapInfo() {
return mMapInfo;
}
@Override
public boolean isOpen() {
return mOpenFile;
}
@Override
public OpenResult open(Map<String, String> options) {
mOpenFile = true;
return OpenResult.SUCCESS;
}
@Override
public void close() {
mOpenFile = false;
}
@Override
public void cancel() {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
final class AnyMatcher implements AttributeMatcher {
private static final AnyMatcher INSTANCE = new AnyMatcher();
static AnyMatcher getInstance() {
return INSTANCE;
}
/**
* Private constructor to prevent instantiation from other classes.
*/
private AnyMatcher() {
// do nothing
}
@Override
public boolean isCoveredBy(AttributeMatcher attributeMatcher) {
return attributeMatcher == this;
}
@Override
public boolean matches(Tag[] tags) {
return true;
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
interface AttributeMatcher {
boolean isCoveredBy(AttributeMatcher attributeMatcher);
boolean matches(Tag[] tags);
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
final class Closed {
public static final int ANY = 0;
public static final int NO = 1;
public static final int YES = 2;
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
final class Element {
public static final int ANY = 0;
public static final int NODE = 1;
public static final int WAY = 2;
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
/**
* An ExternalRenderTheme allows for customizing the rendering style of the map via an XML file.
*/
public class ExternalRenderTheme implements Theme {
private static final long serialVersionUID = 1L;
private final long mFileModificationDate;
private transient int mHashCodeValue;
private final String mRenderThemePath;
/**
* @param renderThemePath
* the path to the XML render theme file.
* @throws FileNotFoundException
* if the file does not exist or cannot be read.
*/
public ExternalRenderTheme(String renderThemePath) throws FileNotFoundException {
File renderThemeFile = new File(renderThemePath);
if (!renderThemeFile.exists()) {
throw new FileNotFoundException("file does not exist: " + renderThemePath);
} else if (!renderThemeFile.isFile()) {
throw new FileNotFoundException("not a file: " + renderThemePath);
} else if (!renderThemeFile.canRead()) {
throw new FileNotFoundException("cannot read file: " + renderThemePath);
}
mFileModificationDate = renderThemeFile.lastModified();
if (mFileModificationDate == 0L) {
throw new FileNotFoundException("cannot read last modification time");
}
mRenderThemePath = renderThemePath;
calculateTransientValues();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof ExternalRenderTheme)) {
return false;
}
ExternalRenderTheme other = (ExternalRenderTheme) obj;
if (mFileModificationDate != other.mFileModificationDate) {
return false;
} else if (mRenderThemePath == null && other.mRenderThemePath != null) {
return false;
} else if (mRenderThemePath != null && !mRenderThemePath.equals(other.mRenderThemePath)) {
return false;
}
return true;
}
@Override
public InputStream getRenderThemeAsStream() throws FileNotFoundException {
return new FileInputStream(mRenderThemePath);
}
@Override
public int hashCode() {
return mHashCodeValue;
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 1;
result = 31 * result + (int) (mFileModificationDate ^ (mFileModificationDate >>> 32));
result = 31 * result + ((mRenderThemePath == null) ? 0 : mRenderThemePath.hashCode());
return result;
}
/**
* Calculates the values of some transient variables.
*/
private void calculateTransientValues() {
mHashCodeValue = calculateHashCode();
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
objectInputStream.defaultReadObject();
calculateTransientValues();
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.theme.renderinstruction.Area;
import org.oscim.theme.renderinstruction.Caption;
import org.oscim.theme.renderinstruction.Line;
import org.oscim.theme.renderinstruction.PathText;
import android.graphics.Bitmap;
import android.graphics.Paint;
/**
* Callback methods for rendering areas, ways and points of interest (POIs).
*/
public interface IRenderCallback {
/**
* Renders an area with the given parameters.
*
* @param area
* ...
* @param level
* ...
*/
void renderArea(Area area, int level);
/**
* Renders an area caption with the given text.
*
* @param caption
* the text to be rendered.
*/
void renderAreaCaption(Caption caption);
/**
* Renders an area symbol with the given bitmap.
*
* @param symbol
* the symbol to be rendered.
*/
void renderAreaSymbol(Bitmap symbol);
/**
* Renders a point of interest caption with the given text.
*
* @param caption
* the text to be rendered.
*/
void renderPointOfInterestCaption(Caption caption);
/**
* Renders a point of interest circle with the given parameters.
*
* @param radius
* the radius of the circle.
* @param fill
* the paint to be used for rendering the circle.
* @param level
* the drawing level on which the circle should be rendered.
*/
void renderPointOfInterestCircle(float radius, Paint fill, int level);
/**
* Renders a point of interest symbol with the given bitmap.
*
* @param symbol
* the symbol to be rendered.
*/
void renderPointOfInterestSymbol(Bitmap symbol);
/**
* Renders a way with the given parameters.
*
* @param line
* ...
* @param level
* ...
*/
void renderWay(Line line, int level);
/**
* Renders a way with the given symbol along the way path.
*
* @param symbol
* the symbol to be rendered.
* @param alignCenter
* true if the symbol should be centered, false otherwise.
* @param repeat
* true if the symbol should be repeated, false otherwise.
*/
void renderWaySymbol(Bitmap symbol, boolean alignCenter, boolean repeat);
/**
* Renders a way with the given text along the way path.
*
* @param pathText
* ...
*/
void renderWayText(PathText pathText);
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.io.InputStream;
/**
* Enumeration of all internal rendering themes.
*/
public enum InternalRenderTheme implements Theme {
/**
* A rendering theme similar to the OpenStreetMap Osmarender style.
*
* @see <a href="http://wiki.openstreetmap.org/wiki/Osmarender">Osmarender</a>
*/
OSMARENDER("/org/oscim/theme/osmarender/osmarender.xml"),
TRONRENDER("/org/oscim/theme/osmarender/tronrender.xml");
private final String mPath;
private InternalRenderTheme(String path) {
mPath = path;
}
@Override
public InputStream getRenderThemeAsStream() {
return InternalRenderTheme.class.getResourceAsStream(mPath);
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
class MatchingCacheKey {
int mHashCodeValue;
Tag[] mTags;
byte mZoomLevel;
MatchingCacheKey() {
}
MatchingCacheKey(Tag[] tags, byte zoomLevel) {
mTags = tags;
mZoomLevel = zoomLevel;
mHashCodeValue = calculateHashCode();
}
MatchingCacheKey(MatchingCacheKey key) {
mTags = key.mTags;
mZoomLevel = key.mZoomLevel;
mHashCodeValue = key.mHashCodeValue;
}
void set(Tag[] tags, byte zoomLevel) {
mTags = tags;
mZoomLevel = zoomLevel;
int result = 7;
for (int i = 0, n = mTags.length; i < n; i++) {
if (mTags[i] == null)
break;
result = 31 * result + mTags[i].hashCode();
}
result = 31 * result + mZoomLevel;
mHashCodeValue = result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
// else if (!(obj instanceof MatchingCacheKey)) {
// return false;
// }
MatchingCacheKey other = (MatchingCacheKey) obj;
if (mZoomLevel != other.mZoomLevel)
return false;
if (mTags == null) {
return (other.mTags == null);
} else if (other.mTags == null)
return false;
int length = mTags.length;
if (length != other.mTags.length) {
return false;
}
for (int i = 0; i < length; i++)
if (mTags[i] != other.mTags[i])
return false;
return true;
}
@Override
public int hashCode() {
return mHashCodeValue;
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
for (int i = 0, n = mTags.length; i < n; i++) {
if (mTags[i] == null) // FIXME
break;
result = 31 * result + mTags[i].hashCode();
}
result = 31 * result + mZoomLevel;
return result;
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.util.List;
import org.oscim.core.Tag;
class MultiKeyMatcher implements AttributeMatcher {
private final String[] mKeys;
MultiKeyMatcher(List<String> keys) {
mKeys = new String[keys.size()];
for (int i = 0, n = mKeys.length; i < n; ++i) {
mKeys[i] = keys.get(i).intern();
}
}
@Override
public boolean isCoveredBy(AttributeMatcher attributeMatcher) {
if (attributeMatcher == this) {
return true;
}
Tag[] tags = new Tag[mKeys.length];
int i = 0;
for (String key : mKeys) {
tags[i++] = new Tag(key, null);
}
return attributeMatcher.matches(tags);
}
@Override
public boolean matches(Tag[] tags) {
for (Tag tag : tags)
for (String key : mKeys)
if (key == tag.key)
return true;
return false;
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.util.List;
import org.oscim.core.Tag;
class MultiValueMatcher implements AttributeMatcher {
private final String[] mValues;
MultiValueMatcher(List<String> values) {
mValues = new String[values.size()];
for (int i = 0, n = mValues.length; i < n; ++i) {
mValues[i] = values.get(i).intern();
}
}
@Override
public boolean isCoveredBy(AttributeMatcher attributeMatcher) {
if (attributeMatcher == this) {
return true;
}
Tag[] tags = new Tag[mValues.length];
int i = 0;
for (String val : mValues) {
tags[i++] = new Tag(null, val);
}
return attributeMatcher.matches(tags);
}
@Override
public boolean matches(Tag[] tags) {
for (Tag tag : tags)
for (String val : mValues)
if (val == tag.value)
return true;
return false;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.util.List;
import org.oscim.core.Tag;
class NegativeMatcher implements AttributeMatcher {
private final String[] mKeyList;
private final String[] mValueList;
private final boolean mExclusive;
NegativeMatcher(List<String> keyList, List<String> valueList, boolean exclusive) {
mKeyList = new String[keyList.size()];
for (int i = 0; i < mKeyList.length; i++)
mKeyList[i] = keyList.get(i).intern();
mValueList = new String[valueList.size()];
for (int i = 0; i < mValueList.length; i++)
mValueList[i] = valueList.get(i).intern();
mExclusive = exclusive;
}
@Override
public boolean isCoveredBy(AttributeMatcher attributeMatcher) {
return false;
}
@Override
public boolean matches(Tag[] tags) {
if (keyListDoesNotContainKeys(tags)) {
return true;
}
for (Tag tag : tags) {
for (String value : mValueList)
if (value == tag.value)
return !mExclusive;
}
return mExclusive;
}
private boolean keyListDoesNotContainKeys(Tag[] tags) {
for (Tag tag : tags) {
for (String key : mKeyList)
if (key == tag.key)
return false;
}
return true;
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
class NegativeRule extends Rule {
final AttributeMatcher mAttributeMatcher;
NegativeRule(int element, int closed, byte zoomMin, byte zoomMax,
AttributeMatcher attributeMatcher) {
super(element, closed, zoomMin, zoomMax);
mAttributeMatcher = attributeMatcher;
}
@Override
boolean matchesNode(Tag[] tags, byte zoomLevel) {
return mZoomMin <= zoomLevel && mZoomMax >= zoomLevel
&& (mElement != Element.WAY)
&& mAttributeMatcher.matches(tags);
}
@Override
boolean matchesWay(Tag[] tags, byte zoomLevel, int closed) {
return mZoomMin <= zoomLevel && mZoomMax >= zoomLevel
&& (mElement != Element.NODE)
&& (mClosed == closed || mClosed == Closed.ANY)
&& mAttributeMatcher.matches(tags);
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
class PositiveRule extends Rule {
final AttributeMatcher mKeyMatcher;
final AttributeMatcher mValueMatcher;
PositiveRule(int element, int closed, byte zoomMin, byte zoomMax,
AttributeMatcher keyMatcher, AttributeMatcher valueMatcher) {
super(element, closed, zoomMin, zoomMax);
if (keyMatcher instanceof AnyMatcher)
mKeyMatcher = null;
else
mKeyMatcher = keyMatcher;
if (valueMatcher instanceof AnyMatcher)
mValueMatcher = null;
else
mValueMatcher = valueMatcher;
}
@Override
boolean matchesNode(Tag[] tags, byte zoomLevel) {
return (mElement != Element.WAY)
&& mZoomMin <= zoomLevel
&& mZoomMax >= zoomLevel
&& (mKeyMatcher == null || mKeyMatcher.matches(tags))
&& (mValueMatcher == null || mValueMatcher.matches(tags));
}
@Override
boolean matchesWay(Tag[] tags, byte zoomLevel, int closed) {
return (mElement != Element.NODE)
&& mZoomMin <= zoomLevel
&& mZoomMax >= zoomLevel
&& (mClosed == closed || mClosed == Closed.ANY)
&& (mKeyMatcher == null || mKeyMatcher.matches(tags))
&& (mValueMatcher == null || mValueMatcher.matches(tags));
}
}

View File

@@ -0,0 +1,280 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.util.ArrayList;
import java.util.List;
import org.oscim.core.LRUCache;
import org.oscim.core.Tag;
import org.oscim.theme.renderinstruction.RenderInstruction;
import org.xml.sax.Attributes;
import android.graphics.Color;
/**
* A RenderTheme defines how ways and nodes are drawn.
*/
public class RenderTheme {
private static final int MATCHING_CACHE_SIZE = 1024;
private static final int RENDER_THEME_VERSION = 1;
private static void validate(String elementName, Integer version,
float baseStrokeWidth, float baseTextSize) {
if (version == null) {
throw new IllegalArgumentException("missing attribute version for element:"
+ elementName);
} else if (version.intValue() != RENDER_THEME_VERSION) {
throw new IllegalArgumentException("invalid render theme version:" + version);
} else if (baseStrokeWidth < 0) {
throw new IllegalArgumentException("base-stroke-width must not be negative: "
+ baseStrokeWidth);
} else if (baseTextSize < 0) {
throw new IllegalArgumentException("base-text-size must not be negative: "
+ baseTextSize);
}
}
static RenderTheme create(String elementName, Attributes attributes) {
Integer version = null;
int mapBackground = Color.WHITE;
float baseStrokeWidth = 1;
float baseTextSize = 1;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("schemaLocation".equals(name)) {
continue;
} else if ("version".equals(name)) {
version = Integer.valueOf(Integer.parseInt(value));
} else if ("map-background".equals(name)) {
mapBackground = Color.parseColor(value);
} else if ("base-stroke-width".equals(name)) {
baseStrokeWidth = Float.parseFloat(value);
} else if ("base-text-size".equals(name)) {
baseTextSize = Float.parseFloat(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, version, baseStrokeWidth, baseTextSize);
return new RenderTheme(mapBackground, baseStrokeWidth, baseTextSize);
}
private final float mBaseStrokeWidth;
private final float mBaseTextSize;
private int mLevels;
private final int mMapBackground;
private final ArrayList<Rule> mRulesList;
private final LRUCache<MatchingCacheKey, RenderInstruction[]> mMatchingCacheNodes;
private final LRUCache<MatchingCacheKey, RenderInstruction[]> mMatchingCacheWay;
private final LRUCache<MatchingCacheKey, RenderInstruction[]> mMatchingCacheArea;
RenderTheme(int mapBackground, float baseStrokeWidth, float baseTextSize) {
mMapBackground = mapBackground;
mBaseStrokeWidth = baseStrokeWidth;
mBaseTextSize = baseTextSize;
mRulesList = new ArrayList<Rule>();
mMatchingCacheNodes = new LRUCache<MatchingCacheKey, RenderInstruction[]>(
MATCHING_CACHE_SIZE);
mMatchingCacheWay = new LRUCache<MatchingCacheKey, RenderInstruction[]>(
MATCHING_CACHE_SIZE);
mMatchingCacheArea = new LRUCache<MatchingCacheKey, RenderInstruction[]>(
MATCHING_CACHE_SIZE);
}
/**
* Must be called when this RenderTheme gets destroyed to clean up and free resources.
*/
public void destroy() {
mMatchingCacheNodes.clear();
mMatchingCacheArea.clear();
mMatchingCacheWay.clear();
for (int i = 0, n = mRulesList.size(); i < n; ++i) {
mRulesList.get(i).onDestroy();
}
}
/**
* @return the number of distinct drawing levels required by this RenderTheme.
*/
public int getLevels() {
return mLevels;
}
/**
* @return the map background color of this RenderTheme.
* @see Color
*/
public int getMapBackground() {
return mMapBackground;
}
/**
* @param renderCallback
* ...
* @param tags
* ...
* @param zoomLevel
* ...
* @return ...
*/
public synchronized RenderInstruction[] matchNode(IRenderCallback renderCallback,
Tag[] tags, byte zoomLevel) {
RenderInstruction[] renderInstructions = null;
MatchingCacheKey matchingCacheKey;
matchingCacheKey = new MatchingCacheKey(tags, zoomLevel);
boolean found = mMatchingCacheNodes.containsKey(matchingCacheKey);
if (found) {
renderInstructions = mMatchingCacheNodes.get(matchingCacheKey);
} else {
// cache miss
List<RenderInstruction> matchingList = new ArrayList<RenderInstruction>(4);
for (int i = 0, n = mRulesList.size(); i < n; ++i)
mRulesList.get(i)
.matchNode(renderCallback, tags, zoomLevel, matchingList);
int size = matchingList.size();
if (size > 0) {
renderInstructions = new RenderInstruction[size];
matchingList.toArray(renderInstructions);
}
mMatchingCacheNodes.put(matchingCacheKey, renderInstructions);
}
if (renderInstructions != null) {
for (int i = 0, n = renderInstructions.length; i < n; i++)
renderInstructions[i].renderNode(renderCallback, tags);
}
return renderInstructions;
}
// private int missCnt = 0;
// private int hitCnt = 0;
private MatchingCacheKey mCacheKey = new MatchingCacheKey();
/**
* Matches a way with the given parameters against this RenderTheme.
*
* @param renderCallback
* the callback implementation which will be executed on each match.
* @param tags
* the tags of the way.
* @param zoomLevel
* the zoom level at which the way should be matched.
* @param closed
* way is Closed
* @param render
* ...
* @return currently processed render instructions
*/
public synchronized RenderInstruction[] matchWay(IRenderCallback renderCallback,
Tag[] tags, byte zoomLevel, boolean closed, boolean render) {
RenderInstruction[] renderInstructions = null;
LRUCache<MatchingCacheKey, RenderInstruction[]> matchingCache;
MatchingCacheKey matchingCacheKey;
if (closed) {
matchingCache = mMatchingCacheArea;
} else {
matchingCache = mMatchingCacheWay;
}
mCacheKey.set(tags, zoomLevel);
renderInstructions = matchingCache.get(mCacheKey);
if (renderInstructions != null) {
// Log.d("RenderTheme", hitCnt++ + "Cache Hit");
} else if (!matchingCache.containsKey(mCacheKey)) {
matchingCacheKey = new MatchingCacheKey(mCacheKey);
// cache miss
// Log.d("RenderTheme", missCnt++ + " Cache Miss");
int c = (closed ? Closed.YES : Closed.NO);
List<RenderInstruction> matchingList = new ArrayList<RenderInstruction>(4);
for (int i = 0, n = mRulesList.size(); i < n; ++i) {
mRulesList.get(i).matchWay(renderCallback, tags, zoomLevel, c,
matchingList);
}
int size = matchingList.size();
if (size > 0) {
renderInstructions = new RenderInstruction[size];
matchingList.toArray(renderInstructions);
}
matchingCache.put(matchingCacheKey, renderInstructions);
}
if (render && renderInstructions != null) {
for (int i = 0, n = renderInstructions.length; i < n; i++)
renderInstructions[i].renderWay(renderCallback, tags);
}
return renderInstructions;
}
void addRule(Rule rule) {
mRulesList.add(rule);
}
void complete() {
mRulesList.trimToSize();
for (int i = 0, n = mRulesList.size(); i < n; ++i) {
mRulesList.get(i).onComplete();
}
}
/**
* Scales the stroke width of this RenderTheme by the given factor.
*
* @param scaleFactor
* the factor by which the stroke width should be scaled.
*/
public void scaleStrokeWidth(float scaleFactor) {
for (int i = 0, n = mRulesList.size(); i < n; ++i) {
mRulesList.get(i).scaleStrokeWidth(scaleFactor * mBaseStrokeWidth);
}
}
/**
* Scales the text size of this RenderTheme by the given factor.
*
* @param scaleFactor
* the factor by which the text size should be scaled.
*/
public void scaleTextSize(float scaleFactor) {
for (int i = 0, n = mRulesList.size(); i < n; ++i) {
mRulesList.get(i).scaleTextSize(scaleFactor * mBaseTextSize);
}
}
void setLevels(int levels) {
mLevels = levels;
}
}

View File

@@ -0,0 +1,358 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.oscim.theme.renderinstruction.Area;
import org.oscim.theme.renderinstruction.AreaLevel;
import org.oscim.theme.renderinstruction.Caption;
import org.oscim.theme.renderinstruction.Circle;
import org.oscim.theme.renderinstruction.Line;
import org.oscim.theme.renderinstruction.LineSymbol;
import org.oscim.theme.renderinstruction.PathText;
import org.oscim.theme.renderinstruction.RenderInstruction;
import org.oscim.theme.renderinstruction.Symbol;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
/**
* SAX2 handler to parse XML render theme files.
*/
public class RenderThemeHandler extends DefaultHandler {
private static final Logger LOG = Logger
.getLogger(RenderThemeHandler.class.getName());
private static enum Element {
RENDER_THEME, RENDERING_INSTRUCTION, RULE, STYLE;
}
private static final String ELEMENT_NAME_RENDER_THEME = "rendertheme";
private static final String ELEMENT_NAME_RULE = "rule";
private static final String ELEMENT_NAME_STYPE_PATH_TEXT = "style-pathtext";
private static final String ELEMENT_NAME_STYLE_AREA = "style-area";
private static final String ELEMENT_NAME_STYLE_LINE = "style-line";
private static final String ELEMENT_NAME_STYLE_OUTLINE = "style-outline";
private static final String ELEMENT_NAME_USE_STYLE_PATH_TEXT = "use-text";
private static final String ELEMENT_NAME_USE_STYLE_AREA = "use-area";
private static final String ELEMENT_NAME_USE_STYLE_LINE = "use-line";
private static final String ELEMENT_NAME_USE_STYLE_OUTLINE = "use-outline";
private static final String UNEXPECTED_ELEMENT = "unexpected element: ";
/**
* @param inputStream
* an input stream containing valid render theme XML data.
* @return a new RenderTheme which is created by parsing the XML data from the input stream.
* @throws SAXException
* if an error occurs while parsing the render theme XML.
* @throws ParserConfigurationException
* if an error occurs while creating the XML parser.
* @throws IOException
* if an I/O error occurs while reading from the input stream.
*/
public static RenderTheme getRenderTheme(InputStream inputStream)
throws SAXException,
ParserConfigurationException, IOException {
RenderThemeHandler renderThemeHandler = new RenderThemeHandler();
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser()
.getXMLReader();
xmlReader.setContentHandler(renderThemeHandler);
xmlReader.parse(new InputSource(inputStream));
return renderThemeHandler.mRenderTheme;
}
/**
* Logs the given information about an unknown XML attribute.
*
* @param element
* the XML element name.
* @param name
* the XML attribute name.
* @param value
* the XML attribute value.
* @param attributeIndex
* the XML attribute index position.
*/
public static void logUnknownAttribute(String element, String name, String value,
int attributeIndex) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("unknown attribute in element ");
stringBuilder.append(element);
stringBuilder.append(" (");
stringBuilder.append(attributeIndex);
stringBuilder.append("): ");
stringBuilder.append(name);
stringBuilder.append('=');
stringBuilder.append(value);
LOG.info(stringBuilder.toString());
}
private Rule mCurrentRule;
private final Stack<Element> mElementStack = new Stack<Element>();
private int mLevel;
private RenderTheme mRenderTheme;
private final Stack<Rule> mRuleStack = new Stack<Rule>();
@Override
public void endDocument() {
if (mRenderTheme == null) {
throw new IllegalArgumentException("missing element: rules");
}
mRenderTheme.setLevels(mLevel);
mRenderTheme.complete();
tmpStyleHash.clear();
}
@Override
public void endElement(String uri, String localName, String qName) {
mElementStack.pop();
if (ELEMENT_NAME_RULE.equals(localName)) {
mRuleStack.pop();
if (mRuleStack.empty()) {
mRenderTheme.addRule(mCurrentRule);
} else {
mCurrentRule = mRuleStack.peek();
}
}
}
@Override
public void error(SAXParseException exception) {
LOG.log(Level.SEVERE, null, exception);
}
private static HashMap<String, RenderInstruction> tmpStyleHash = new HashMap<String, RenderInstruction>(
10);
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
try {
if (ELEMENT_NAME_RENDER_THEME.equals(localName)) {
checkState(localName, Element.RENDER_THEME);
mRenderTheme = RenderTheme.create(localName, attributes);
}
else if (ELEMENT_NAME_RULE.equals(localName)) {
checkState(localName, Element.RULE);
Rule rule = Rule.create(localName, attributes, mRuleStack);
if (!mRuleStack.empty()) {
mCurrentRule.addSubRule(rule);
}
mCurrentRule = rule;
mRuleStack.push(mCurrentRule);
}
else if (ELEMENT_NAME_STYPE_PATH_TEXT.equals(localName)) {
checkState(localName, Element.STYLE);
PathText pathText = PathText.create(localName, attributes);
tmpStyleHash.put("t" + pathText.style, pathText);
// System.out.println("add style: " + pathText.style);
}
else if (ELEMENT_NAME_STYLE_AREA.equals(localName)) {
checkState(localName, Element.STYLE);
Area area = Area.create(localName, attributes, 0);
tmpStyleHash.put("a" + area.style, area);
// System.out.println("add style: " + area.style);
}
else if (ELEMENT_NAME_STYLE_LINE.equals(localName)) {
checkState(localName, Element.STYLE);
String style = null;
if ((style = attributes.getValue("from")) != null) {
RenderInstruction ri = tmpStyleHash.get("l" + style);
if (ri instanceof Line) {
Line line = Line.create((Line) ri, localName, attributes, 0,
false);
tmpStyleHash.put("l" + line.style, line);
// System.out.println("add style: " + line.style + " from " + style);
}
else {
Log.d("...", "this aint no style! " + style);
}
} else {
Line line = Line.create(null, localName, attributes, 0, false);
tmpStyleHash.put("l" + line.style, line);
// System.out.println("add style: " + line.style);
}
}
else if (ELEMENT_NAME_STYLE_OUTLINE.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
Line line = Line.create(null, localName, attributes, mLevel++, true);
tmpStyleHash.put("o" + line.style, line);
// outlineLayers.add(line);
}
else if ("area".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
Area area = Area.create(localName, attributes, mLevel++);
// mRuleStack.peek().addRenderingInstruction(area);
mCurrentRule.addRenderingInstruction(area);
}
else if ("caption".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
Caption caption = Caption.create(localName, attributes);
mCurrentRule.addRenderingInstruction(caption);
}
else if ("circle".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
Circle circle = Circle.create(localName, attributes, mLevel++);
mCurrentRule.addRenderingInstruction(circle);
}
else if ("line".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
Line line = Line.create(null, localName, attributes, mLevel++, false);
mCurrentRule.addRenderingInstruction(line);
}
else if ("lineSymbol".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
LineSymbol lineSymbol = LineSymbol.create(localName, attributes);
mCurrentRule.addRenderingInstruction(lineSymbol);
}
else if ("pathText".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
PathText pathText = PathText.create(localName, attributes);
mCurrentRule.addRenderingInstruction(pathText);
}
else if ("symbol".equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
Symbol symbol = Symbol.create(localName, attributes);
mCurrentRule.addRenderingInstruction(symbol);
}
else if (ELEMENT_NAME_USE_STYLE_LINE.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
String style = attributes.getValue("name");
if (style != null) {
Line line = (Line) tmpStyleHash.get("l" + style);
if (line != null) {
// System.out.println("found style line : " + line.style);
Line newLine = Line.create(line, localName, attributes,
mLevel++, false);
mCurrentRule.addRenderingInstruction(newLine);
}
else
Log.d("...", "styles not a line! " + style);
}
} else if (ELEMENT_NAME_USE_STYLE_OUTLINE.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
String style = attributes.getValue("name");
if (style != null) {
Line line = (Line) tmpStyleHash.get("o" + style);
if (line != null && line.outline)
mCurrentRule.addRenderingInstruction(line);
else
Log.d("...", "styles not bad, but this aint no outline! " + style);
}
} else if (ELEMENT_NAME_USE_STYLE_AREA.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
String style = attributes.getValue("name");
if (style != null) {
Area area = (Area) tmpStyleHash.get("a" + style);
if (area != null)
mCurrentRule.addRenderingInstruction(new AreaLevel(area,
mLevel++));
else
Log.d("...", "this aint no style inna di area! " + style);
}
} else if (ELEMENT_NAME_USE_STYLE_PATH_TEXT.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION);
String style = attributes.getValue("name");
if (style != null) {
PathText pt = (PathText) tmpStyleHash.get("t" + style);
if (pt != null)
mCurrentRule.addRenderingInstruction(pt);
else
Log.d("...", "this aint no path text style! " + style);
}
} else {
throw new SAXException("unknown element: " + localName);
}
} catch (IllegalArgumentException e) {
throw new SAXException(null, e);
} catch (IOException e) {
throw new SAXException(null, e);
}
}
@Override
public void warning(SAXParseException exception) {
LOG.log(Level.SEVERE, null, exception);
}
private void checkElement(String elementName, Element element) throws SAXException {
Element parentElement;
switch (element) {
case RENDER_THEME:
if (!mElementStack.empty()) {
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
}
return;
case RULE:
parentElement = mElementStack.peek();
if (parentElement != Element.RENDER_THEME
&& parentElement != Element.RULE) {
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
}
return;
case STYLE:
parentElement = mElementStack.peek();
if (parentElement != Element.RENDER_THEME) {
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
}
return;
case RENDERING_INSTRUCTION:
if (mElementStack.peek() != Element.RULE) {
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
}
return;
}
throw new SAXException("unknown enum value: " + element);
}
private void checkState(String elementName, Element element) throws SAXException {
checkElement(elementName, element);
mElementStack.push(element);
}
}

View File

@@ -0,0 +1,278 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Stack;
import java.util.regex.Pattern;
import org.oscim.core.Tag;
import org.oscim.theme.renderinstruction.RenderInstruction;
import org.xml.sax.Attributes;
abstract class Rule {
private static final Map<List<String>, AttributeMatcher> MATCHERS_CACHE_KEY = new HashMap<List<String>, AttributeMatcher>();
private static final Map<List<String>, AttributeMatcher> MATCHERS_CACHE_VALUE = new HashMap<List<String>, AttributeMatcher>();
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\|");
private static final String STRING_NEGATION = "~";
private static final String STRING_EXCLUSIVE = "-";
private static final String STRING_WILDCARD = "*";
private static Rule createRule(Stack<Rule> ruleStack, int element, String keys,
String values, int closed,
byte zoomMin, byte zoomMax) {
List<String> keyList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN
.split(keys)));
List<String> valueList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN
.split(values)));
if (valueList.remove(STRING_NEGATION)) {
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
false);
return new NegativeRule(element, closed, zoomMin, zoomMax,
attributeMatcher);
}
if (valueList.remove(STRING_EXCLUSIVE)) {
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
true);
return new NegativeRule(element, closed, zoomMin, zoomMax,
attributeMatcher);
}
AttributeMatcher keyMatcher = getKeyMatcher(keyList);
AttributeMatcher valueMatcher = getValueMatcher(valueList);
keyMatcher = RuleOptimizer.optimize(keyMatcher, ruleStack);
valueMatcher = RuleOptimizer.optimize(valueMatcher, ruleStack);
return new PositiveRule(element, closed, zoomMin, zoomMax,
keyMatcher, valueMatcher);
}
private static AttributeMatcher getKeyMatcher(List<String> keyList) {
if (STRING_WILDCARD.equals(keyList.get(0))) {
return AnyMatcher.getInstance();
}
AttributeMatcher attributeMatcher = MATCHERS_CACHE_KEY.get(keyList);
if (attributeMatcher == null) {
if (keyList.size() == 1) {
attributeMatcher = new SingleKeyMatcher(keyList.get(0));
} else {
attributeMatcher = new MultiKeyMatcher(keyList);
}
MATCHERS_CACHE_KEY.put(keyList, attributeMatcher);
}
return attributeMatcher;
}
private static AttributeMatcher getValueMatcher(List<String> valueList) {
if (STRING_WILDCARD.equals(valueList.get(0))) {
return AnyMatcher.getInstance();
}
AttributeMatcher attributeMatcher = MATCHERS_CACHE_VALUE.get(valueList);
if (attributeMatcher == null) {
if (valueList.size() == 1) {
attributeMatcher = new SingleValueMatcher(valueList.get(0));
} else {
attributeMatcher = new MultiValueMatcher(valueList);
}
MATCHERS_CACHE_VALUE.put(valueList, attributeMatcher);
}
return attributeMatcher;
}
private static void validate(String elementName, String keys, String values,
byte zoomMin, byte zoomMax) {
if (keys == null) {
throw new IllegalArgumentException("missing attribute k for element: "
+ elementName);
} else if (values == null) {
throw new IllegalArgumentException("missing attribute v for element: "
+ elementName);
} else if (zoomMin < 0) {
throw new IllegalArgumentException("zoom-min must not be negative: "
+ zoomMin);
} else if (zoomMax < 0) {
throw new IllegalArgumentException("zoom-max must not be negative: "
+ zoomMax);
} else if (zoomMin > zoomMax) {
throw new IllegalArgumentException(
"zoom-min must be less or equal zoom-max: " + zoomMin);
}
}
static Rule create(String elementName, Attributes attributes, Stack<Rule> ruleStack) {
int element = Element.ANY;
String keys = null;
String values = null;
int closed = Closed.ANY;
byte zoomMin = 0;
byte zoomMax = Byte.MAX_VALUE;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("e".equals(name)) {
String val = value.toUpperCase(Locale.ENGLISH);
if ("WAY".equals(val))
element = Element.WAY;
else if ("NODE".equals(val))
element = Element.NODE;
} else if ("k".equals(name)) {
keys = value;
} else if ("v".equals(name)) {
values = value;
} else if ("closed".equals(name)) {
String val = value.toUpperCase(Locale.ENGLISH);
if ("YES".equals(val))
closed = Closed.YES;
else if ("NO".equals(val))
closed = Closed.NO;
} else if ("zoom-min".equals(name)) {
zoomMin = Byte.parseByte(value);
} else if ("zoom-max".equals(name)) {
zoomMax = Byte.parseByte(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, keys, values, zoomMin, zoomMax);
return createRule(ruleStack, element, keys, values, closed, zoomMin, zoomMax);
}
private ArrayList<RenderInstruction> mRenderInstructions;
private ArrayList<Rule> mSubRules;
private Rule[] mSubRuleArray;
private RenderInstruction[] mRenderInstructionArray;
final byte mZoomMax;
final byte mZoomMin;
final int mElement;
final int mClosed;
Rule(int element, int closed, byte zoomMin,
byte zoomMax) {
mClosed = closed;
mElement = element;
mZoomMin = zoomMin;
mZoomMax = zoomMax;
mRenderInstructions = new ArrayList<RenderInstruction>(4);
mSubRules = new ArrayList<Rule>(4);
}
void addRenderingInstruction(RenderInstruction renderInstruction) {
mRenderInstructions.add(renderInstruction);
}
void addSubRule(Rule rule) {
mSubRules.add(rule);
}
abstract boolean matchesNode(Tag[] tags, byte zoomLevel);
abstract boolean matchesWay(Tag[] tags, byte zoomLevel, int closed);
void matchNode(IRenderCallback renderCallback, Tag[] tags, byte zoomLevel,
List<RenderInstruction> matchingList) {
if (matchesNode(tags, zoomLevel)) {
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
matchingList.add(mRenderInstructionArray[i]);
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].matchNode(renderCallback, tags, zoomLevel, matchingList);
}
}
void matchWay(IRenderCallback renderCallback, Tag[] tags, byte zoomLevel,
int closed,
List<RenderInstruction> matchingList) {
if (matchesWay(tags, zoomLevel, closed)) {
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
matchingList.add(mRenderInstructionArray[i]);
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].matchWay(renderCallback, tags, zoomLevel, closed,
matchingList);
}
}
void onComplete() {
MATCHERS_CACHE_KEY.clear();
MATCHERS_CACHE_VALUE.clear();
mRenderInstructionArray = new RenderInstruction[mRenderInstructions.size()];
mRenderInstructions.toArray(mRenderInstructionArray);
// for (int i = 0, n = mRenderInstructions.size(); i < n; i++)
// mRenderInstructionArray[i] = mRenderInstructions.get(i);
mSubRuleArray = new Rule[mSubRules.size()];
mSubRules.toArray(mSubRuleArray);
// for (int i = 0, n = mSubRules.size(); i < n; i++)
// mSubRuleArray[i] = mSubRules.get(i);
mRenderInstructions.clear();
mRenderInstructions = null;
mSubRules.clear();
mSubRules = null;
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].onComplete();
}
void onDestroy() {
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
mRenderInstructionArray[i].destroy();
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].onDestroy();
}
void scaleStrokeWidth(float scaleFactor) {
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
mRenderInstructionArray[i].scaleStrokeWidth(scaleFactor);
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].scaleStrokeWidth(scaleFactor);
}
void scaleTextSize(float scaleFactor) {
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
mRenderInstructionArray[i].scaleTextSize(scaleFactor);
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].scaleTextSize(scaleFactor);
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.util.Stack;
final class RuleOptimizer {
// private static final Logger LOG = Logger.getLogger(RuleOptimizer.class.getName());
private static AttributeMatcher optimizeKeyMatcher(AttributeMatcher attributeMatcher,
Stack<Rule> ruleStack) {
for (int i = 0, n = ruleStack.size(); i < n; ++i) {
if (ruleStack.get(i) instanceof PositiveRule) {
PositiveRule positiveRule = (PositiveRule) ruleStack.get(i);
if (positiveRule.mKeyMatcher != null
&& positiveRule.mKeyMatcher.isCoveredBy(attributeMatcher)) {
return null; // AnyMatcher.getInstance();
}
}
}
return attributeMatcher;
}
private static AttributeMatcher optimizeValueMatcher(
AttributeMatcher attributeMatcher, Stack<Rule> ruleStack) {
for (int i = 0, n = ruleStack.size(); i < n; ++i) {
if (ruleStack.get(i) instanceof PositiveRule) {
PositiveRule positiveRule = (PositiveRule) ruleStack.get(i);
if (positiveRule.mValueMatcher != null
&& positiveRule.mValueMatcher.isCoveredBy(attributeMatcher)) {
return null; // AnyMatcher.getInstance();
}
}
}
return attributeMatcher;
}
static AttributeMatcher optimize(AttributeMatcher attributeMatcher,
Stack<Rule> ruleStack) {
if (attributeMatcher instanceof AnyMatcher)
return attributeMatcher;// return null;
else if (attributeMatcher instanceof NegativeMatcher) {
return attributeMatcher;
} else if (attributeMatcher instanceof SingleKeyMatcher) {
return optimizeKeyMatcher(attributeMatcher, ruleStack);
} else if (attributeMatcher instanceof SingleValueMatcher) {
return optimizeValueMatcher(attributeMatcher, ruleStack);
} else if (attributeMatcher instanceof MultiKeyMatcher) {
return optimizeKeyMatcher(attributeMatcher, ruleStack);
} else if (attributeMatcher instanceof MultiValueMatcher) {
return optimizeValueMatcher(attributeMatcher, ruleStack);
}
throw new IllegalArgumentException("unknown AttributeMatcher: "
+ attributeMatcher);
}
// static ClosedMatcher optimize(ClosedMatcher closedMatcher, Stack<Rule> ruleStack) {
// if (closedMatcher == null) {
// return null;
// }
//
// if (closedMatcher instanceof AnyMatcher) {
// return null;
// }
//
// for (int i = 0, n = ruleStack.size(); i < n; ++i) {
// ClosedMatcher matcher = ruleStack.get(i).mClosedMatcher;
// if (matcher == null)
// return null;
//
// if (matcher.isCoveredBy(closedMatcher)) {
// return null; // AnyMatcher.getInstance();
//
// } else if (!closedMatcher.isCoveredBy(ruleStack.get(i).mClosedMatcher)) {
// LOG.warning("unreachable rule (closed)");
// }
// }
//
// return closedMatcher;
// }
//
// static ElementMatcher optimize(ElementMatcher elementMatcher, Stack<Rule> ruleStack) {
//
// if (elementMatcher == null) {
// return null;
// }
//
// if (elementMatcher instanceof AnyMatcher) {
// return null;
// }
//
// for (int i = 0, n = ruleStack.size(); i < n; ++i) {
// ElementMatcher matcher = ruleStack.get(i).mElementMatcher;
//
// if (matcher == null)
// return null;
//
// if (matcher.isCoveredBy(elementMatcher)) {
// return null; // AnyMatcher.getInstance();
//
// } else if (!elementMatcher.isCoveredBy(ruleStack.get(i).mElementMatcher)) {
// LOG.warning("unreachable rule (e)");
// }
// }
//
// return elementMatcher;
// }
/**
* Private constructor to prevent instantiation from other classes.
*/
private RuleOptimizer() {
// do nothing
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
class SingleKeyMatcher implements AttributeMatcher {
private final String mKey;
SingleKeyMatcher(String key) {
mKey = key.intern();
}
@Override
public boolean isCoveredBy(AttributeMatcher attributeMatcher) {
Tag[] tags = { new Tag(mKey, null) };
return attributeMatcher == this || attributeMatcher.matches(tags);
}
@Override
public boolean matches(Tag[] tags) {
for (Tag tag : tags)
if (mKey == tag.key)
return true;
return false;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import org.oscim.core.Tag;
class SingleValueMatcher implements AttributeMatcher {
private final String mValue;
SingleValueMatcher(String value) {
mValue = value.intern();
}
@Override
public boolean isCoveredBy(AttributeMatcher attributeMatcher) {
Tag[] tags = { new Tag(null, mValue) };
return attributeMatcher == this || attributeMatcher.matches(tags);
}
@Override
public boolean matches(Tag[] tags) {
for (Tag tag : tags)
if (mValue == tag.value)
return true;
return false;
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;
public interface Theme extends Serializable {
/**
* @return an InputStream to read the render theme data from.
* @throws FileNotFoundException
* if the render theme file cannot be found.
*/
InputStream getRenderThemeAsStream() throws FileNotFoundException;
}

View File

@@ -0,0 +1,974 @@
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns="http://mapsforge.org/renderTheme"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapsforge.org/renderTheme ../renderTheme.xsd"
version="1" map-background="#fcfcfa">
<style-pathtext name="road" k="name" font-size="16" fill="#101010" stroke="#ffffff" stroke-width="2.0" />
<style-pathtext name="major-road" k="name" font-style="bold" font-size="16" fill="#101010" stroke="#ffffff" stroke-width="2.0" />
<style-area name="residential" fill="#f0f0ec" fade="10"/>
<style-area name="railway|industrial" fill="#f2eeef" fade="10"/>
<!-- "#f0fae7" mint green -->
<style-area name="farmland" fill="#fff8bf" fade="11" />
<!-- fade out at z=7, blend over to 'blend-fill' in z=11 -->
<style-area name="forest|wood" fill="#ebefe5" fade="7" blend="11" blend-fill="#d3dec8"/>
<!-- grass|meadow|garden|grassland|scrub -->
<style-area name="greens" fill="#ebf2d2" fade="10" />
<!-- marsh|wetland|nature_reserve -->
<style-area name="greens2" fill="#deecb9" fade="12" />
<!-- park|common|green|cemetery|golf_course|dog_park -->
<style-area name="park" fill="#d7e6b0" fade="11" />
<!-- de:Kleingartengebiet -->
<style-area name="allotments" fill="#efeae0" fade="12" />
<!-- de:Steinbruch, Schotter-, Kies-, Sand- und Tongrube -->
<style-area name="quarry" fill="#ddddcc" fade="10" />
<style-area name="military" fill="#eeedea" fade="10"/>
<style-line name="residential" stroke="#ffffff" width="1.3" />
<style-line name="residential:bridge" from="residential" cap="square"/>
<!-- when inheriting another style with 'from' then 'witdth' is meant relative to the parent -->
<style-line name="pedestrian" from="residential" width="-0.4"/>
<style-line name="pedestrian:bridge" from="pedestrian" cap="square"/>
<style-line name="highway:z11" stroke="#fcba5a" width="1.8" />
<!-- <style-line name="highway:z11:bridge" from="highway:z11" cap="butt" /> -->
<style-line name="trunk_link" stroke="#fee16e" width="1.3" cap="butt"/>
<style-line name="trunk" stroke="#fedb52" width="1.6"/>
<style-line name="primary:z11" stroke="#fff000" width="1.5"/>
<style-line name="secondary:z11" from="primary:z11" width="-0.1"/>
<style-line name="tertiary" from="residential" width="0.2" />
<style-line name="construction" stroke="#e0e0e0" width="1.2" />
<style-line name="highway-service" from="residential" width="-0.6" />
<!-- track|footway|path|cycleway -->
<style-line name="footway" stroke="#c1bcb6" width="1.2" cap="butt" fixed="true"/>
<style-line name="footway:z16" from="footway" width="-1.0" fixed="false" fade="-1"/>
<style-line name="footway:z17" stroke="#faf8f5" width="0.3"/>
<!-- de: ein Weg der für Reiter vorgeshen ist.. -->
<style-line name="bridleway" stroke="#d3cb98" width="0.4" cap="butt"/>
<style-line name="steps" stroke="#f1f0f4" width="0.25" cap="butt" />
<style-line name="water:outline" stroke="#a4bbcc" width="1.0" fixed="true" cap="butt" />
<style-line name="water" stroke="#b4cbdc" width="1.0" cap="butt" />
<style-area name="water" fill="#b4cbdc" />
<!-- no-go area boundary -->
<style-line name="fence" stroke="#444444" width="1.2" fixed="true" cap="butt"/>
<style-line name="aeroway:runway" stroke="#c8ccbe" width="1.8" cap="butt" />
<style-line name="building" stroke="#c9c3c1" width="1.2" fixed="true" cap="butt" fade="15"/>
<style-area name="building" fill="#e9e6e3" fade="15"/>
<!-- ways -->
<rule e="way" k="*" v="*" >
<rule e="way" k="natural" v="grassland|scrub" zoom-min="10">
<use-area name="greens"/>
</rule>
<!-- landuse base -->
<rule e="way" k="landuse" v="*">
<rule e="way" k="*" zoom-min="10" v="farmland|farm|orchard|vineyard|greenhouse_horticulture|plant_nursery">
<use-area name="farmland"/>
</rule>
<rule e="way" k="*" v="quarry">
<use-area name="quarry"/>
</rule>
<rule e="way" k="*" v="residential|farmyard|retail|commercial|industrial;retail">
<use-area name="residential" />
</rule>
<rule e="way" k="*" v="industrial|railway">
<use-area name ="railway|industrial"/>
</rule>
<!-- <rule e="way" k="*" v="military">
<use-area name="military"/>
</rule> -->
<!--<rule e="way" k="landuse" v="construction|greenfield"> <area fill="#a47c41"
stroke="#e4e4e4" width="0.2" /> </rule> -->
<!-- <rule e="way" k="landuse" v="garages"> <area fill="#d6d6e4" /> </rule> -->
</rule>
<rule e="way" k="landuse|natural|leisure||amenity" v="*">
<!-- kind of more like landuse imho -->
<rule e="way" k="leisure|landuse" v="nature_reserve">
<use-area name="greens2" />
<rule e="way" k="*" v="*" zoom-min="14">
<line stroke="#abe29c" width="1.0" fixed="true" cap="butt" />
</rule>
</rule>
<!-- landuse -->
<rule e="way" k="landuse" v="*" zoom-min="11">
<!-- how about 'leisure' for this one? -->
<rule e="way" k="*" v="cemetery">
<use-area name="park"/>
</rule>
</rule>
<rule e="way" k="landuse" v="village_green|recreation_ground" >
<use-area name="greens" />
</rule>
<rule e="way" k="landuse" v="allotments" zoom-min="12">
<use-area name="allotments"/>
</rule>
<rule e="way" k="leisure" v="park|common|green|golf_course|dog_park" zoom-min="11">
<use-area name="park"/>
</rule>
<!-- Heideland, keep below forest -->
<rule e="way" k="*" zoom-min="11" v="heath|sand">
<area fill="#ffffc0" fade="11" />
</rule>
<rule e="way" k="landuse" v="forest">
<use-area name="forest|wood"/>
</rule>
<rule e="way" k="natural" v="wood">
<use-area name="forest|wood"/>
<!-- <line stroke="#abcfab" width="1.5" fixed="true" cap="butt"/> -->
</rule>
<!-- keep grass above forest:wood and leisure:park! -->
<rule e="way" k="landuse" v="grass|meadow">
<use-area name="greens"/>
</rule>
<rule e="way" k="leisure" v="garden">
<use-area name="greens"/>
</rule>
<rule e="way" k="leisure" v="track">
<line stroke="#c1bcb6" width="1.3" cap="butt" fixed="true" />
</rule>
<!-- amenity -->
<rule e="way" k="amenity" v="*">
<rule e="way" k="*" v="kindergarten|school|college|university" zoom-min="14">
<area fill="#cdabde" />
<line stroke="#9aabae" width="1.0" fixed="true" cap="butt"/>
</rule>
<rule e="way" k="*" v="parking" zoom-min="14">
<area fill="#f4f4f4" stroke="#d4d4d4" stroke-width="0.2" />
</rule>
<rule e="way" k="*" v="fountain" closed="yes">
<area fill="#b4cbdc" stroke="#000080" stroke-width="0.15" />
</rule>
</rule>
<!-- <rule e="way" k="natural" v="coastline">
<line stroke="#a4bbcc" width="1.2" fixed="true" />
</rule> -->
<!-- natural -->
<rule e="way" k="natural" v="*" zoom-min="10">
<rule e="way" k="*" v="glacier">
<area fill="#fafaff" />
</rule>
<rule e="way" k="*" v="land">
<area fill="#f8f8f8" />
</rule>
<rule e="way" k="*" v="beach">
<area fill="#fcfeab" />
</rule>
<rule e="way" k="*" v="marsh|wetland|mud">
<use-area name="greens2" />
</rule>
</rule>
<!-- leisure -->
<rule e="way" k="leisure" v="*" zoom-min="13">
<rule e="way" k="*" v="stadium" >
<line stroke="#c9c3c1" width="1.0" fixed="true" cap="butt" />
<area fill="#e9e6e3" />
</rule>
<!--should be under playing field -->
<rule e="way" k="*" zoom-min="14" v="sports_centre|water_park">
<area fill="#daefdb" fade="12" />
</rule>
<rule e="way" k="*" zoom-min="15" v="playground|miniature_golf">
<area fill="#f4f4de" />
<line stroke="#fbdbc8" width="0.6" fixed="true" cap="butt" />
</rule>
<rule e="way" k="*" v="playing_fields|pitch">
<area fill="#f4f4de" />
<line stroke="#dbdbc8" width="0.6" fixed="true" cap="butt" />
</rule>
<rule e="way" k="*" v="swimming_pool">
<area fill="#b4cbdc" stroke="#6060ff" width="0.2" />
</rule>
<!-- <rule e="way" k="*" v="track"> <rule e="way" k="area" v="yes|true">
<area fill="#c9d8a2" stroke="#b7c690" width="0.025" /> </rule> <rule
e="way" k="area" v="~|no|false"> <line stroke="#b7c690" width="0.75"
/> </rule> </rule> -->
</rule>
<!-- area outlines need to be above to avoid uggly pixelation where
not aliased polygon overlaps the lines... -->
<rule e="way" k="leisure|landuse" v="*" zoom-min="14">
<rule e="way" k="*" v="nature_reserve">
<line stroke="#abe29c" width="1.0" fixed="true" cap="butt" />
</rule>
<rule e="way" k="*" v="military">
<use-line name="fence" />
</rule>
</rule>
<rule e="way" k="natural" v="water">
<use-area name="water"/>
<use-line name="water:outline"/>
</rule>
</rule>
<rule e="way" k="landuse" v="reservoir|basin">
<use-area name="water" />
</rule>
<!-- waterways -->
<rule e="way" k="waterway" v="*">
<rule e="way" k="waterway" v="ditch|drain" zoom-min="14">
<use-line name="water" width="0.1" fixed="true"/>
</rule>
<rule e="way" k="waterway" v="canal">
<use-line name="water" width="-0.2"/>
</rule>
<rule e="way" k="waterway" v="stream" zoom-min="14">
<use-line name="water" width="-0.7"/>
</rule>
<rule e="way" k="waterway" v="river">
<rule e="way" k="*" v="*" zoom-min="12">
<use-line name="water" width="0.3"/>
</rule>
<rule e="way" k="*" v="*" zoom-max="11">
<use-line name="water" width="0.3" fixed="true"/>
</rule>
</rule>
<rule e="way" k="waterway" v="riverbank|dock">
<use-area name="water"/>
<use-line name="water:outline"/>
</rule>
<rule e="way" k="waterway" v="weir">
<line stroke="#000044" width="0.375" cap="butt" />
</rule>
<rule e="way" k="waterway" v="dam" zoom-min="12">
<!-- sehr seltsam was in deutschland so als Damm gekenzeichnet wird.. -->
<line stroke="#ababab" width="1.2" cap="butt" fixed="true" />
</rule>
<rule e="way" k="lock" v="yes|true">
<line stroke="#f8f8f8" width="1.5" cap="butt" />
</rule>
</rule>
<!-- sport -->
<!-- <rule e="way" k="sport" v="*"> <rule e="way" k="sport" v="soccer"
zoom-min="17"> <rule e="way" k="sport" v="swimming|canoe|diving|scuba_diving">
<area fill="#b4cbdc" stroke="#6060ff" width="0.2" /> </rule> <rule
e="way" k="sport" v="tennis"> <area fill="#d18a6a" stroke="#b36c4c" width="0.2"
/> </rule> </rule> -->
<!-- tourism areas -->
<rule e="way" k="tourism" v="*">
<!-- <rule e="way" k="tourism" v="attraction"> <area fill="#f2caea" /> </rule> -->
<rule e="way" k="tourism" v="zoo|picnic_site|caravan_site|camp_site">
<area fill="#d7e6b0" />
</rule>
</rule>
<!-- outline 0 -->
<style-outline name="glow" stroke="#000000" width="0.2" blur="1.0"/>
<style-outline name="0" stroke="#44000000" width="0.1" />
<!-- tunnel -->
<rule e="way" k="tunnel" v="yes|true" zoom-min="11">
<!-- highway tunnels -->
<rule e="way" k="highway" v="*">
<rule e="way" k="*" v="*" zoom-min="15">
<rule e="way" k="*" v="steps">
<use-line name="steps"/>
<use-outline name="0"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16">
<use-line name="footway:z16"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
<rule e="way" k="*" v="construction">
<use-line name="construction"/>
<use-outline name="0"/>
</rule>
<rule e="way" k="*" v="service">
<rule e="way" k="service" v="~|parking_aisle">
<use-line name="highway-service"/>
<use-outline name="0"/>
</rule>
</rule>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link">
<use-line name="trunk_link"/>
<use-outline name="0"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="*" zoom-min="13">
<rule e="way" k="*" v="byway|pedestrian">
<use-line name="pedestrian"/>
<use-outline name="0"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="residential|road|unclassified|living_street">
<use-line name="residential"/>
<use-outline name="0"/>
<use-text name="road"/>
</rule>
</rule>
<rule e="way" k="*" v="tertiary|secondary_link">
<use-line name="tertiary"/>
<use-outline name="0"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="secondary|primary_link">
<use-line name="secondary:z11"/>
<use-outline name="0"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="primary">
<use-line name="primary:z11"/>
<use-outline name="0"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="trunk">
<use-line name="trunk" blur="0.3"/>
<use-outline name="0"/>
<!-- <use-outline name="glow"/> -->
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="motorway">
<use-line name="highway:z11" blur="0.3"/>
<use-outline name="0"/>
<!-- <use-outline name="glow"/> -->
<use-text name="major-road"/>
</rule>
</rule>
<!-- railway tunnel -->
<rule e="way" k="railway" v="*">
<!-- <rule e="way" k="railway" v="tram|subway|light_rail|narrow_gauge">
<line stroke="#a0a0a0" width="0.8" cap="butt" fixed="true"/>
</rule> -->
<rule e="way" k="railway" v="rail">
<line stroke="#aa888888" width="0.9" cap="butt" fixed="true" />
</rule>
</rule>
</rule> <!-- end tunnel -->
<!-- platform cores -->
<rule e="way" k="highway|railway|public_transport" v="platform">
<rule e="way" k="*" v="*" closed="yes">
<area fill="#dbdbc9" />
</rule>
<rule e="way" k="*" v="*" closed="no">
<line stroke="#dbdbc9" width="0.3" />
</rule>
</rule>
<!-- runways areas -->
<rule e="way" k="aeroway" v="*">
<rule e="way" k="*" v="aerodrome" closed="yes">
<area fill="#e8ecde" />
</rule>
<!-- A place where planes are parked -->
<rule e="way" k="*" v="apron">
<area fill="#f0f0f0" />
</rule>
<!-- Airport passenger building -->
<rule e="way" k="*" v="terminal|hangar">
<use-line name="building" />
<use-area name="building" />
</rule>
</rule>
<!-- turning circles -->
<!-- <rule e="node" k="highway" v="turning_circle"> <circle r="1.5" scale-radius="true"
fill="#707070" />
</rule> -->
<!-- building -->
<rule e="way" k="building" v="*">
<rule e="way" k="*" v="*" zoom-min="15">
<use-area name="building" fade="15"/>
<use-line name="building" fade="15"/>
<!-- <line stroke="#c9c3c1" width="1.0" fixed="true" cap="butt" fade="15"/>
<area fill="#e9e6e3" fade="15" /> -->
</rule>
<!-- <rule e="way" k="*" v="*" zoom-min="17">
<caption k="name" font-style="bold" font-size="10" fill="#4040ff"
stroke="#ffffff" stroke-width="2.0" />
<caption k="addr:housenumber" font-style="bold" font-size="10" fill="#606060"
stroke="#ffffff" stroke-width="2.0" />
</rule> -->
</rule>
<!-- outline 1 - 4 -->
<style-outline name="1" stroke="#ee605020" width="0.02"/>
<!-- <style-outline name="1" stroke="#404030"/> -->
<style-outline name="2" stroke="#c0c0c0" />
<style-outline name="primary" stroke="#7f7700" width="0.025"/>
<style-outline name="motorway" stroke="#805f2e" width="0.025"/>
<!-- highway -->
<rule e="way" k="highway" v="*">
<rule e="way" k="*" v="*" zoom-min="5" zoom-max="10">
<rule e="way" k="area" v="~|no|false">
<rule e="way" k="*" v="secondary|primary_link" zoom-min="9">
<line stroke="#f2df6d" width="1.8" cap="butt" fixed="true" fade="9"/>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link" zoom-min="8">
<line stroke="#fed6a3" width="1.8" cap="butt" fixed="true" fade="8"/>
</rule>
<rule e="way" k="*" v="primary" zoom-min="5">
<line stroke="#f2df6d" width="1.8" cap="butt" fixed="true" fade="5"/>
</rule>
<rule e="way" k="*" v="trunk" zoom-min="5">
<line stroke="#fed6a3" width="2.0" cap="butt" fixed="true" fade="5"/>
</rule>
<rule e="way" k="*" v="motorway">
<line stroke="#eec693" width="2.2" cap="butt" fixed="true" fade="5"/>
</rule>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="11">
<rule e="way" k="tunnel|bridge" v="~|no|false">
<!-- highway area -->
<rule e="way" k="area" v="yes|true">
<rule e="way" k="tunnel|bridge" v="~|no|false">
<rule e="way" k="*" v="footway" zoom-min="15">
<area fill="#fefefe" />
<line stroke="#c0c0c0" width="1.0" fixed="true" cap="butt" />
</rule>
<rule e="way" k="*" zoom-min="13" v="pedestrian|service|unclassified|residential|road|living_street">
<area fill="#ffffff" />
<line stroke="#d0d0d0" width="1.0" fixed="true" cap="butt" />
</rule>
<!-- <rule e="way" k="*" v="path" zoom-min="14">
<area fill="#d0d0d0" />
</rule>-->
</rule>
</rule>
<rule e="way" k="area" v="~|no|false">
<rule e="way" k="*" v="*" zoom-min="15">
<rule e="way" k="*" v="steps">
<use-line name="steps"/>
<use-outline name="2"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16" zoom-max="16">
<use-line name="footway:z16"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="17">
<use-line name="footway:z17"/>
<use-outline name="1"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
<rule e="way" k="*" v="construction">
<use-line name="construction"/>
<use-outline name="1"/>
</rule>
<rule e="way" k="*" v="service">
<rule e="way" k="service" v="-|parking_aisle">
<use-line name="highway-service"/>
<use-outline name="1"/>
</rule>
<rule e="way" k="service" v="parking_aisle" zoom-min="16">
<use-line name="highway-service" width="-0.4"/>
<use-outline name="1"/>
</rule>
</rule>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link">
<use-line name="trunk_link"/>
<use-outline name="motorway"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="*" zoom-min="13">
<rule e="way" k="*" v="byway|pedestrian">
<use-line name="residential" width="-0.4"/>
<use-outline name="1"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="residential|road|unclassified|living_street">
<use-line name="residential"/>
<use-outline name="1"/>
<use-text name="road"/>
</rule>
</rule>
<rule e="way" k="*" v="tertiary|secondary_link">
<use-line name="tertiary"/>
<use-outline name="1"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="secondary|primary_link">
<!-- <line stroke="#fff939" width="1.6" /> -->
<use-line name="secondary:z11"/>
<use-outline name="primary"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="primary">
<use-line name="primary:z11"/>
<use-outline name="primary"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="trunk">
<use-line name="trunk"/>
<use-outline name="motorway"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="motorway">
<use-line name="highway:z11"/>
<use-outline name="motorway"/>
<use-text name="major-road"/>
</rule>
</rule> <!-- end area=~|no|false -->
</rule> <!-- end tunnel|bridge=~|no|false -->
<rule e="way" k="bridge" v="yes|true|viaduct|suspension">
<rule e="way" k="area" v="~|no|false">
<style-outline name="bridge" stroke="#aa202020" width="0.08"/>
<rule e="way" k="*" v="*" zoom-min="15">
<rule e="way" k="*" v="steps">
<use-line name="steps"/>
<use-outline name="bridge"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16" zoom-max="16">
<use-line name="footway:z16"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="17">
<use-line name="footway:z17" cap="butt"/>
<use-outline name="bridge"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
<rule e="way" k="*" v="construction">
<use-line name="construction" cap="square"/>
<use-outline name="bridge"/>
</rule>
<rule e="way" k="*" v="service">
<use-line name="highway-service" cap="square"/>
<use-outline name="bridge"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="13">
<rule e="way" k="*" v="byway|pedestrian">
<use-line name="pedestrian:bridge"/>
<use-outline name="bridge"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="residential|road|unclassified|living_street">
<use-line name="residential:bridge"/>
<use-outline name="bridge"/>
<use-text name="road"/>
</rule>
</rule>
<rule e="way" k="*" v="tertiary|secondary_link">
<use-line name="tertiary" cap="square"/>
<use-outline name="bridge"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link">
<use-line name="trunk_link" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="secondary|primary_link">
<!-- <line stroke="#fff939" width="1.6" cap="butt" /> -->
<use-line name="secondary:z11" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="primary">
<use-line name="primary:z11" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="trunk">
<use-line name="trunk" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="motorway">
<use-line name="highway:z11" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
</rule> <!-- end area=~|no|false -->
<rule e="way" k="area" v="yes|true">
<rule e="way" k="*" v="footway" zoom-min="15">
<area fill="#fefefe" />
<line stroke="#c0c0c0" width="0.15" cap="butt" />
</rule>
<rule e="way" k="*" zoom-min="13" v="pedestrian|service|unclassified|residential|road|living_street">
<area fill="#ffffff" />
<line stroke="#d0d0d0" width="1.0" fixed="true" cap="butt" />
</rule>
<!-- <rule e="way" k="*" v="path" zoom-min="14">
<area fill="#d0d0d0" />
</rule>-->
</rule> <!-- end area=yes|true -->
</rule> <!-- end bridge=yes -->
</rule> <!-- end zoom-min=11 -->
</rule> <!-- end highway -->
<!-- runways cores -->
<rule e="way" k="aeroway" v="*">
<rule e="way" k="*" v="runway">
<use-line name="aeroway:runway"/>
</rule>
<rule e="way" k="*" v="taxiway">
<use-line name="aeroway:runway" width="-0.8"/>
</rule>
</rule>
<!-- man_made features -->
<!-- <rule e="way" k="man_made" v="pier">
<rule e="way" k="*" v="*" closed="no">
<line stroke="#d0d0d0" width="0.4" cap="butt" />
<line stroke="#e4e4e4" width="0.3" cap="butt" />
</rule>
<rule e="way" k="*" v="*" closed="yes">
<area fill="#e4e4e4" stroke="#d0d0d0" stroke-width="0.05" />
</rule>
</rule> -->
<!-- barriers -->
<rule e="way" k="barrier" v="*">
<!-- <rule e="way" k="*" v="fence|wall|city_wall" zoom-min="15"> <line
stroke="#909090" width="0.1" cap="butt" /> </rule> -->
<rule e="way" k="*" v="retaining_wall" zoom-min="15">
<line stroke="#888888" width="0.1" cap="butt" />
</rule>
</rule>
<!-- non-physical routes -->
<!-- <rule e="way" k="route" v="ferry"> <line stroke="#707070" width="0.3"
stroke-dasharray="15,10" cap="butt" /> </rule> -->
<!-- aerial ways -->
<!-- <rule e="way" k="aerialway" v="*"> <line stroke="#202020" width="0.4"
cap="butt" /> <rule e="way" k="aerialway" v="cable_car"> <lineSymbol
src="jar:/org/mapsforge/android/maps/rendertheme/osmarender/symbols/cable_car.png"
/> </rule> <rule e="way" k="aerialway" v="chair_lift"> <lineSymbol src="jar:/org/mapsforge/android/maps/rendertheme/osmarender/symbols/chair_lift_2.png"
/> </rule> <rule e="way" k="aerialway" v="gondola"> <lineSymbol src="jar:/org/mapsforge/android/maps/rendertheme/osmarender/symbols/gondola.png"
/> </rule> <rule e="way" k="*" v="*" zoom-min="14"> <pathText k="name" font-style="bold"
font-size="10" fill="#606060" stroke="#ffffff" width="2.0" /> </rule>
</rule> -->
<!-- railway (no tunnel) -->
<rule e="way" k="railway" v="*" zoom-min="12">
<rule e="way" k="tunnel" v="~|false|no">
<rule e="way" k="railway" v="station">
<area fill="#dbdbc9" stroke="#707070" stroke-width="0.3" />
</rule>
<!-- railway bridge casings -->
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="bridge" v="yes|true">
<rule e="way" k="railway" v="tram">
<line stroke="#777777" width="0.9" cap="butt"
fixed="true" />
</rule>
<rule e="way" k="railway" v="subway|light_rail|narrow_gauge">
<line stroke="#777777" width="0.9" cap="butt"
fixed="true" />
</rule>
<rule e="way" k="railway" v="rail">
<line stroke="#777777" width="0.9" cap="butt"
fixed="true" />
</rule>
</rule>
</rule>
<!-- railway casings and cores -->
<rule e="way" k="railway" v="tram" zoom-min="15">
<line stroke="#887766" width="1.0" fixed="true" />
</rule>
<rule e="way" k="railway" v="light_rail|subway|narrow_gauge" zoom-min="14">
<line stroke="#a0a0a0" width="0.9" cap="butt" fixed="true" />
</rule>
<rule e="way" k="railway" v="rail|turntable" >
<line stroke="#887766" width="0.8" cap="butt" fixed="true" fade="12"/>
</rule>
<!-- <rule e="way" k="railway" v="rail" zoom-max="14" zoom-min="13">
<line stroke="#8888aa" width="0.6" cap="butt"
fixed="true" />
</rule> -->
<!-- <rule e="way" k="railway" v="rail" zoom-max="13" zoom-min="11">
<line stroke="#bbbbcc" width="0.8" cap="butt" fixed="true" />
</rule> -->
<!-- whatever railway:spur means ... -->
<rule e="way" k="railway" v="disused|spur|abandoned|preserved" >
<line stroke="#cccccc" width="0.8" cap="butt" fixed="true" fade="12"/>
</rule>
</rule>
</rule>
<!-- non-physical boundaries -->
<!-- <rule e="way" k="boundary" v="*"> <rule e="way" k="boundary" v="national_park">
<line stroke="#4ef94b" width="0.25" stroke-dasharray="15, 5, 5, 5"
/> -->
<!--<rule e="way" k="boundary" v="administrative"> -->
<rule e="way" k="admin_level" v="*">
<!-- <rule e="way" k="admin_level" v="11"> <line stroke="#f9574b" width="0.1"
fixed="true" cap="butt" /> </rule> <rule e="way" k="admin_level"
v="10"> <line stroke="#f9574b" width="0.1" fixed="true" cap="butt"
/> </rule> <rule e="way" k="admin_level" v="9"> <line stroke="#f9574b" width="0.1"
fixed="true" cap="butt" /> </rule> <rule e="way" k="admin_level"
v="8"> <line stroke="#f9574b" width="0.3" fixed="true" cap="butt"
/> </rule> <rule e="way" k="admin_level" v="7"> <line stroke="#f9574b" width="0.1"
fixed="true" cap="butt" /> </rule> <rule e="way" k="admin_level"
v="6"> <line stroke="#f9574b" width="0.15" fixed="true" cap="butt"
/> </rule> <rule e="way" k="admin_level" v="5"> <line stroke="#f9574b" width="0.15"
fixed="true" cap="butt" /> </rule> -->
<rule e="way" k="admin_level" v="4">
<line stroke="#8f80dd" width="0.9" fixed="true" cap="butt" />
</rule>
<rule e="way" k="admin_level" v="3">
<line stroke="#0000ff" width="0.95" fixed="true" cap="butt" />
</rule>
<rule e="way" k="admin_level" v="2">
<line stroke="#a0a0a0" width="0.95" fixed="true" cap="butt" />
</rule>
<rule e="way" k="admin_level" v="1">
<line stroke="#ff0000" width="0.95" fixed="true" cap="butt" />
</rule>
</rule>
<!-- </rule> -->
<!-- historic -->
<!-- <rule e="way" k="historic" v="ruins" zoom-min="17">
<caption k="name" font-style="bold" font-size="10" fill="#4040ff" stroke="#ffffff" stroke-width="2.0" />
</rule> -->
<!-- place -->
<rule e="way" k="place" v="locality" zoom-min="17">
<caption k="name" font-style="bold" font-size="10" fill="#000000" stroke="#ffffff" stroke-width="2.0" />
</rule>
<rule e="way" k="debug" v="area">
<line stroke="#ff0000" width="1.2" fixed="true" cap="butt" />
<area fill="#880000ff"/>
<caption k="name" font-size="15" fill="#ff0000" stroke="#444444" stroke-width="2.0"/>
</rule>
<rule e="way" k="debug" v="way">
<line stroke="#00ffff" width="1.5" fixed="true" cap="butt" />
<caption k="name" font-size="15" fill="#00ffff" stroke="#444444" stroke-width="2.0"/>
</rule>
<rule e="way" k="debug" v="box">
<line stroke="#000000" width="1.5" fixed="true" cap="butt" />
</rule>
</rule>
<rule e="node" k="*" v="*">
<!-- barrier -->
<rule e="node" k="barrier" v="bollard">
<circle r="1.5" fill="#909090" />
</rule>
<rule e="node" k="debug" v="*" >
<caption k="name" font-size="12" fill="#0000ff" />
</rule>
<!-- highway -->
<!-- <rule e="node" k="highway" v="*"> <rule e="node" k="highway" v="turning_circle">
<circle r="1.4" scale-radius="true" fill="#ffffff" /> </rule> </rule> -->
<!-- historic -->
<!-- <rule e="node" k="historic" v="*"> <circle r="3" fill="#4040ff" stroke="#606060"
width="1.5" /> <rule e="node" k="*" v="*" zoom-min="17"> <caption
k="name" dy="-10" font-style="bold" font-size="10" fill="#4040ff" stroke="#ffffff"
width="2.0" /> </rule> </rule> -->
<!-- house numbers -->
<!-- <rule e="node" k="addr:housenumber" v="*" zoom-min="18"> <caption
k="addr:housenumber" font-style="bold" font-size="10" fill="#606060" stroke="#ffffff"
width="2.0" /> </rule> -->
<!-- place -->
<rule e="node" k="place" v="*">
<rule e="node" k="*" v="suburb|town|village">
<caption k="name" font-size="18" fill="#000000"
stroke="#ffffff" stroke-width="2.0" />
</rule>
<rule e="node" k="*" v="island" zoom-min="10">
<caption k="name" font-style="bold" font-size="20" fill="#000000"
stroke="#ffffff" stroke-width="2.0" />
</rule>
<rule e="node" k="*" v="city">
<caption k="name" font-style="bold" font-size="20" fill="#000000"
stroke="#ffffff" stroke-width="2.0" />
</rule>
<rule e="node" k="*" v="country">
<caption k="name" font-size="20" fill="#000000"
stroke="#ffffff" stroke-width="2.0" />
</rule>
</rule>
<!-- railway -->
<rule e="node" k="railway" v="*">
<rule e="node" k="*" v="station" zoom-min="14">
<circle r="6" fill="#ec2d2d" stroke="#606060" width="1.5" />
<!-- <caption k="name" dy="-10" font-style="bold" font-size="13" fill="#ec2d2d"
stroke="#ffffff" stroke-width="2.0" /> -->
</rule>
<rule e="node" k="*" v="halt|tram_stop" zoom-min="17">
<circle r="4" fill="#ec2d2d" stroke="#606060" width="1.5" />
<!-- <caption k="name" dy="-15" font-style="bold" font-size="11" fill="#ec2d2d"
stroke="#ffffff" stroke-width="2.0" /> -->
</rule>
</rule>
</rule>
</rendertheme>

View File

@@ -0,0 +1,992 @@
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns="http://mapsforge.org/renderTheme"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapsforge.org/renderTheme ../renderTheme.xsd"
version="1" map-background="#050508">
<style-pathtext name="road" k="name" font-style="bold" font-size="18" stroke="#606050" fill="#eeffee" stroke-width="2.5" />
<style-pathtext name="major-road" k="name" font-style="bold" font-size="19" fill="#e2cf5d" stroke="#101010" stroke-width="2.5" />
<style-area name="residential" fill="#ff0000" fade="10"/>
<style-area name="railway|industrial" fill="#f2eeef" fade="10"/>
<!-- "#f0fae7" mint green -->
<style-area name="farmland" fill="#fff8bf" fade="11" />
<!-- fade out at z=7, blend over to 'blend-fill' in z=11 -->
<style-area name="forest|wood" fill="#151806" fade="7" blend="11" blend-fill="#1e2205"/>
<!-- grass|meadow|garden|grassland|scrub -->
<style-area name="greens" fill="#33390c" fade="10" />
<!-- marsh|wetland|nature_reserve -->
<style-area name="greens2" fill="#627100" fade="12" />
<!-- park|common|green|cemetery|golf_course|dog_park -->
<style-area name="park" fill="#627100" fade="11" />
<!-- de:Kleingartengebiet -->
<style-area name="allotments" fill="#efeae0" fade="12" />
<!-- de:Steinbruch, Schotter-, Kies-, Sand- und Tongrube -->
<style-area name="quarry" fill="#ddddcc" fade="10" />
<style-area name="military" fill="#eeedea" fade="10"/>
<style-line name="residential" stroke="#ffffff" width="1.0" blur="1.0" fade="13"/>
<style-line name="residential:bridge" from="residential" cap="square"/>
<!-- when inheriting another style with 'from' then 'witdth' is meant relative to the parent -->
<style-line name="pedestrian" from="residential" width="-0.4"/>
<style-line name="pedestrian:bridge" from="pedestrian" cap="square"/>
<style-line name="highway:z11" stroke="#fcba5a" width="1.8" blur="0.9"/>
<!-- <style-line name="highway:z11:bridge" from="highway:z11" cap="butt" /> -->
<style-line name="trunk_link" stroke="#fee16e" width="1.3" cap="butt" blur="0.9"/>
<style-line name="trunk" stroke="#fedb52" width="1.6" blur="0.9"/>
<style-line name="primary:z11" stroke="#f2df6d" width="1.5" blur="0.9"/>
<style-line name="secondary:z11" from="primary:z11" width="-0.1"/>
<style-line name="tertiary" from="residential" width="0.2" fade="11"/>
<style-line name="construction" stroke="#e0e0e0" width="1.2" />
<style-line name="highway-service" from="residential" width="-0.6" />
<!-- track|footway|path|cycleway -->
<style-line name="footway" stroke="#c1bcb6" width="1.2" cap="butt" fixed="true"/>
<style-line name="footway:z16" from="footway" width="-1.0" fixed="false" fade="-1"/>
<style-line name="footway:z17" stroke="#faf8f5" width="0.3"/>
<!-- de: ein Weg der für Reiter vorgeshen ist.. -->
<style-line name="bridleway" stroke="#d3cb98" width="0.4" cap="butt"/>
<style-line name="steps" stroke="#f1f0f4" width="0.25" cap="butt" />
<style-line name="water:outline" stroke="#a4bbcc" width="1.0" cap="butt" />
<style-line name="water" stroke="#cca4bbcc" width="0.6" cap="butt" />
<style-area name="water" fill="#001223" />
<!-- no-go area boundary -->
<style-line name="fence" stroke="#444444" width="1.2" fixed="true" cap="butt"/>
<style-line name="aeroway:runway" stroke="#008888" width="1.8" cap="butt" blur="0.7" />
<style-line name="building" stroke="#dd999999" width="1.8" fixed="true" cap="butt"/>
<style-area name="building" fill="#ee202020" fade="15"/>
<!-- ways -->
<rule e="way" k="*" v="*" >
<rule e="way" k="natural" v="grassland|scrub" zoom-min="10">
<use-area name="greens"/>
</rule>
<!-- landuse base -->
<rule e="way" k="landuse" v="*">
<!-- <rule e="way" k="*" zoom-min="10" v="farmland|farm|orchard|vineyard|greenhouse_horticulture|plant_nursery">
<use-area name="farmland"/>
</rule>
<rule e="way" k="*" v="quarry">
<use-area name="quarry"/>
</rule>
<rule e="way" k="*" v="residential|farmyard|retail|commercial|industrial;retail">
<use-area name="residential" />
</rule>
<rule e="way" k="*" v="industrial|railway">
<use-area name ="railway|industrial"/>
</rule>
-->
<!-- <rule e="way" k="*" v="military">
<use-area name="military"/>
</rule> -->
<!--<rule e="way" k="landuse" v="construction|greenfield"> <area fill="#a47c41"
stroke="#e4e4e4" width="0.2" /> </rule> -->
<!-- <rule e="way" k="landuse" v="garages"> <area fill="#d6d6e4" /> </rule> -->
</rule>
<rule e="way" k="landuse|natural|leisure||amenity" v="*">
<!-- kind of more like landuse imho -->
<rule e="way" k="leisure|landuse" v="nature_reserve">
<use-area name="greens2" />
<rule e="way" k="*" v="*" zoom-min="14">
<line stroke="#abe29c" width="1.0" fixed="true" cap="butt" />
</rule>
</rule>
<!-- landuse -->
<rule e="way" k="landuse" v="*" zoom-min="11">
<!-- how about 'leisure' for this one? -->
<rule e="way" k="*" v="cemetery">
<use-area name="park"/>
</rule>
<rule e="way" k="*" v="reservoir|basin">
<use-area name="water" />
</rule>
</rule>
<rule e="way" k="landuse" v="village_green|recreation_ground" >
<use-area name="greens" />
</rule>
<!-- <rule e="way" k="landuse" v="allotments" zoom-min="12">
<use-area name="allotments"/>
</rule>-->
<rule e="way" k="leisure" v="park|common|green|golf_course|dog_park" zoom-min="11">
<use-area name="park"/>
</rule>
<!-- Heideland, keep below forest -->
<rule e="way" k="*" zoom-min="11" v="heath|sand">
<area fill="#0f0f0c" fade="11" />
</rule>
<rule e="way" k="landuse" v="forest">
<use-area name="forest|wood"/>
</rule>
<rule e="way" k="natural" v="wood">
<use-area name="forest|wood"/>
<!-- <line stroke="#abcfab" width="1.5" fixed="true" cap="butt"/> -->
</rule>
<!-- keep grass above forest:wood and leisure:park! -->
<rule e="way" k="landuse" v="grass|meadow">
<use-area name="greens"/>
</rule>
<rule e="way" k="leisure" v="garden">
<use-area name="greens"/>
</rule>
<rule e="way" k="leisure" v="track">
<line stroke="#c1bcb6" width="1.3" cap="butt" fixed="true" />
</rule>
<!-- amenity -->
<rule e="way" k="amenity" v="*">
<rule e="way" k="*" v="kindergarten|school|college|university" zoom-min="14">
<area fill="#cdabde" stroke="#b094bf" stroke-width="0.2" /> </rule>
<rule e="way" k="*" v="parking" zoom-min="14">
<area fill="#f4f4f4" stroke="#d4d4d4" stroke-width="0.2" />
</rule>
<rule e="way" k="*" v="fountain" closed="yes">
<area fill="#b4cbdc" stroke="#000080" stroke-width="0.15" />
</rule>
</rule>
<!-- <rule e="way" k="natural" v="coastline">
<line stroke="#a4bbcc" width="1.2" fixed="true" />
</rule> -->
<!-- natural -->
<rule e="way" k="natural" v="*" zoom-min="10">
<rule e="way" k="*" v="glacier">
<area fill="#fafaff" />
</rule>
<rule e="way" k="*" v="land">
<area fill="#080808" />
</rule>
<!-- <rule e="way" k="*" v="beach">
<area fill="#aaedd400"/>
<line stroke="#fce94f" fixed="true" width="2.8" />
</rule>-->
<rule e="way" k="*" v="marsh|wetland|mud">
<use-area name="greens2" />
</rule>
</rule>
<!-- leisure -->
<rule e="way" k="leisure" v="*" zoom-min="13">
<rule e="way" k="*" v="stadium" >
<area fill="#404040" />
<line stroke="#cccccc" width="1.0" fixed="true" cap="butt" />
</rule>
<!--should be under playing field -->
<!-- <rule e="way" k="*" zoom-min="14" v="sports_centre|water_park">
<area fill="#daefdb" fade="12" />
</rule>
<rule e="way" k="*" zoom-min="15" v="playground|miniature_golf">
<area fill="#f4f4de" />
<line stroke="#fbdbc8" width="0.6" fixed="true" cap="butt" />
</rule>
<rule e="way" k="*" v="playing_fields|pitch">
<area fill="#f4f4de" />
<line stroke="#dbdbc8" width="0.6" fixed="true" cap="butt" />
</rule>
-->
<rule e="way" k="*" v="swimming_pool">
<area fill="#b4cbdc" stroke="#6060ff" width="0.2" />
</rule>
<!-- <rule e="way" k="*" v="track"> <rule e="way" k="area" v="yes|true">
<area fill="#c9d8a2" stroke="#b7c690" width="0.025" /> </rule> <rule
e="way" k="area" v="~|no|false"> <line stroke="#b7c690" width="0.75"
/> </rule> </rule> -->
</rule>
<!-- area outlines need to be above to avoid uggly pixelation where
not aliased polygon overlaps the lines... -->
<rule e="way" k="leisure|landuse" v="*" zoom-min="14">
<rule e="way" k="*" v="nature_reserve">
<line stroke="#abe29c" width="1.0" fixed="true" cap="butt" />
</rule>
<rule e="way" k="*" v="military">
<use-line name="fence" />
</rule>
</rule>
</rule>
<!-- waterways -->
<rule e="way" k="waterway" v="*">
<rule e="way" k="waterway" v="ditch|drain" zoom-min="14">
<use-line name="water" width="0.1" fixed="true"/>
</rule>
<rule e="way" k="waterway" v="canal">
<use-line name="water" width="-0.2"/>
</rule>
<rule e="way" k="waterway" v="stream" zoom-min="14">
<use-line name="water" width="-0.1"/>
</rule>
<style-outline name="river" width="1.0" stroke="#456799" blur="1.0"/>
<rule e="way" k="waterway" v="river" closed="no">
<rule e="way" k="*" v="*" zoom-min="12">
<use-line name="water" width="0.5"/>
<use-outline name="river"/>
</rule>
<rule e="way" k="*" v="*" zoom-max="12">
<use-line name="water" width="1.0" fixed="true" fade="9"/>
</rule>
</rule>
<rule e="way" k="waterway" v="riverbank|dock">
<use-area name="water"/>
<use-line name="water" width="1.0" fixed="true"/>
</rule>
<rule e="way" k="waterway" v="river" closed="yes">
<use-area name="water"/>
<use-line name="water" width="1.0" fixed="true"/>
</rule>
<rule e="way" k="waterway" v="weir">
<line stroke="#000044" width="0.375" cap="butt" />
</rule>
<rule e="way" k="waterway" v="dam" zoom-min="12">
<!-- sehr seltsam was in deutschland so als Damm gekenzeichnet wird.. -->
<line stroke="#ababab" width="1.2" cap="butt" fixed="true" />
</rule>
<rule e="way" k="lock" v="yes|true">
<line stroke="#f8f8f8" width="1.5" cap="butt" />
</rule>
</rule>
<rule e="way" k="natural" v="water">
<use-area name="water"/>
<use-line name="water:outline" width="0.5" fixed="true"/>
</rule>
<!-- sport -->
<!-- <rule e="way" k="sport" v="*"> <rule e="way" k="sport" v="soccer"
zoom-min="17"> <rule e="way" k="sport" v="swimming|canoe|diving|scuba_diving">
<area fill="#b4cbdc" stroke="#6060ff" width="0.2" /> </rule> <rule
e="way" k="sport" v="tennis"> <area fill="#d18a6a" stroke="#b36c4c" width="0.2"
/> </rule> </rule> -->
<!-- tourism areas -->
<rule e="way" k="tourism" v="*">
<!-- <rule e="way" k="tourism" v="attraction"> <area fill="#f2caea" /> </rule> -->
<rule e="way" k="tourism" v="zoo|picnic_site|caravan_site|camp_site">
<area fill="#d7e6b0" />
</rule>
</rule>
<!-- outline 0 -->
<style-outline name="0" stroke="#44000000" width="0.1" />
<!-- tunnel -->
<rule e="way" k="tunnel" v="yes|true" zoom-min="11">
<!-- highway tunnels -->
<rule e="way" k="highway" v="*">
<rule e="way" k="*" v="*" zoom-min="15">
<rule e="way" k="*" v="steps">
<use-line name="steps"/>
<use-outline name="0"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16">
<use-line name="footway:z16"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
<rule e="way" k="*" v="construction">
<use-line name="construction"/>
<use-outline name="0"/>
</rule>
<rule e="way" k="*" v="service">
<rule e="way" k="service" v="-|parking_aisle">
<use-line name="highway-service"/>
<use-outline name="0"/>
</rule>
</rule>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link">
<use-line name="trunk_link"/>
<use-outline name="0"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="*" zoom-min="13">
<rule e="way" k="*" v="byway|pedestrian">
<use-line name="pedestrian"/>
<use-outline name="0"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="residential|road|unclassified|living_street">
<use-line name="residential"/>
<use-outline name="0"/>
<use-text name="road"/>
</rule>
</rule>
<rule e="way" k="*" v="tertiary|secondary_link">
<use-line name="tertiary"/>
<use-outline name="0"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="secondary|primary_link">
<use-line name="secondary:z11"/>
<use-outline name="0"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="primary">
<use-line name="primary:z11"/>
<use-outline name="0"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="trunk">
<use-line name="trunk" blur="0.3"/>
<use-outline name="0"/>
<!-- <use-outline name="glow"/> -->
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="motorway">
<use-line name="highway:z11" blur="0.3"/>
<use-outline name="0"/>
<!-- <use-outline name="glow"/> -->
<use-text name="major-road"/>
</rule>
</rule>
<!-- railway tunnel -->
<rule e="way" k="railway" v="*">
<!-- <rule e="way" k="railway" v="tram|subway|light_rail|narrow_gauge">
<line stroke="#a0a0a0" width="0.8" cap="butt" fixed="true"/>
</rule> -->
<rule e="way" k="railway" v="rail">
<line stroke="#aaaaaa" width="0.9" cap="butt" fixed="true" />
</rule>
</rule>
</rule> <!-- end tunnel -->
<!-- platform cores -->
<rule e="way" k="highway|railway|public_transport" v="platform">
<rule e="way" k="*" v="*" closed="yes">
<area fill="#999999" />
</rule>
<rule e="way" k="*" v="*" closed="no">
<line stroke="#cccccc" width="0.3" />
</rule>
</rule>
<!-- runways areas -->
<rule e="way" k="aeroway" v="*">
<!-- <rule e="way" k="*" v="aerodrome" closed="yes">
<area fill="#050008" />
</rule>
<rule e="way" k="*" v="apron">
<area fill="#050008" />
</rule>-->
<!-- Airport passenger building -->
<rule e="way" k="*" v="terminal|hangar">
<use-area name="building" />
<use-line name="building" />
</rule>
</rule>
<!-- turning circles -->
<!-- <rule e="node" k="highway" v="turning_circle"> <circle r="1.5" scale-radius="true"
fill="#707070" />
</rule> -->
<!-- building -->
<rule e="way" k="building" v="*">
<rule e="way" k="*" v="*" zoom-min="15">
<use-area name="building" fade="15"/>
<use-line name="building" fade="15"/>
<!-- <line stroke="#c9c3c1" width="1.0" fixed="true" cap="butt" fade="15"/>
<area fill="#e9e6e3" fade="15" /> -->
</rule>
<!-- <rule e="way" k="*" v="*" zoom-min="17">
<caption k="name" font-style="bold" font-size="10" fill="#4040ff"
stroke="#ffffff" stroke-width="2.0" />
<caption k="addr:housenumber" font-style="bold" font-size="10" fill="#606060"
stroke="#ffffff" stroke-width="2.0" />
</rule> -->
</rule>
<!-- outline 1 - 4 -->
<style-outline name="glow3" stroke="#ddffffff" width="0.8" blur="0.5" fade="13"/>
<!-- > <style-outline name="glow" stroke="#ee909090" width="0.8" blur="0.5" fade="14"/>-->
<style-outline name="glow2" width="1.0" stroke="#ffffff" blur="1.0" fade="13"/>
<style-outline name="1" stroke="#dd000000" width="-0.3" fade="14"/>
<!-- <style-outline name="1" stroke="#404030"/> -->
<style-outline name="2" stroke="#c0c0c0" />
<style-outline name="primary" stroke="#7f7700" width="0.025"/>
<style-outline name="motorway" stroke="#805f2e" width="0.025"/>
<!-- highway -->
<rule e="way" k="highway" v="*">
<rule e="way" k="*" v="*" zoom-min="5" zoom-max="10">
<rule e="way" k="area" v="~|no|false">
<rule e="way" k="*" v="secondary|primary_link" zoom-min="9">
<line stroke="#ddf2df6d" width="1.8" cap="butt" fixed="true" fade="9"/>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link" zoom-min="8">
<line stroke="#ddfed6a3" width="1.8" cap="butt" fixed="true" fade="8"/>
</rule>
<rule e="way" k="*" v="primary" zoom-min="5">
<line stroke="#ddf2df6d" cap="butt" fixed="true" width="1.8" fade="5"/> <!-- stroke="#f2df6d" width="1.8" cap="butt" fixed="true" fade="5"/>-->
</rule>
<rule e="way" k="*" v="trunk" zoom-min="5">
<line stroke="#ddfed6a3" width="2.0" cap="butt" fixed="true" fade="5"/>
</rule>
<rule e="way" k="*" v="motorway">
<line stroke="#ddeec693" width="2.2" cap="butt" fixed="true" fade="5"/>
</rule>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="11">
<rule e="way" k="tunnel|bridge" v="~|no|false">
<!-- highway area -->
<rule e="way" k="area" v="yes|true">
<rule e="way" k="*" v="footway" zoom-min="15">
<area fill="#44ffffff" />
<line stroke="#888888" width="0.15" cap="butt" />
</rule>
<rule e="way" k="*" zoom-min="13" v="pedestrian|unclassified|residential|road|living_street">
<area fill="#44ffffff" />
<line stroke="#888888" width="1.0" fixed="true" cap="butt" />
</rule>
<!-- <rule e="way" k="*" v="path" zoom-min="14">
<area fill="#d0d0d0" />
</rule>-->
</rule>
<rule e="way" k="area" v="~|no|false">
<rule e="way" k="*" v="*" zoom-min="15">
<rule e="way" k="*" v="steps">
<use-line name="steps"/>
<use-outline name="2"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16" zoom-max="16">
<use-line name="footway:z16"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="17">
<use-line name="footway:z17"/>
<!-- <use-outline name="1"/> -->
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
<rule e="way" k="*" v="construction">
<use-line name="construction"/>
<use-outline name="1"/>
</rule>
<rule e="way" k="*" v="service">
<rule e="way" k="service" v="-|parking_aisle">
<use-line name="highway-service"/>
<use-outline name="1"/>
</rule>
<!-- <rule e="way" k="service" v="parking_aisle" zoom-min="16">
<use-line name="highway-service" width="-0.4"/>
<use-outline name="1"/>
</rule> -->
</rule>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link">
<use-line name="trunk_link"/>
<use-outline name="motorway"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="*" zoom-min="13">
<rule e="way" k="*" v="byway|pedestrian">
<use-line name="residential" width="-0.4"/>
<use-outline name="1"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="residential|road|unclassified|living_street">
<use-line name="residential"/>
<use-outline name="1"/>
<use-outline name="glow"/>
<use-text name="road"/>
</rule>
</rule>
<rule e="way" k="*" v="tertiary|secondary_link">
<use-line name="tertiary"/>
<use-outline name="1"/>
<use-outline name="glow"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="secondary|primary_link">
<!-- <line stroke="#fff939" width="1.6" /> -->
<use-line name="secondary:z11"/>
<use-outline name="primary"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="primary">
<use-line name="primary:z11"/>
<use-outline name="primary"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="trunk">
<use-line name="trunk"/>
<use-outline name="motorway"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="motorway">
<use-line name="highway:z11"/>
<use-outline name="motorway"/>
<use-text name="major-road"/>
</rule>
</rule> <!-- end area=~|no|false -->
</rule> <!-- end tunnel|bridge=~|no|false -->
<rule e="way" k="bridge" v="yes|true|viaduct|suspension">
<rule e="way" k="area" v="~|no|false">
<style-outline name="bridge" stroke="#aa202020" width="0.08"/>
<rule e="way" k="*" v="*" zoom-min="15">
<rule e="way" k="*" v="steps">
<use-line name="steps"/>
<use-outline name="bridge"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16" zoom-max="16">
<use-line name="footway:z16"/>
</rule>
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="17">
<use-line name="footway:z17" cap="butt"/>
<use-outline name="bridge"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
<rule e="way" k="*" v="construction">
<use-line name="construction" cap="square"/>
<use-outline name="bridge"/>
</rule>
<rule e="way" k="*" v="service">
<use-line name="highway-service" cap="square"/>
<use-outline name="bridge"/>
</rule>
</rule>
<rule e="way" k="*" v="*" zoom-min="13">
<rule e="way" k="*" v="byway|pedestrian">
<use-line name="pedestrian:bridge"/>
<use-outline name="bridge"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="residential|road|unclassified|living_street">
<use-line name="residential:bridge"/>
<use-outline name="bridge"/>
<use-text name="road"/>
</rule>
</rule>
<rule e="way" k="*" v="tertiary|secondary_link">
<use-line name="tertiary" cap="square"/>
<use-outline name="bridge"/>
<use-text name="road"/>
</rule>
<rule e="way" k="*" v="trunk_link|motorway_link">
<use-line name="trunk_link" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="secondary|primary_link">
<!-- <line stroke="#fff939" width="1.6" cap="butt" /> -->
<use-line name="secondary:z11" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="primary">
<use-line name="primary:z11" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="trunk">
<use-line name="trunk" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
<rule e="way" k="*" v="motorway">
<use-line name="highway:z11" cap="square"/>
<use-outline name="bridge"/>
<use-text name="major-road"/>
</rule>
</rule> <!-- end area=~|no|false -->
<rule e="way" k="area" v="yes|true">
<rule e="way" k="*" v="footway" zoom-min="15">
<area fill="#fefefe" />
<line stroke="#c0c0c0" width="0.15" cap="butt" />
</rule>
<rule e="way" k="*" zoom-min="13" v="pedestrian|service|unclassified|residential|road|living_street">
<area fill="#ffffff" />
<line stroke="#d0d0d0" width="1.0" fixed="true" cap="butt" />
</rule>
<!-- <rule e="way" k="*" v="path" zoom-min="14">
<area fill="#d0d0d0" />
</rule>-->
</rule> <!-- end area=yes|true -->
</rule> <!-- end bridge=yes -->
</rule> <!-- end zoom-min=11 -->
</rule> <!-- end highway -->
<!-- runways cores -->
<rule e="way" k="aeroway" v="*">
<rule e="way" k="*" v="runway">
<use-line name="aeroway:runway"/>
</rule>
<rule e="way" k="*" v="taxiway">
<use-line name="aeroway:runway" width="-0.8"/>
</rule>
</rule>
<!-- man_made features -->
<!-- <rule e="way" k="man_made" v="pier">
<rule e="way" k="*" v="*" closed="no">
<line stroke="#d0d0d0" width="0.4" cap="butt" />
<line stroke="#e4e4e4" width="0.3" cap="butt" />
</rule>
<rule e="way" k="*" v="*" closed="yes">
<area fill="#e4e4e4" stroke="#d0d0d0" stroke-width="0.05" />
</rule>
</rule> -->
<!-- barriers -->
<rule e="way" k="barrier" v="*">
<!-- <rule e="way" k="*" v="fence|wall|city_wall" zoom-min="15"> <line
stroke="#909090" width="0.1" cap="butt" /> </rule> -->
<rule e="way" k="*" v="retaining_wall" zoom-min="15">
<line stroke="#888888" width="0.1" cap="butt" />
</rule>
</rule>
<!-- non-physical routes -->
<!-- <rule e="way" k="route" v="ferry"> <line stroke="#707070" width="0.3"
stroke-dasharray="15,10" cap="butt" /> </rule> -->
<!-- aerial ways -->
<!-- <rule e="way" k="aerialway" v="*"> <line stroke="#202020" width="0.4"
cap="butt" /> <rule e="way" k="aerialway" v="cable_car"> <lineSymbol
src="jar:/org/mapsforge/android/maps/rendertheme/osmarender/symbols/cable_car.png"
/> </rule> <rule e="way" k="aerialway" v="chair_lift"> <lineSymbol src="jar:/org/mapsforge/android/maps/rendertheme/osmarender/symbols/chair_lift_2.png"
/> </rule> <rule e="way" k="aerialway" v="gondola"> <lineSymbol src="jar:/org/mapsforge/android/maps/rendertheme/osmarender/symbols/gondola.png"
/> </rule> <rule e="way" k="*" v="*" zoom-min="14"> <pathText k="name" font-style="bold"
font-size="10" fill="#606060" stroke="#ffffff" width="2.0" /> </rule>
</rule> -->
<!-- railway (no tunnel) -->
<rule e="way" k="railway" v="*" zoom-min="12">
<rule e="way" k="tunnel" v="~|false|no">
<rule e="way" k="railway" v="station">
<area fill="#aa000000" />
<line stroke="#cccccc" width="1.0" fixed="true"/>
</rule>
<!-- railway bridge casings -->
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="bridge" v="yes|true">
<rule e="way" k="railway" v="tram">
<line stroke="#777777" width="0.9" cap="butt"
fixed="true" />
</rule>
<rule e="way" k="railway" v="subway|light_rail|narrow_gauge">
<line stroke="#777777" width="0.9" cap="butt"
fixed="true" />
</rule>
<rule e="way" k="railway" v="rail">
<line stroke="#777777" width="0.9" cap="butt"
fixed="true" />
</rule>
</rule>
</rule>
<!-- railway casings and cores -->
<rule e="way" k="railway" v="tram" zoom-min="15">
<line stroke="#887766" width="1.0" fixed="true" />
</rule>
<rule e="way" k="railway" v="light_rail|subway|narrow_gauge" zoom-min="14">
<line stroke="#a0a0a0" width="0.9" cap="butt" fixed="true" />
</rule>
<rule e="way" k="railway" v="rail|turntable" >
<line stroke="#aaaaaa" width="1.0" cap="butt" fixed="true" fade="12"/>
</rule>
<!-- <rule e="way" k="railway" v="rail" zoom-max="14" zoom-min="13">
<line stroke="#8888aa" width="0.6" cap="butt"
fixed="true" />
</rule> -->
<!-- <rule e="way" k="railway" v="rail" zoom-max="13" zoom-min="11">
<line stroke="#bbbbcc" width="0.8" cap="butt" fixed="true" />
</rule> -->
<!-- whatever railway:spur means ... -->
<rule e="way" k="railway" v="disused|spur|abandoned|preserved" >
<line stroke="#cccccc" width="0.8" cap="butt" fixed="true" fade="12"/>
</rule>
</rule>
</rule>
<!-- non-physical boundaries -->
<!-- <rule e="way" k="boundary" v="*"> <rule e="way" k="boundary" v="national_park">
<line stroke="#4ef94b" width="0.25" stroke-dasharray="15, 5, 5, 5"
/> -->
<!--<rule e="way" k="boundary" v="administrative"> -->
<rule e="way" k="admin_level" v="*">
<!-- <rule e="way" k="admin_level" v="11"> <line stroke="#f9574b" width="0.1"
fixed="true" cap="butt" /> </rule> <rule e="way" k="admin_level"
v="10"> <line stroke="#f9574b" width="0.1" fixed="true" cap="butt"
/> </rule> <rule e="way" k="admin_level" v="9"> <line stroke="#f9574b" width="0.1"
fixed="true" cap="butt" /> </rule> <rule e="way" k="admin_level"
v="8"> <line stroke="#f9574b" width="0.3" fixed="true" cap="butt"
/> </rule> <rule e="way" k="admin_level" v="7"> <line stroke="#f9574b" width="0.1"
fixed="true" cap="butt" /> </rule> <rule e="way" k="admin_level"
v="6"> <line stroke="#f9574b" width="0.15" fixed="true" cap="butt"
/> </rule> <rule e="way" k="admin_level" v="5"> <line stroke="#f9574b" width="0.15"
fixed="true" cap="butt" /> </rule> -->
<rule e="way" k="admin_level" v="4">
<line stroke="#8f80dd" width="0.9" fixed="true" cap="butt" />
</rule>
<rule e="way" k="admin_level" v="3">
<line stroke="#0000ff" width="1.0" fixed="true" cap="butt" />
</rule>
<rule e="way" k="admin_level" v="2">
<line stroke="#dddddd" width="1.0" fixed="true" cap="butt" blur="0.3"/>
</rule>
<rule e="way" k="admin_level" v="1">
<line stroke="#ff0000" width="0.95" fixed="true" cap="butt" />
</rule>
</rule>
<!-- </rule> -->
<!-- historic -->
<!-- <rule e="way" k="historic" v="ruins" zoom-min="17">
<caption k="name" font-style="bold" font-size="10" fill="#4040ff" stroke="#ffffff" stroke-width="2.0" />
</rule> -->
<!-- place -->
<rule e="way" k="place" v="locality" zoom-min="17">
<caption k="name" font-style="bold" font-size="10" fill="#000000" stroke="#ffffff" stroke-width="2.0" />
</rule>
<rule e="way" k="debug" v="area">
<line stroke="#ff0000" width="1.2" fixed="true" cap="butt" />
<area fill="#880000ff"/>
<caption k="name" font-size="15" fill="#ff0000" stroke="#444444" stroke-width="2.0"/>
</rule>
<rule e="way" k="debug" v="way">
<line stroke="#00ffff" width="1.5" fixed="true" cap="butt" />
<caption k="name" font-size="15" fill="#00ffff" stroke="#444444" stroke-width="2.0"/>
</rule>
<rule e="way" k="debug" v="box">
<line stroke="#dedeae" width="1.5" fixed="true" cap="butt" />
</rule>
</rule>
<rule e="node" k="*" v="*">
<!-- barrier -->
<rule e="node" k="barrier" v="bollard">
<circle r="1.5" fill="#909090" />
</rule>
<rule e="node" k="debug" v="*" >
<caption k="name" font-size="16" fill="#fefece"/>
</rule>
<!-- highway -->
<!-- <rule e="node" k="highway" v="*"> <rule e="node" k="highway" v="turning_circle">
<circle r="1.4" scale-radius="true" fill="#ffffff" /> </rule> </rule> -->
<!-- historic -->
<!-- <rule e="node" k="historic" v="*"> <circle r="3" fill="#4040ff" stroke="#606060"
width="1.5" /> <rule e="node" k="*" v="*" zoom-min="17"> <caption
k="name" dy="-10" font-style="bold" font-size="10" fill="#4040ff" stroke="#ffffff"
width="2.0" /> </rule> </rule> -->
<!-- house numbers -->
<!-- <rule e="node" k="addr:housenumber" v="*" zoom-min="18"> <caption
k="addr:housenumber" font-style="bold" font-size="10" fill="#606060" stroke="#ffffff"
width="2.0" /> </rule> -->
<!-- place -->
<rule e="node" k="place" v="*">
<rule e="node" k="*" v="suburb|town|village">
<caption k="name" font-size="20" fill="#eeeeee"
stroke="#000020" stroke-width="4.0" />
</rule>
<rule e="node" k="*" v="island" zoom-min="10">
<caption k="name" font-style="bold" font-size="20" fill="#ffffff"
stroke="#ffffff" stroke-width="1.0" />
</rule>
<rule e="node" k="*" v="city">
<caption k="name" font-style="bold" font-size="22" fill="#ffffff"
stroke="#002020" stroke-width="4.0" />
</rule>
<rule e="node" k="*" v="country">
<caption k="name" font-size="22" fill="#ffffff"
stroke="#000000" stroke-width="2.0" />
</rule>
</rule>
<!-- railway -->
<rule e="node" k="railway" v="*">
<rule e="node" k="*" v="station" zoom-min="14">
<circle r="6" fill="#ec2d2d" stroke="#606060" width="1.5" />
<!-- <caption k="name" dy="-10" font-style="bold" font-size="13" fill="#ec2d2d"
stroke="#ffffff" stroke-width="2.0" /> -->
</rule>
<rule e="node" k="*" v="halt|tram_stop" zoom-min="17">
<circle r="4" fill="#ec2d2d" stroke="#606060" width="1.5" />
<!-- <caption k="name" dy="-15" font-style="bold" font-size="11" fill="#ec2d2d"
stroke="#ffffff" stroke-width="2.0" /> -->
</rule>
</rule>
</rule>
</rendertheme>

View File

@@ -0,0 +1,241 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://mapsforge.org/renderTheme" xmlns:tns="http://mapsforge.org/renderTheme"
elementFormDefault="qualified" xml:lang="en">
<!-- attribute types -->
<xs:simpleType name="cap">
<xs:restriction base="xs:string">
<xs:enumeration value="butt" />
<xs:enumeration value="round" />
<xs:enumeration value="square" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="closed">
<xs:restriction base="xs:string">
<xs:enumeration value="yes" />
<xs:enumeration value="no" />
<xs:enumeration value="any" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="color">
<xs:restriction base="xs:string">
<xs:pattern value="#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="elementList">
<xs:restriction base="xs:string">
<xs:enumeration value="node" />
<xs:enumeration value="way" />
<xs:enumeration value="any" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="fontFamily">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="default_bold" />
<xs:enumeration value="monospace" />
<xs:enumeration value="sans_serif" />
<xs:enumeration value="serif" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="fontStyle">
<xs:restriction base="xs:string">
<xs:enumeration value="bold" />
<xs:enumeration value="bold_italic" />
<xs:enumeration value="italic" />
<xs:enumeration value="normal" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="nonNegativeFloat">
<xs:restriction base="xs:float">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="src">
<xs:restriction base="xs:string">
<xs:pattern value="(jar|file)\:.+" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="strokeDasharray">
<xs:restriction base="xs:string">
<xs:pattern
value="([0-9]+(\.[0-9]+)? *, *[0-9]+(\.[0-9]+)? *, *)*[0-9]+(\.[0-9]+)? *, *[0-9]+(\.[0-9]+)?" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="textKey">
<xs:restriction base="xs:string">
<xs:enumeration value="ele" />
<xs:enumeration value="addr:housenumber" />
<xs:enumeration value="name" />
<xs:enumeration value="ref" />
</xs:restriction>
</xs:simpleType>
<!-- rendering instructions -->
<xs:complexType name="area">
<xs:attribute name="src" type="tns:src" use="optional" />
<xs:attribute name="fill" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="stroke" type="tns:color" u se="optional"
default="#00000000" />
<xs:attribute name="stroke-width" type="tns:nonNegativeFloat"
use="optional" default="0" />
<xs:attribute name="fade" type="xs:integer" use="optional"
default="-1" />
<xs:attribute name="blend" type="xs:integer" use="optional"
default="-1" />
<xs:attribute name="blend-fill" type="tns:color" use="optional"
default="#000000" />
</xs:complexType>
<xs:complexType name="caption">
<xs:attribute name="k" type="tns:textKey" use="required" />
<xs:attribute name="dy" type="xs:float" use="optional"
default="0" />
<xs:attribute name="font-family" type="tns:fontFamily"
use="optional" default="default" />
<xs:attribute name="font-style" type="tns:fontStyle" use="optional"
default="normal" />
<xs:attribute name="font-size" type="tns:nonNegativeFloat"
use="optional" default="0" />
<xs:attribute name="fill" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="stroke" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="stroke-width" type="tns:nonNegativeFloat"
use="optional" default="0" />
</xs:complexType>
<xs:complexType name="circle">
<xs:attribute name="r" type="tns:nonNegativeFloat" use="required" />
<xs:attribute name="scale-radius" type="xs:boolean" use="optional"
default="false" />
<xs:attribute name="fill" type="tns:color" use="optional"
default="#00000000" />
<xs:attribute name="stroke" type="tns:color" use="optional"
default="#00000000" />
<xs:attribute name="stroke-width" type="tns:nonNegativeFloat"
use="optional" default="0" />
</xs:complexType>
<xs:complexType name="line">
<xs:attribute name="src" type="tns:src" use="optional" />
<xs:attribute name="stroke" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="width" type="tns:nonNegativeFloat"
use="optional" default="0" />
<xs:attribute name="stroke-dasharray" type="tns:strokeDasharray"
use="optional" />
<xs:attribute name="cap" type="tns:cap" use="optional"
default="round" />
<xs:attribute name="outline" type="xs:integer" use="optional"
default="0" />
<xs:attribute name="fade" type="xs:integer" use="optional"
default="-1" />
<xs:attribute name="fixed" type="xs:boolean" use="optional"
default="false" />
</xs:complexType>
<xs:complexType name="outline">
<xs:attribute name="src" type="tns:src" use="optional" />
<xs:attribute name="stroke" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="stroke-width" type="tns:nonNegativeFloat"
use="optional" default="0" />
</xs:complexType>
<xs:complexType name="lineSymbol">
<xs:attribute name="src" type="tns:src" use="required" />
<xs:attribute name="align-center" type="xs:boolean" use="optional"
default="false" />
<xs:attribute name="repeat" type="xs:boolean" use="optional"
default="false" />
</xs:complexType>
<xs:complexType name="pathText">
<xs:attribute name="style" type="xs:string" use="optional" default="0"/>
<xs:attribute name="k" type="tns:textKey" use="required" />
<xs:attribute name="dy" type="xs:float" use="optional"
default="0" />
<xs:attribute name="font-family" type="tns:fontFamily"
use="optional" default="default" />
<xs:attribute name="font-style" type="tns:fontStyle" use="optional"
default="normal" />
<xs:attribute name="font-size" type="tns:nonNegativeFloat"
use="optional" default="0" />
<xs:attribute name="fill" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="stroke" type="tns:color" use="optional"
default="#000000" />
<xs:attribute name="stroke-width" type="tns:nonNegativeFloat"
use="optional" default="0" />
</xs:complexType>
<xs:complexType name="symbol">
<xs:attribute name="src" type="tns:src" use="required" />
</xs:complexType>
<!-- rule elements -->
<xs:complexType name="rule">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<!-- recursion to allow for nested rules -->
<xs:element name="rule" type="tns:rule" />
<xs:element name="area" type="tns:area" />
<xs:element name="caption" type="tns:caption" />
<xs:element name="circle" type="tns:circle" />
<xs:element name="line" type="tns:line" />
<xs:element name="outline" type="tns:outline" />
<xs:element name="lineSymbol" type="tns:lineSymbol" />
<xs:element name="pathText" type="tns:pathText" />
<xs:element name="stylePathText type="xs:string" />
<xs:element name="symbol" type="tns:symbol" />
</xs:choice>
<xs:attribute name="e" type="tns:elementList" use="required" />
<xs:attribute name="k" type="xs:string" use="required" />
<xs:attribute name="v" type="xs:string" use="required" />
<xs:attribute name="closed" type="tns:closed" use="optional"
default="any" />
<xs:attribute name="zoom-min" type="xs:unsignedByte" use="optional"
default="0" />
<xs:attribute name="zoom-max" type="xs:unsignedByte" use="optional"
default="127" />
</xs:complexType>
<!-- rendertheme element -->
<xs:complexType name="rendertheme">
<xs:sequence minOccurs="0" maxOccurds="256">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="style-pathtext" type="tns:pathText" />
<xs:element name="style-area" type="tns:area" />
</xs:choice>
</xs:sequence)
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="rule" type="tns:rule" />
</xs:sequence>
<xs:attribute name="version" type="xs:positiveInteger"
use="required" />
<xs:attribute name="map-background" type="tns:color" use="optional"
default="#ffffff" />
<xs:attribute name="base-stroke-width" type="tns:nonNegativeFloat"
use="optional" default="1" />
<xs:attribute name="base-text-size" type="tns:nonNegativeFloat"
use="optional" default="1" />
</xs:complexType>
<!-- root element -->
<xs:element name="rendertheme" type="tns:rendertheme" />
</xs:schema>

View File

@@ -0,0 +1,179 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Color;
/**
* Represents a closed polygon on the map.
*/
public final class Area extends RenderInstruction {
/**
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @param level
* the drawing level of this instruction.
* @return a new Area with the given rendering attributes.
*/
public static Area create(String elementName, Attributes attributes, int level) {
String src = null;
int fill = Color.BLACK;
int stroke = Color.TRANSPARENT;
float strokeWidth = 0;
int fade = -1;
int blend = -1;
int blendFill = Color.BLACK;
String style = null;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("name".equals(name))
style = value;
else if ("src".equals(name)) {
src = value;
} else if ("fill".equals(name)) {
fill = Color.parseColor(value);
} else if ("stroke".equals(name)) {
stroke = Color.parseColor(value);
} else if ("stroke-width".equals(name)) {
strokeWidth = Float.parseFloat(value);
} else if ("fade".equals(name)) {
fade = Integer.parseInt(value);
} else if ("blend".equals(name)) {
blend = Integer.parseInt(value);
} else if ("blend-fill".equals(name)) {
blendFill = Color.parseColor(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(strokeWidth);
return new Area(style, src, fill, stroke, strokeWidth, fade, level, blend,
blendFill);
}
private static void validate(float strokeWidth) {
if (strokeWidth < 0) {
throw new IllegalArgumentException("stroke-width must not be negative: "
+ strokeWidth);
}
}
private Area(String style, String src, int fill, int stroke, float strokeWidth,
int fade, int level, int blend, int blendFill) {
super();
this.style = style;
// if (fill == Color.TRANSPARENT) {
// paintFill = null;
// } else {
// paintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
// if (src != null) {
// Shader shader = BitmapUtils.createBitmapShader(src);
// paintFill.setShader(shader);
// }
// paintFill.setStyle(Style.FILL);
// paintFill.setColor(fill);
// paintFill.setStrokeCap(Cap.ROUND);
// }
//
// if (stroke == Color.TRANSPARENT) {
// paintOutline = null;
// } else {
// paintOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
// paintOutline.setStyle(Style.STROKE);
// paintOutline.setColor(stroke);
// paintOutline.setStrokeCap(Cap.ROUND);
// }
// if (stroke == Color.TRANSPARENT) {
// stroke = null;
// } else{
// stroke = new Line()
// }
color = new float[4];
color[3] = (fill >> 24 & 0xff) / 255.0f;
color[0] = (fill >> 16 & 0xff) / 255.0f * color[3];
color[1] = (fill >> 8 & 0xff) / 255.0f * color[3];
color[2] = (fill >> 0 & 0xff) / 255.0f * color[3];
if (blend > 0) {
blendColor = new float[4];
blendColor[3] = (blendFill >> 24 & 0xff) / 255.0f;
blendColor[0] = (blendFill >> 16 & 0xff) / 255.0f * blendColor[3];
blendColor[1] = (blendFill >> 8 & 0xff) / 255.0f * blendColor[3];
blendColor[2] = (blendFill >> 0 & 0xff) / 255.0f * blendColor[3];
} else {
blendColor = null;
}
this.blend = blend;
this.strokeWidth = strokeWidth;
this.fade = fade;
this.level = level;
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderArea(this, this.level);
}
// @Override
// public void scaleStrokeWidth(float scaleFactor) {
// // if (paintOutline != null) {
// // paintOutline.setStrokeWidth(strokeWidth * scaleFactor);
// // }
// }
public String style;
/**
*
*/
private final int level;
/**
*
*/
// public final Paint paintFill;
/**
*
*/
// public final Paint paintOutline;
/**
*
*/
public final float strokeWidth;
/**
*
*/
public final float color[];
/**
*
*/
public final int fade;
public final float blendColor[];
public final int blend;
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
public class AreaLevel extends RenderInstruction {
private final Area area;
private final int level;
public AreaLevel(Area area, int level) {
this.area = area;
this.level = level;
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderArea(this.area, level);
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Shader.TileMode;
final class BitmapUtils {
private static final String PREFIX_FILE = "file:";
private static final String PREFIX_JAR = "jar:";
private static InputStream createInputStream(String src) throws FileNotFoundException {
if (src.startsWith(PREFIX_JAR)) {
String name = src.substring(PREFIX_JAR.length());
InputStream inputStream = Thread.currentThread().getClass().getResourceAsStream(name);
if (inputStream == null) {
throw new FileNotFoundException("resource not found: " + src);
}
return inputStream;
} else if (src.startsWith(PREFIX_FILE)) {
File file = new File(src.substring(PREFIX_FILE.length()));
if (!file.exists()) {
throw new IllegalArgumentException("file does not exist: " + src);
} else if (!file.isFile()) {
throw new IllegalArgumentException("not a file: " + src);
} else if (!file.canRead()) {
throw new IllegalArgumentException("cannot read file: " + src);
}
return new FileInputStream(file);
}
throw new IllegalArgumentException("invalid bitmap source: " + src);
}
static Bitmap createBitmap(String src) throws IOException {
if (src == null || src.length() == 0) {
// no image source defined
return null;
}
InputStream inputStream = createInputStream(src);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
inputStream.close();
return bitmap;
}
static BitmapShader createBitmapShader(String src) throws IOException {
Bitmap bitmap = BitmapUtils.createBitmap(src);
if (bitmap == null) {
return null;
}
return new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT);
}
private BitmapUtils() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import java.util.Locale;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.FontMetrics;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.util.FloatMath;
/**
* Represents a text label on the map.
*/
public final class Caption extends RenderInstruction {
/**
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @return a new Caption with the given rendering attributes.
*/
public static Caption create(String elementName, Attributes attributes) {
String textKey = null;
float dy = 0;
FontFamily fontFamily = FontFamily.DEFAULT;
FontStyle fontStyle = FontStyle.NORMAL;
float fontSize = 0;
int fill = Color.BLACK;
int stroke = Color.BLACK;
float strokeWidth = 0;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("k".equals(name)) {
textKey = TextKey.getInstance(value);
} else if ("dy".equals(name)) {
dy = Float.parseFloat(value);
} else if ("font-family".equals(name)) {
fontFamily = FontFamily.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("font-style".equals(name)) {
fontStyle = FontStyle.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("font-size".equals(name)) {
fontSize = Float.parseFloat(value);
} else if ("fill".equals(name)) {
fill = Color.parseColor(value);
} else if ("stroke".equals(name)) {
stroke = Color.parseColor(value);
} else if ("stroke-width".equals(name)) {
strokeWidth = Float.parseFloat(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, textKey, fontSize, strokeWidth);
Typeface typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
return new Caption(textKey, dy, typeface, fontSize, fill, stroke, strokeWidth);
}
private static void validate(String elementName, String textKey, float fontSize,
float strokeWidth) {
if (textKey == null) {
throw new IllegalArgumentException("missing attribute k for element: "
+ elementName);
} else if (fontSize < 0) {
throw new IllegalArgumentException("font-size must not be negative: "
+ fontSize);
} else if (strokeWidth < 0) {
throw new IllegalArgumentException("stroke-width must not be negative: "
+ strokeWidth);
}
}
public final float dy;
public float fontSize;
public final Paint paint;
public final Paint stroke;
public final String textKey;
public final float fontHeight;
public final float fontDescent;
private Caption(String textKey, float dy, Typeface typeface, float fontSize,
int fillColor, int strokeColor, float strokeWidth) {
super();
this.textKey = textKey.intern();
this.dy = dy;
this.fontSize = fontSize;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextAlign(Align.CENTER);
paint.setTypeface(typeface);
paint.setColor(fillColor);
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
stroke.setStyle(Style.STROKE);
stroke.setTextAlign(Align.CENTER);
stroke.setTypeface(typeface);
stroke.setColor(strokeColor);
stroke.setStrokeWidth(strokeWidth);
paint.setTextSize(fontSize);
stroke.setTextSize(fontSize);
FontMetrics fm = paint.getFontMetrics();
fontHeight = FloatMath.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
fontDescent = FloatMath.ceil(Math.abs(fm.descent));
}
@Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderPointOfInterestCaption(this);
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderAreaCaption(this);
}
@Override
public void scaleTextSize(float scaleFactor) {
paint.setTextSize(fontSize * scaleFactor);
stroke.setTextSize(fontSize * scaleFactor);
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
/**
* Represents a round area on the map.
*/
public final class Circle extends RenderInstruction {
/**
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @param level
* the drawing level of this instruction.
* @return a new Circle with the given rendering attributes.
*/
public static Circle create(String elementName, Attributes attributes, int level) {
Float radius = null;
boolean scaleRadius = false;
int fill = Color.TRANSPARENT;
int stroke = Color.TRANSPARENT;
float strokeWidth = 0;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("r".equals(name)) {
radius = Float.valueOf(Float.parseFloat(value));
} else if ("scale-radius".equals(name)) {
scaleRadius = Boolean.parseBoolean(value);
} else if ("fill".equals(name)) {
fill = Color.parseColor(value);
} else if ("stroke".equals(name)) {
stroke = Color.parseColor(value);
} else if ("stroke-width".equals(name)) {
strokeWidth = Float.parseFloat(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, radius, strokeWidth);
return new Circle(radius, scaleRadius, fill, stroke, strokeWidth, level);
}
private static void validate(String elementName, Float radius, float strokeWidth) {
if (radius == null) {
throw new IllegalArgumentException("missing attribute r for element: "
+ elementName);
} else if (radius.floatValue() < 0) {
throw new IllegalArgumentException("radius must not be negative: " + radius);
} else if (strokeWidth < 0) {
throw new IllegalArgumentException("stroke-width must not be negative: "
+ strokeWidth);
}
}
private final Paint mFill;
private final int mLevel;
private final Paint mOutline;
private final float mRadius;
private float mRenderRadius;
private final boolean mScaleRadius;
private final float mStrokeWidth;
private Circle(Float radius, boolean scaleRadius, int fill, int stroke,
float strokeWidth, int level) {
super();
mRadius = radius.floatValue();
mScaleRadius = scaleRadius;
if (fill == Color.TRANSPARENT) {
mFill = null;
} else {
mFill = new Paint(Paint.ANTI_ALIAS_FLAG);
mFill.setStyle(Style.FILL);
mFill.setColor(fill);
}
if (stroke == Color.TRANSPARENT) {
mOutline = null;
} else {
mOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
mOutline.setStyle(Style.STROKE);
mOutline.setColor(stroke);
}
mStrokeWidth = strokeWidth;
mLevel = level;
if (!mScaleRadius) {
mRenderRadius = mRadius;
if (mOutline != null) {
mOutline.setStrokeWidth(mStrokeWidth);
}
}
}
@Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
if (mOutline != null) {
renderCallback.renderPointOfInterestCircle(mRenderRadius, mOutline, mLevel);
}
if (mFill != null) {
renderCallback.renderPointOfInterestCircle(mRenderRadius, mFill, mLevel);
}
}
@Override
public void scaleStrokeWidth(float scaleFactor) {
if (mScaleRadius) {
mRenderRadius = mRadius * scaleFactor;
if (mOutline != null) {
mOutline.setStrokeWidth(mStrokeWidth * scaleFactor);
}
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import android.graphics.Typeface;
enum FontFamily {
DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF;
/**
* @return the typeface object of this FontFamily.
* @see <a href="http://developer.android.com/reference/android/graphics/Typeface.html">Typeface</a>
*/
Typeface toTypeface() {
switch (this) {
case DEFAULT:
return Typeface.DEFAULT;
case DEFAULT_BOLD:
return Typeface.DEFAULT_BOLD;
case MONOSPACE:
return Typeface.MONOSPACE;
case SANS_SERIF:
return Typeface.SANS_SERIF;
case SERIF:
return Typeface.SERIF;
}
throw new IllegalArgumentException("unknown enum value: " + this);
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
enum FontStyle {
BOLD, BOLD_ITALIC, ITALIC, NORMAL;
/**
* @return the constant int value of this FontStyle.
* @see <a href="http://developer.android.com/reference/android/graphics/Typeface.html">Typeface</a>
*/
int toInt() {
switch (this) {
case BOLD:
return 1;
case BOLD_ITALIC:
return 3;
case ITALIC:
return 2;
case NORMAL:
return 0;
}
throw new IllegalArgumentException("unknown enum value: " + this);
}
}

View File

@@ -0,0 +1,238 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import java.util.Locale;
import java.util.regex.Pattern;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Color;
import android.graphics.Paint.Cap;
/**
* Represents a polyline on the map.
*/
public final class Line extends RenderInstruction {
private static final Pattern SPLIT_PATTERN = Pattern.compile(",");
/**
* @param line
* ...
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @param level
* the drawing level of this instruction.
* @param isOutline
* ...
* @return a new Line with the given rendering attributes.
*/
public static Line create(Line line, String elementName, Attributes attributes,
int level, boolean isOutline) {
String src = null;
int stroke = Color.BLACK;
float strokeWidth = 0;
float[] strokeDasharray = null;
Cap strokeLinecap = Cap.ROUND;
int fade = -1;
boolean fixed = false;
String style = null;
float blur = 0;
if (line != null) {
fixed = line.fixed;
fade = line.fade;
strokeLinecap = line.cap;
blur = line.blur;
}
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("name".equals(name))
style = value;
else if ("src".equals(name)) {
src = value;
} else if ("stroke".equals(name)) {
stroke = Color.parseColor(value);
} else if ("width".equals(name)) {
strokeWidth = Float.parseFloat(value);
} else if ("stroke-dasharray".equals(name)) {
strokeDasharray = parseFloatArray(value);
} else if ("cap".equals(name)) {
strokeLinecap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("fade".equals(name)) {
fade = Integer.parseInt(value);
} else if ("fixed".equals(name)) {
fixed = Boolean.parseBoolean(value);
} else if ("blur".equals(name)) {
blur = Float.parseFloat(value);
} else if ("from".equals(name)) {
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
if (line != null) {
strokeWidth = line.width + strokeWidth;
if (strokeWidth <= 0)
strokeWidth = 1;
return new Line(line, style, src, stroke, strokeWidth, strokeDasharray,
strokeLinecap, level, fixed, fade, blur, isOutline);
}
if (!isOutline)
validate(strokeWidth);
return new Line(style, src, stroke, strokeWidth, strokeDasharray, strokeLinecap,
level, fixed, fade, blur, isOutline);
}
private static void validate(float strokeWidth) {
if (strokeWidth < 0) {
throw new IllegalArgumentException("width must not be negative: "
+ strokeWidth);
}
}
static float[] parseFloatArray(String dashString) {
String[] dashEntries = SPLIT_PATTERN.split(dashString);
float[] dashIntervals = new float[dashEntries.length];
for (int i = 0; i < dashEntries.length; ++i) {
dashIntervals[i] = Float.parseFloat(dashEntries[i]);
}
return dashIntervals;
}
/**
*
*/
private final int level;
/**
*
*/
// public final Paint paint;
/**
*
*/
public final float width;
/**
*
*/
public final boolean round;
/**
*
*/
public final float color[];
/**
*
*/
public final boolean outline;
/**
*
*/
public final boolean fixed;
public final int fade;
public final String style;
public final Cap cap;
public final float blur;
private Line(String style, String src, int stroke, float strokeWidth,
float[] strokeDasharray, Cap strokeLinecap, int level, boolean fixed,
int fade, float blur, boolean isOutline) {
super();
this.style = style;
// paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//
// if (src != null) {
// Shader shader = BitmapUtils.createBitmapShader(src);
// paint.setShader(shader);
// }
//
// paint.setStyle(Style.STROKE);
// paint.setColor(stroke);
// if (strokeDasharray != null) {
// paint.setPathEffect(new DashPathEffect(strokeDasharray, 0));
// }
// paint.setStrokeCap(strokeLinecap);
round = (strokeLinecap == Cap.ROUND);
this.cap = strokeLinecap;
color = new float[4];
color[3] = (stroke >> 24 & 0xff) / 255.0f;
color[0] = (stroke >> 16 & 0xff) / 255.0f * color[3];
color[1] = (stroke >> 8 & 0xff) / 255.0f * color[3];
color[2] = (stroke >> 0 & 0xff) / 255.0f * color[3];
this.width = strokeWidth;
this.level = level;
this.outline = isOutline;
this.fixed = fixed;
this.blur = blur;
this.fade = fade;
}
private Line(Line line, String style, String src, int stroke, float strokeWidth,
float[] strokeDasharray, Cap strokeLinecap, int level, boolean fixed,
int fade, float blur, boolean isOutline) {
super();
this.style = style;
round = (strokeLinecap == Cap.ROUND);
color = line.color;
this.width = strokeWidth;
this.level = level;
this.outline = isOutline;
this.fixed = fixed;
this.fade = fade;
this.cap = strokeLinecap;
this.blur = blur;
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
// renderCallback.renderWay(mPaint, mLevel, mColor, mStrokeWidth, mRound, mOutline);
renderCallback.renderWay(this, level);
}
// @Override
// public void scaleStrokeWidth(float scaleFactor) {
// paint.setStrokeWidth(strokeWidth * scaleFactor);
// }
public int getLevel() {
return this.level;
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import java.io.IOException;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Bitmap;
/**
* Represents an icon along a polyline on the map.
*/
public final class LineSymbol extends RenderInstruction {
/**
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @return a new LineSymbol with the given rendering attributes.
* @throws IOException
* if an I/O error occurs while reading a resource.
*/
public static LineSymbol create(String elementName, Attributes attributes)
throws IOException {
String src = null;
boolean alignCenter = false;
boolean repeat = false;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("src".equals(name)) {
src = value;
} else if ("align-center".equals(name)) {
alignCenter = Boolean.parseBoolean(value);
} else if ("repeat".equals(name)) {
repeat = Boolean.parseBoolean(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, src);
return new LineSymbol(src, alignCenter, repeat);
}
private static void validate(String elementName, String src) {
if (src == null) {
throw new IllegalArgumentException("missing attribute src for element: "
+ elementName);
}
}
private final boolean mAlignCenter;
private final Bitmap mBitmap;
private final boolean mRepeat;
private LineSymbol(String src, boolean alignCenter, boolean repeat)
throws IOException {
super();
mBitmap = BitmapUtils.createBitmap(src);
mAlignCenter = alignCenter;
mRepeat = repeat;
}
@Override
public void destroy() {
mBitmap.recycle();
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderWaySymbol(mBitmap, mAlignCenter, mRepeat);
}
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import java.util.Locale;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.FontMetrics;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.util.FloatMath;
/**
* Represents a text along a polyline on the map.
*/
public final class PathText extends RenderInstruction {
/**
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @return a new PathText with the given rendering attributes.
*/
public static PathText create(String elementName, Attributes attributes) {
String textKey = null;
FontFamily fontFamily = FontFamily.DEFAULT;
FontStyle fontStyle = FontStyle.NORMAL;
float fontSize = 0;
int fill = Color.BLACK;
int stroke = Color.BLACK;
float strokeWidth = 0;
String style = null;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("name".equals(name))
style = value;
else if ("k".equals(name)) {
textKey = TextKey.getInstance(value);
} else if ("font-family".equals(name)) {
fontFamily = FontFamily.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("font-style".equals(name)) {
fontStyle = FontStyle.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("font-size".equals(name)) {
fontSize = Float.parseFloat(value);
} else if ("fill".equals(name)) {
fill = Color.parseColor(value);
} else if ("stroke".equals(name)) {
stroke = Color.parseColor(value);
} else if ("stroke-width".equals(name)) {
strokeWidth = Float.parseFloat(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, textKey, fontSize, strokeWidth);
Typeface typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
return new PathText(style, textKey, typeface, fontSize, fill, stroke, strokeWidth);
}
private static void validate(String elementName, String textKey, float fontSize,
float strokeWidth) {
if (textKey == null) {
throw new IllegalArgumentException("missing attribute k for element: "
+ elementName);
} else if (fontSize < 0) {
throw new IllegalArgumentException("font-size must not be negative: "
+ fontSize);
} else if (strokeWidth < 0) {
throw new IllegalArgumentException("stroke-width must not be negative: "
+ strokeWidth);
}
}
public final float fontSize;
public final Paint paint;
public Paint stroke;
public String textKey;
public final float fontHeight;
public final float fontDescent;
public String style;
private PathText(String style, String textKey, Typeface typeface, float fontSize,
int fill, int outline, float strokeWidth) {
super();
this.style = style;
this.textKey = textKey;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextAlign(Align.CENTER);
paint.setTypeface(typeface);
paint.setColor(fill);
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
stroke.setStyle(Style.STROKE);
stroke.setTextAlign(Align.CENTER);
stroke.setTypeface(typeface);
stroke.setColor(outline);
stroke.setStrokeWidth(strokeWidth);
this.fontSize = fontSize;
paint.setTextSize(fontSize);
stroke.setTextSize(fontSize);
FontMetrics fm = paint.getFontMetrics();
fontHeight = FloatMath.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
fontDescent = FloatMath.ceil(Math.abs(fm.descent));
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderWayText(this);
}
@Override
public void scaleTextSize(float scaleFactor) {
paint.setTextSize(fontSize * scaleFactor);
stroke.setTextSize(fontSize * scaleFactor);
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
/**
* A RenderInstruction is a basic graphical primitive to draw a map.
*/
public abstract class RenderInstruction {
/**
* Destroys this RenderInstruction and cleans up all its internal resources.
*/
public void destroy() {
}
/**
* @param renderCallback
* a reference to the receiver of all render callbacks.
* @param tags
* the tags of the node.
*/
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
}
/**
* @param renderCallback
* a reference to the receiver of all render callbacks.
* @param tags
* the tags of the way.
*/
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
}
/**
* Scales the stroke width of this RenderInstruction by the given factor.
*
* @param scaleFactor
* the factor by which the stroke width should be scaled.
*/
public void scaleStrokeWidth(float scaleFactor) {
}
/**
* Scales the text size of this RenderInstruction by the given factor.
*
* @param scaleFactor
* the factor by which the text size should be scaled.
*/
public void scaleTextSize(float scaleFactor) {
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import java.io.IOException;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes;
import android.graphics.Bitmap;
/**
* Represents an icon on the map.
*/
public final class Symbol extends RenderInstruction {
/**
* @param elementName
* the name of the XML element.
* @param attributes
* the attributes of the XML element.
* @return a new Symbol with the given rendering attributes.
* @throws IOException
* if an I/O error occurs while reading a resource.
*/
public static Symbol create(String elementName, Attributes attributes)
throws IOException {
String src = null;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
if ("src".equals(name)) {
src = value;
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
}
validate(elementName, src);
return new Symbol(src);
}
private static void validate(String elementName, String src) {
if (src == null) {
throw new IllegalArgumentException("missing attribute src for element: "
+ elementName);
}
}
private final Bitmap mBitmap;
private Symbol(String src) throws IOException {
super();
mBitmap = BitmapUtils.createBitmap(src);
}
@Override
public void destroy() {
mBitmap.recycle();
}
@Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderPointOfInterestSymbol(mBitmap);
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderAreaSymbol(mBitmap);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
final class TextKey {
static String getInstance(String key) {
if (Tag.TAG_KEY_ELE.equals(key)) {
return Tag.TAG_KEY_ELE;
} else if (Tag.TAG_KEY_HOUSE_NUMBER.equals(key)) {
return Tag.TAG_KEY_HOUSE_NUMBER;
} else if (Tag.TAG_KEY_NAME.equals(key)) {
return Tag.TAG_KEY_NAME;
} else if (Tag.TAG_KEY_REF.equals(key)) {
return Tag.TAG_KEY_REF;
} else {
throw new IllegalArgumentException("invalid key: " + key);
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2012 Hannes Janetzek
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class Compass {
private final SensorEventListener mListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0];
if (mMapView != null) {
mMapView.getMapPosition().setRotation(mAngle);
mMapView.redrawTiles();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
/* package */float mAngle = 0;
/* package */MapView mMapView;
private SensorManager mSensorManager;
private Sensor mSensor;
public Compass(MapActivity mapActivity, MapView mapView) {
mMapView = mapView;
mSensorManager = (SensorManager) mapActivity
.getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
void enable() {
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_GAME);
}
void disable() {
mSensorManager.unregisterListener(mListener);
mMapView.getMapPosition().setRotation(0);
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
/**
* A simple DTO to stores flags for debugging rendered map tiles.
*/
public class DebugSettings {
/**
* True if drawing of tile coordinates is enabled, false otherwise.
*/
public final boolean mDrawTileCoordinates;
/**
* True if drawing of tile frames is enabled, false otherwise.
*/
public final boolean mDrawTileFrames;
public final boolean mDrawUnmatchted;
/**
* True if highlighting of water tiles is enabled, false otherwise.
*/
public final boolean mDisablePolygons;
/**
* @param drawTileCoordinates
* if drawing of tile coordinates is enabled.
* @param drawTileFrames
* if drawing of tile frames is enabled.
* @param disablePolygons
* if highlighting of water tiles is enabled.
* @param drawUnmatched
* ...
*/
public DebugSettings(boolean drawTileCoordinates, boolean drawTileFrames,
boolean disablePolygons, boolean drawUnmatched) {
mDrawTileCoordinates = drawTileCoordinates;
mDrawTileFrames = drawTileFrames;
mDrawUnmatchted = drawUnmatched;
mDisablePolygons = disablePolygons;
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2012 Hannes Janetzek
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import org.oscim.theme.RenderTheme;
import org.oscim.view.mapgenerator.IMapGenerator;
import org.oscim.view.mapgenerator.JobTile;
import android.opengl.GLSurfaceView;
/**
*
*/
public interface IMapRenderer extends GLSurfaceView.Renderer {
/**
* @param tile
* Tile data ready for rendering
* @return true
*/
public boolean passTile(JobTile tile);
/**
* called by MapView on position and map changes
*
* @param clear
* recreate all tiles (i.e. on theme change)
*/
public void updateMap(boolean clear);
/**
* @return new MapGenerator Instance for this Renderer
*/
public IMapGenerator createMapGenerator();
/**
* @param t
* the theme
*/
public void setRenderTheme(RenderTheme t);
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import java.io.FileNotFoundException;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.theme.InternalRenderTheme;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
/**
* MapActivity is the abstract base class which must be extended in order to use a {@link MapView}. There are no
* abstract methods in this implementation which subclasses need to override and no API key or registration is required.
* <p>
* A subclass may create a MapView either via one of the MapView constructors or by inflating an XML layout file. It is
* possible to use more than one MapView at the same time.
* <p>
* When the MapActivity is shut down, the current center position, zoom level and map file of the MapView are saved in a
* preferences file and restored in the next startup process.
*/
public abstract class MapActivity extends Activity {
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_MAP_FILE = "mapFile";
private static final String KEY_ZOOM_LEVEL = "zoomLevel";
private static final String PREFERENCES_FILE = "MapActivity";
private static final String KEY_THEME = "Theme";
private static boolean containsMapViewPosition(SharedPreferences sharedPreferences) {
return sharedPreferences.contains(KEY_LATITUDE)
&& sharedPreferences.contains(KEY_LONGITUDE)
&& sharedPreferences.contains(KEY_ZOOM_LEVEL);
}
private MapView mMapView;
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.destroy();
}
@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
Editor editor = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE).edit();
editor.clear();
// save the map position and zoom level
MapPosition mapPosition = mMapView.getMapPosition().getMapPosition();
if (mapPosition != null) {
GeoPoint geoPoint = new GeoPoint(mapPosition.lat, mapPosition.lon);
editor.putInt(KEY_LATITUDE, geoPoint.latitudeE6);
editor.putInt(KEY_LONGITUDE, geoPoint.longitudeE6);
editor.putInt(KEY_ZOOM_LEVEL, mapPosition.zoomLevel);
}
// if (mMapView.getMapFile() != null) {
// // save the map file
// editor.putString(KEY_MAP_FILE, mMapView.getMapFile());
// }
editor.putString(KEY_THEME, mMapView.getRenderTheme());
editor.commit();
}
@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}
/**
* This method is called once by each MapView during its setup process.
*
* @param mapView
* the calling MapView.
*/
final void registerMapView(MapView mapView) {
mMapView = mapView;
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
MODE_PRIVATE);
if (containsMapViewPosition(sharedPreferences)) {
//
// if (sharedPreferences.contains(KEY_MAP_FILE)) {
// // get and set the map file
// mapView.setMapFile(sharedPreferences.getString(KEY_MAP_FILE, null));
// }
// get and set the map position and zoom level
int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0);
int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 0);
int zoomLevel = sharedPreferences.getInt(KEY_ZOOM_LEVEL, -1);
GeoPoint geoPoint = new GeoPoint(latitudeE6, longitudeE6);
MapPosition mapPosition = new MapPosition(geoPoint, (byte) zoomLevel, 1);
mapView.setMapCenter(mapPosition);
}
String theme = sharedPreferences.getString(KEY_THEME,
InternalRenderTheme.OSMARENDER.name());
if (theme.startsWith("/")) {
try {
mapView.setRenderTheme(theme);
} catch (FileNotFoundException e) {
mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
}
} else {
mapView.setRenderTheme(InternalRenderTheme.valueOf(theme));
}
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import android.util.AttributeSet;
/**
* A factory for the internal MapRenderer implementations.
*/
public final class MapRendererFactory {
private static final String MAP_RENDERER_ATTRIBUTE_NAME = "mapRenderer";
/**
* @param mapView
* ...
* @param attributeSet
* A collection of attributes which includes the desired MapRenderer.
* @return a new MapRenderer instance.
*/
public static IMapRenderer createMapRenderer(MapView mapView,
AttributeSet attributeSet) {
String mapRendererName = attributeSet.getAttributeValue(null,
MAP_RENDERER_ATTRIBUTE_NAME);
if (mapRendererName == null) {
return new org.oscim.view.glrenderer.MapRenderer(mapView);
}
MapRenderers mapRendererInternal = MapRenderers.valueOf(mapRendererName);
return MapRendererFactory.createMapRenderer(mapView, mapRendererInternal);
}
public static MapRenderers getMapRenderer(AttributeSet attributeSet) {
String mapRendererName = attributeSet.getAttributeValue(null,
MAP_RENDERER_ATTRIBUTE_NAME);
if (mapRendererName == null) {
return MapRenderers.GL_RENDERER;
}
return MapRenderers.valueOf(mapRendererName);
}
/**
* @param mapView
* ...
* @param mapRendererInternal
* the internal MapRenderer implementation.
* @return a new MapRenderer instance.
*/
public static IMapRenderer createMapRenderer(MapView mapView,
MapRenderers mapRendererInternal) {
switch (mapRendererInternal) {
case SW_RENDERER:
return new org.oscim.view.swrenderer.MapRenderer(mapView);
case GL_RENDERER:
return new org.oscim.view.glrenderer.MapRenderer(mapView);
}
throw new IllegalArgumentException("unknown enum value: " + mapRendererInternal);
}
private MapRendererFactory() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
/**
* Enumeration of all internal MapGenerator implementations.
*/
public enum MapRenderers {
/**
* texture renderer.
*/
SW_RENDERER,
/**
* opengl renderer.
*/
GL_RENDERER
}

View File

@@ -0,0 +1,278 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import java.util.HashMap;
import java.util.Map;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
/**
* A MapScaleBar displays the ratio of a distance on the map to the corresponding distance on the ground.
*/
public class MapScaleBar {
/**
* Enumeration of all text fields.
*/
public enum TextField {
/**
* Unit symbol for one foot.
*/
FOOT,
/**
* Unit symbol for one kilometer.
*/
KILOMETER,
/**
* Unit symbol for one meter.
*/
METER,
/**
* Unit symbol for one mile.
*/
MILE;
}
private static final int BITMAP_HEIGHT = 50;
private static final int BITMAP_WIDTH = 150;
private static final double LATITUDE_REDRAW_THRESHOLD = 0.2;
private static final int MARGIN_BOTTOM = 5;
private static final int MARGIN_LEFT = 5;
private static final double METER_FOOT_RATIO = 0.3048;
private static final int ONE_KILOMETER = 1000;
private static final int ONE_MILE = 5280;
private static final Paint SCALE_BAR = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_BAR_STROKE = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final int[] SCALE_BAR_VALUES_IMPERIAL = { 26400000, 10560000, 5280000,
2640000, 1056000, 528000,
264000, 105600, 52800, 26400, 10560, 5280, 2000, 1000, 500, 200, 100, 50, 20,
10, 5, 2, 1 };
private static final int[] SCALE_BAR_VALUES_METRIC = { 10000000, 5000000, 2000000,
1000000, 500000, 200000, 100000,
50000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5, 2, 1 };
private static final Paint SCALE_TEXT = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_TEXT_STROKE = new Paint(Paint.ANTI_ALIAS_FLAG);
private static void configurePaints() {
SCALE_BAR.setStrokeWidth(2);
SCALE_BAR.setStrokeCap(Paint.Cap.SQUARE);
SCALE_BAR.setColor(Color.BLACK);
SCALE_BAR_STROKE.setStrokeWidth(5);
SCALE_BAR_STROKE.setStrokeCap(Paint.Cap.SQUARE);
SCALE_BAR_STROKE.setColor(Color.WHITE);
SCALE_TEXT.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
SCALE_TEXT.setTextSize(17);
SCALE_TEXT.setColor(Color.BLACK);
SCALE_TEXT_STROKE.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
SCALE_TEXT_STROKE.setStyle(Paint.Style.STROKE);
SCALE_TEXT_STROKE.setColor(Color.WHITE);
SCALE_TEXT_STROKE.setStrokeWidth(2);
SCALE_TEXT_STROKE.setTextSize(17);
}
private boolean mImperialUnits;
private MapPosition mMapPosition;
private final Bitmap mMapScaleBitmap;
private final Canvas mMapScaleCanvas;
private final MapView mMapView;
private boolean mRedrawNeeded;
private boolean mShowMapScaleBar;
private final Map<TextField, String> mTextFields;
MapScaleBar(MapView mapView) {
mMapView = mapView;
mMapScaleBitmap = Bitmap.createBitmap(BITMAP_WIDTH, BITMAP_HEIGHT,
Bitmap.Config.ARGB_4444);
mMapScaleCanvas = new Canvas(mMapScaleBitmap);
mTextFields = new HashMap<TextField, String>();
setDefaultTexts();
configurePaints();
}
/**
* @return true if imperial units are used, false otherwise.
*/
public boolean isImperialUnits() {
return mImperialUnits;
}
/**
* @return true if this map scale bar is visible, false otherwise.
*/
public boolean isShowMapScaleBar() {
return mShowMapScaleBar;
}
/**
* @param imperialUnits
* true if imperial units should be used rather than metric units.
*/
public void setImperialUnits(boolean imperialUnits) {
mImperialUnits = imperialUnits;
mRedrawNeeded = true;
}
/**
* @param showMapScaleBar
* true if the map scale bar should be drawn, false otherwise.
*/
public void setShowMapScaleBar(boolean showMapScaleBar) {
mShowMapScaleBar = showMapScaleBar;
}
/**
* Overrides the specified text field with the given string.
*
* @param textField
* the text field to override.
* @param value
* the new value of the text field.
*/
public void setText(TextField textField, String value) {
mTextFields.put(textField, value);
mRedrawNeeded = true;
}
private void drawScaleBar(float scaleBarLength, Paint paint) {
mMapScaleCanvas.drawLine(7, 25, scaleBarLength + 3, 25, paint);
mMapScaleCanvas.drawLine(5, 10, 5, 40, paint);
mMapScaleCanvas.drawLine(scaleBarLength + 5, 10, scaleBarLength + 5, 40, paint);
}
private void drawScaleText(int scaleValue, String unitSymbol, Paint paint) {
mMapScaleCanvas.drawText(scaleValue + unitSymbol, 12, 18, paint);
}
private boolean isRedrawNecessary() {
if (mRedrawNeeded || mMapPosition == null) {
return true;
}
MapPosition currentMapPosition = mMapView.getMapPosition().getMapPosition();
if (currentMapPosition.zoomLevel != mMapPosition.zoomLevel) {
return true;
}
double latitudeDiff = Math.abs(currentMapPosition.lat
- mMapPosition.lat);
if (latitudeDiff > LATITUDE_REDRAW_THRESHOLD) {
return true;
}
return false;
}
/**
* Redraws the map scale bitmap with the given parameters.
*
* @param scaleBarLength
* the length of the map scale bar in pixels.
* @param mapScaleValue
* the map scale value in meters.
*/
private void redrawMapScaleBitmap(float scaleBarLength, int mapScaleValue) {
mMapScaleBitmap.eraseColor(Color.TRANSPARENT);
// draw the scale bar
drawScaleBar(scaleBarLength, SCALE_BAR_STROKE);
drawScaleBar(scaleBarLength, SCALE_BAR);
int scaleValue;
String unitSymbol;
if (mImperialUnits) {
if (mapScaleValue < ONE_MILE) {
scaleValue = mapScaleValue;
unitSymbol = mTextFields.get(TextField.FOOT);
} else {
scaleValue = mapScaleValue / ONE_MILE;
unitSymbol = mTextFields.get(TextField.MILE);
}
} else {
if (mapScaleValue < ONE_KILOMETER) {
scaleValue = mapScaleValue;
unitSymbol = mTextFields.get(TextField.METER);
} else {
scaleValue = mapScaleValue / ONE_KILOMETER;
unitSymbol = mTextFields.get(TextField.KILOMETER);
}
}
// draw the scale text
drawScaleText(scaleValue, unitSymbol, SCALE_TEXT_STROKE);
drawScaleText(scaleValue, unitSymbol, SCALE_TEXT);
}
private void setDefaultTexts() {
mTextFields.put(TextField.FOOT, " ft");
mTextFields.put(TextField.MILE, " mi");
mTextFields.put(TextField.METER, " m");
mTextFields.put(TextField.KILOMETER, " km");
}
void destroy() {
mMapScaleBitmap.recycle();
}
void draw(Canvas canvas) {
int top = mMapView.getHeight() - BITMAP_HEIGHT - MARGIN_BOTTOM;
canvas.drawBitmap(mMapScaleBitmap, MARGIN_LEFT, top, null);
}
void redrawScaleBar() {
if (!isRedrawNecessary()) {
return;
}
mMapPosition = mMapView.getMapPosition().getMapPosition();
double groundResolution = MercatorProjection.calculateGroundResolution(
mMapPosition.lat,
mMapPosition.zoomLevel);
int[] scaleBarValues;
if (mImperialUnits) {
groundResolution = groundResolution / METER_FOOT_RATIO;
scaleBarValues = SCALE_BAR_VALUES_IMPERIAL;
} else {
scaleBarValues = SCALE_BAR_VALUES_METRIC;
}
float scaleBarLength = 0;
int mapScaleValue = 0;
for (int i = 0; i < scaleBarValues.length; ++i) {
mapScaleValue = scaleBarValues[i];
scaleBarLength = mapScaleValue / (float) groundResolution;
if (scaleBarLength < (BITMAP_WIDTH - 10)) {
break;
}
}
redrawMapScaleBitmap(scaleBarLength, mapScaleValue);
mRedrawNeeded = false;
}
}

View File

@@ -0,0 +1,676 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.MapDatabaseFactory;
import org.oscim.database.MapDatabases;
import org.oscim.database.MapInfo;
import org.oscim.database.OpenResult;
import org.oscim.theme.ExternalRenderTheme;
import org.oscim.theme.InternalRenderTheme;
import org.oscim.theme.RenderTheme;
import org.oscim.theme.RenderThemeHandler;
import org.oscim.theme.Theme;
import org.oscim.view.mapgenerator.IMapGenerator;
import org.oscim.view.mapgenerator.JobQueue;
import org.oscim.view.mapgenerator.JobTile;
import org.oscim.view.mapgenerator.MapWorker;
import org.oscim.view.utils.GlConfigChooser;
import org.xml.sax.SAXException;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
/**
* A MapView shows a map on the display of the device. It handles all user input and touch gestures to move and zoom the
* map.
*/
public class MapView extends GLSurfaceView {
final static String TAG = "MapView";
/**
* Default render theme of the MapView.
*/
public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER;
// private static final float DEFAULT_TEXT_SCALE = 1;
// private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
public final static boolean debugFrameTime = false;
public boolean enableRotation = false;
public boolean enableCompass = false;
private final MapViewPosition mMapViewPosition;
private final MapZoomControls mMapZoomControls;
private final Projection mProjection;
private final TouchHandler mTouchEventHandler;
private final Compass mCompass;
private IMapDatabase mMapDatabase;
private MapDatabases mMapDatabaseType;
private IMapRenderer mMapRenderer;
private JobQueue mJobQueue;
private MapWorker mMapWorkers[];
private int mNumMapWorkers = 4;
private DebugSettings debugSettings;
private String mRenderTheme;
/**
* @param context
* the enclosing MapActivity instance.
* @throws IllegalArgumentException
* if the context object is not an instance of {@link MapActivity} .
*/
public MapView(Context context) {
this(context, null, MapRenderers.GL_RENDERER, MapDatabases.MAP_READER);
}
/**
* @param context
* the enclosing MapActivity instance.
* @param attributeSet
* a set of attributes.
* @throws IllegalArgumentException
* if the context object is not an instance of {@link MapActivity} .
*/
public MapView(Context context, AttributeSet attributeSet) {
this(context, attributeSet,
MapRendererFactory.getMapRenderer(attributeSet),
MapDatabaseFactory.getMapDatabase(attributeSet));
}
private boolean mDebugDatabase = false;
private MapView(Context context, AttributeSet attributeSet,
MapRenderers mapGeneratorType, MapDatabases mapDatabaseType) {
super(context, attributeSet);
if (!(context instanceof MapActivity)) {
throw new IllegalArgumentException(
"context is not an instance of MapActivity");
}
Log.d(TAG, "create MapView: " + mapDatabaseType.name());
// TODO make this dpi dependent
Tile.TILE_SIZE = 400;
MapActivity mapActivity = (MapActivity) context;
debugSettings = new DebugSettings(false, false, false, false);
mMapDatabaseType = mapDatabaseType;
mMapViewPosition = new MapViewPosition(this);
mMapZoomControls = new MapZoomControls(mapActivity, this);
mProjection = new MapViewProjection(this);
mTouchEventHandler = new TouchHandler(mapActivity, this);
mCompass = new Compass(mapActivity, this);
mJobQueue = new JobQueue();
mMapRenderer = MapRendererFactory.createMapRenderer(this, mapGeneratorType);
mMapWorkers = new MapWorker[mNumMapWorkers];
for (int i = 0; i < mNumMapWorkers; i++) {
IMapDatabase mapDatabase;
if (mDebugDatabase) {
mapDatabase = MapDatabaseFactory
.createMapDatabase(MapDatabases.TEST_READER);
} else {
mapDatabase = MapDatabaseFactory.createMapDatabase(mapDatabaseType);
}
IMapGenerator mapGenerator = mMapRenderer.createMapGenerator();
mapGenerator.setMapDatabase(mapDatabase);
if (i == 0)
mMapDatabase = mapDatabase;
mMapWorkers[i] = new MapWorker(i, this, mapGenerator, mMapRenderer);
mMapWorkers[i].start();
}
mapActivity.registerMapView(this);
if (!mMapDatabase.isOpen()) {
Log.d(TAG, "open database with defaults");
setMapOptions(null);
}
if (!mMapViewPosition.isValid()) {
Log.d(TAG, "set default start position");
setMapCenter(getStartPosition());
}
setEGLConfigChooser(new GlConfigChooser());
setEGLContextClientVersion(2);
// setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
setRenderer(mMapRenderer);
if (!debugFrameTime)
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
/**
* @return the debug settings which are used in this MapView.
*/
public DebugSettings getDebugSettings() {
return debugSettings;
}
/**
* @return the job queue which is used in this MapView.
*/
public JobQueue getJobQueue() {
return mJobQueue;
}
/**
* @return the map database which is used for reading map files.
*/
public IMapDatabase getMapDatabase() {
return mMapDatabase;
}
/**
* @return the current position and zoom level of this MapView.
*/
public MapViewPosition getMapPosition() {
return mMapViewPosition;
}
/**
* @return the currently used projection of the map. Do not keep this object for a longer time.
*/
public Projection getProjection() {
return mProjection;
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
if (this.isClickable())
return mTouchEventHandler.handleMotionEvent(motionEvent);
return false;
}
/**
* Calculates all necessary tiles and adds jobs accordingly.
*/
public void redrawTiles() {
mMapRenderer.updateMap(false);
}
/**
* @param debugSettings
* the new DebugSettings for this MapView.
*/
public void setDebugSettings(DebugSettings debugSettings) {
this.debugSettings = debugSettings;
mMapRenderer.updateMap(true);
}
private Map<String, String> mMapOptions;
public Map<String, String> getMapOptions() {
return mMapOptions;
}
/**
* Sets the map file for this MapView.
*
* @param mapOptions
* ...
* @return true if the map file was set correctly, false otherwise.
*/
public boolean setMapOptions(Map<String, String> mapOptions) {
OpenResult openResult = null;
boolean initialized = false;
mJobQueue.clear();
mapWorkersPause(true);
for (MapWorker mapWorker : mMapWorkers) {
IMapGenerator mapGenerator = mapWorker.getMapGenerator();
IMapDatabase mapDatabase = mapGenerator.getMapDatabase();
mapDatabase.close();
openResult = mapDatabase.open(null);
if (openResult.isSuccess())
initialized = true;
}
mapWorkersProceed();
if (initialized) {
mMapOptions = mapOptions;
mMapRenderer.updateMap(true);
Log.i(TAG, "MapDatabase ready");
return true;
}
mMapOptions = null;
Log.i(TAG, "Opening MapDatabase failed");
return false;
}
private MapPosition getStartPosition() {
if (mMapDatabase == null)
return new MapPosition();
MapInfo mapInfo = mMapDatabase.getMapInfo();
if (mapInfo == null)
return new MapPosition();
GeoPoint startPos = mapInfo.startPosition;
if (startPos == null)
startPos = mapInfo.mapCenter;
if (startPos == null)
startPos = new GeoPoint(0, 0);
if (mapInfo.startZoomLevel != null)
return new MapPosition(startPos, (mapInfo.startZoomLevel).byteValue(), 1);
return new MapPosition(startPos, (byte) 1, 1);
}
/**
* Sets the MapDatabase for this MapView.
*
* @param mapDatabaseType
* the new MapDatabase.
*/
public void setMapDatabase(MapDatabases mapDatabaseType) {
if (mDebugDatabase)
return;
IMapGenerator mapGenerator;
Log.i(TAG, "setMapDatabase " + mapDatabaseType.name());
if (mMapDatabaseType == mapDatabaseType)
return;
mMapDatabaseType = mapDatabaseType;
mapWorkersPause(true);
for (MapWorker mapWorker : mMapWorkers) {
mapGenerator = mapWorker.getMapGenerator();
mapGenerator.setMapDatabase(MapDatabaseFactory
.createMapDatabase(mapDatabaseType));
}
mJobQueue.clear();
// String mapFile = mMapFile;
// mMapFile = null;
setMapOptions(null);
mapWorkersProceed();
}
public String getRenderTheme() {
return mRenderTheme;
}
/**
* Sets the internal theme which is used for rendering the map.
*
* @param internalRenderTheme
* the internal rendering theme.
* @return ...
* @throws IllegalArgumentException
* if the supplied internalRenderTheme is null.
*/
public boolean setRenderTheme(InternalRenderTheme internalRenderTheme) {
if (internalRenderTheme == null) {
throw new IllegalArgumentException("render theme must not be null");
}
boolean ret = setRenderTheme((Theme) internalRenderTheme);
if (ret) {
mRenderTheme = internalRenderTheme.name();
}
mMapRenderer.updateMap(true);
return ret;
}
/**
* Sets the theme file which is used for rendering the map.
*
* @param renderThemePath
* the path to the XML file which defines the rendering theme.
* @throws IllegalArgumentException
* if the supplied internalRenderTheme is null.
* @throws FileNotFoundException
* if the supplied file does not exist, is a directory or cannot be read.
*/
public void setRenderTheme(String renderThemePath) throws FileNotFoundException {
if (renderThemePath == null) {
throw new IllegalArgumentException("render theme path must not be null");
}
boolean ret = setRenderTheme(new ExternalRenderTheme(renderThemePath));
if (ret) {
mRenderTheme = renderThemePath;
}
mMapRenderer.updateMap(true);
}
private boolean setRenderTheme(Theme theme) {
mapWorkersPause(true);
InputStream inputStream = null;
try {
inputStream = theme.getRenderThemeAsStream();
RenderTheme t = RenderThemeHandler.getRenderTheme(inputStream);
mMapRenderer.setRenderTheme(t);
mMapWorkers[0].getMapGenerator().setRenderTheme(t);
return true;
} catch (ParserConfigurationException e) {
Log.e(TAG, e.getMessage());
} catch (SAXException e) {
Log.e(TAG, e.getMessage());
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
mapWorkersProceed();
}
return false;
}
@Override
protected synchronized void onSizeChanged(int width, int height,
int oldWidth, int oldHeight) {
mJobQueue.clear();
mapWorkersPause(true);
super.onSizeChanged(width, height, oldWidth, oldHeight);
mapWorkersProceed();
}
void destroy() {
for (MapWorker mapWorker : mMapWorkers) {
mapWorker.pause();
mapWorker.interrupt();
try {
mapWorker.join();
} catch (InterruptedException e) {
// restore the interrupted status
Thread.currentThread().interrupt();
}
IMapDatabase mapDatabase = mapWorker.getMapGenerator().getMapDatabase();
mapDatabase.close();
}
}
@Override
public void onPause() {
super.onPause();
mapWorkersPause(false);
if (this.enableCompass)
mCompass.disable();
}
@Override
public void onResume() {
super.onResume();
mapWorkersProceed();
if (this.enableCompass)
mCompass.enable();
}
/**
* Zooms in or out by the given amount of zoom levels.
*
* @param zoomLevelDiff
* the difference to the current zoom level.
* @return true if the zoom level was changed, false otherwise.
*/
public boolean zoom(byte zoomLevelDiff) {
int z = mMapViewPosition.getZoomLevel() + zoomLevelDiff;
if (zoomLevelDiff > 0) {
// check if zoom in is possible
if (z > getMaximumPossibleZoomLevel()) {
return false;
}
} else if (zoomLevelDiff < 0) {
// check if zoom out is possible
if (z < mMapZoomControls.getZoomLevelMin()) {
return false;
}
}
mMapViewPosition.setZoomLevel((byte) z);
redrawTiles();
return true;
}
/**
* @return the maximum possible zoom level.
*/
byte getMaximumPossibleZoomLevel() {
return (byte) 20;
// FIXME Math.min(mMapZoomControls.getZoomLevelMax(),
// mMapGenerator.getZoomLevelMax());
}
/**
* @return true if the current center position of this MapView is valid, false otherwise.
*/
boolean hasValidCenter() {
MapInfo mapInfo;
if (!mMapViewPosition.isValid())
return false;
if ((mapInfo = mMapDatabase.getMapInfo()) == null)
return false;
if (!mapInfo.boundingBox.contains(getMapPosition().getMapCenter()))
return false;
return true;
}
byte limitZoomLevel(byte zoom) {
return (byte) Math.max(Math.min(zoom, getMaximumPossibleZoomLevel()),
mMapZoomControls.getZoomLevelMin());
}
/**
* Sets the center and zoom level of this MapView and triggers a redraw.
*
* @param mapPosition
* the new map position of this MapView.
*/
public void setMapCenter(MapPosition mapPosition) {
Log.d(TAG, "setMapCenter "
+ " lat: " + mapPosition.lat
+ " lon: " + mapPosition.lon);
mMapViewPosition.setMapCenter(mapPosition);
redrawTiles();
}
/**
* Sets the center of the MapView and triggers a redraw.
*
* @param geoPoint
* the new center point of the map.
*/
public void setCenter(GeoPoint geoPoint) {
MapPosition mapPosition = new MapPosition(geoPoint,
mMapViewPosition.getZoomLevel(), 1);
setMapCenter(mapPosition);
}
/**
* @return MapPosition
*/
public MapViewPosition getMapViewPosition() {
return mMapViewPosition;
}
/**
* add jobs and remember MapWorkers that stuff needs to be done
*
* @param jobs
* tile jobs
*/
public void addJobs(ArrayList<JobTile> jobs) {
if (jobs == null) {
mJobQueue.clear();
return;
}
mJobQueue.setJobs(jobs);
for (int i = 0; i < mNumMapWorkers; i++) {
MapWorker m = mMapWorkers[i];
synchronized (m) {
m.notify();
}
}
}
private void mapWorkersPause(boolean wait) {
for (MapWorker mapWorker : mMapWorkers) {
if (!mapWorker.isPausing())
mapWorker.pause();
}
if (wait) {
for (MapWorker mapWorker : mMapWorkers) {
if (!mapWorker.isPausing())
mapWorker.awaitPausing();
}
}
}
private void mapWorkersProceed() {
for (MapWorker mapWorker : mMapWorkers)
mapWorker.proceed();
}
public void enableRotation(boolean enable) {
enableRotation = enable;
if (enable) {
enableCompass(false);
}
}
public void enableCompass(boolean enable) {
if (enable == this.enableCompass)
return;
this.enableCompass = enable;
if (enable)
enableRotation(false);
if (enable)
mCompass.enable();
else
mCompass.disable();
}
// /**
// * Sets the visibility of the zoom controls.
// *
// * @param showZoomControls
// * true if the zoom controls should be visible, false otherwise.
// */
// public void setBuiltInZoomControls(boolean showZoomControls) {
// mMapZoomControls.setShowMapZoomControls(showZoomControls);
//
// }
// /**
// * Sets the text scale for the map rendering. Has no effect in downloading mode.
// *
// * @param textScale
// * the new text scale for the map rendering.
// */
// public void setTextScale(float textScale) {
// mJobParameters = new JobParameters(mJobParameters.theme, textScale);
// clearAndRedrawMapView();
// }
// public final int
// public Handler messageHandler = new Handler() {
//
// @Override
// public void handleMessage(Message msg) {
// switch (msg.what) {
// // handle update
// // .....
// }
// }
//
// };
}

View File

@@ -0,0 +1,259 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import android.util.FloatMath;
import android.util.Log;
/**
* A MapPosition stores the latitude and longitude coordinate of a MapView together with its zoom level.
*/
public class MapViewPosition {
private static float MAX_SCALE = 2.0f;
private static float MIN_SCALE = 1.0f;
private static int MAX_ZOOMLEVEL = 16;
private double mLatitude;
private double mLongitude;
private final MapView mMapView;
private byte mZoomLevel;
private float mScale;
private float mRotation;
MapViewPosition(MapView mapView) {
mMapView = mapView;
mLatitude = Double.NaN;
mLongitude = Double.NaN;
mZoomLevel = -1;
mScale = 1;
mRotation = 0.0f;
}
/**
* @return the current center point of the MapView.
*/
public synchronized GeoPoint getMapCenter() {
return new GeoPoint(mLatitude, mLongitude);
}
/**
* @return an immutable MapPosition or null, if this map position is not valid.
* @see #isValid()
*/
public synchronized MapPosition getMapPosition() {
if (!isValid()) {
return null;
}
// Log.d("MapViewPosition", "lat: " + mLatitude + " lon: " + mLongitude);
return new MapPosition(mLatitude, mLongitude, mZoomLevel, mScale, mRotation);
}
/**
* @return the current zoom level of the MapView.
*/
public synchronized byte getZoomLevel() {
return mZoomLevel;
}
/**
* @return the current scale of the MapView.
*/
public synchronized float getScale() {
return mScale;
}
/**
* @return true if this MapViewPosition is valid, false otherwise.
*/
public synchronized boolean isValid() {
if (Double.isNaN(mLatitude)) {
return false;
} else if (mLatitude < MercatorProjection.LATITUDE_MIN) {
return false;
} else if (mLatitude > MercatorProjection.LATITUDE_MAX) {
return false;
}
if (Double.isNaN(mLongitude)) {
return false;
} else if (mLongitude < MercatorProjection.LONGITUDE_MIN) {
return false;
} else if (mLongitude > MercatorProjection.LONGITUDE_MAX) {
return false;
}
return true;
}
/**
* Moves this MapViewPosition by the given amount of pixels.
*
* @param mx
* the amount of pixels to move the map horizontally.
* @param my
* the amount of pixels to move the map vertically.
*/
public synchronized void moveMap(float mx, float my) {
double pixelX = MercatorProjection.longitudeToPixelX(mLongitude, mZoomLevel);
double pixelY = MercatorProjection.latitudeToPixelY(mLatitude, mZoomLevel);
double dx, dy;
if (mMapView.enableRotation || mMapView.enableCompass) {
float rad = (float) Math.toRadians(mRotation);
dx = mx / mScale;
dy = my / mScale;
double x = dx * FloatMath.cos(rad) + dy * -FloatMath.sin(rad);
double y = dx * FloatMath.sin(rad) + dy * FloatMath.cos(rad);
dx = pixelX - x;
dy = pixelY - y;
}
else {
dx = pixelX - mx / mScale;
dy = pixelY - my / mScale;
}
mLatitude = MercatorProjection.pixelYToLatitude(dy, mZoomLevel);
mLatitude = MercatorProjection.limitLatitude(mLatitude);
mLongitude = MercatorProjection.pixelXToLongitude(dx, mZoomLevel);
mLongitude = MercatorProjection.wrapLongitude(mLongitude);
// mLongitude = MercatorProjection.limitLongitude(mLongitude);
}
public synchronized void rotateMap(float angle, float cx, float cy) {
moveMap(cx, cy);
Log.d("MapViewPosition", "rotate:" + angle + " " + (mRotation - angle));
mRotation -= angle;
}
public void setRotation(float f) {
mRotation = f;
}
synchronized void setMapCenter(GeoPoint geoPoint) {
mLatitude = MercatorProjection.limitLatitude(geoPoint.getLatitude());
mLongitude = MercatorProjection.limitLongitude(geoPoint.getLongitude());
}
synchronized void setMapCenter(MapPosition mapPosition) {
mLatitude = MercatorProjection.limitLatitude(mapPosition.lat);
mLongitude = MercatorProjection.limitLongitude(mapPosition.lon);
mZoomLevel = mMapView.limitZoomLevel(mapPosition.zoomLevel);
}
synchronized void setZoomLevel(byte zoomLevel) {
mZoomLevel = mMapView.limitZoomLevel(zoomLevel);
}
synchronized void setScale(float scale) {
mScale = scale;
}
/**
* @param scale
* ...
* @param pivotX
* ...
* @param pivotY
* ...
*/
public synchronized void scaleMap(float scale, float pivotX, float pivotY) {
if (pivotY != 0 || pivotY != 0)
moveMap(pivotX * (1.0f - scale),
pivotY * (1.0f - scale));
float s = mScale * scale;
if (s >= MAX_SCALE) {
if (s > 8)
return;
if (mZoomLevel <= MAX_ZOOMLEVEL) {
byte z = (byte) FloatMath.sqrt(s);
mZoomLevel += z;
s *= 1.0f / (1 << z);
}
} else if (s < MIN_SCALE) {
byte z = (byte) FloatMath.sqrt(1 / s);
if (z != 0 && mZoomLevel == 1)
return;
mZoomLevel -= z;
s *= 1 << z;
}
mScale = s;
}
/**
* Zooms in or out by the given amount of zoom levels.
*
* @param zoomLevelDiff
* the difference to the current zoom level.
* @param s
* scale between min/max zoom
* @return true if the zoom level was changed, false otherwise.
*/
// public boolean zoom(byte zoomLevelDiff, float s) {
// float scale = s;
//
// if (zoomLevelDiff > 0) {
// // check if zoom in is possible
// if (mMapViewPosition.getZoomLevel() + zoomLevelDiff > getMaximumPossibleZoomLevel()) {
// return false;
// }
//
// scale *= 1.0f / (1 << zoomLevelDiff);
// } else if (zoomLevelDiff < 0) {
// // check if zoom out is possible
// if (mMapViewPosition.getZoomLevel() + zoomLevelDiff < mMapZoomControls.getZoomLevelMin()) {
// return false;
// }
//
// scale *= 1 << -zoomLevelDiff;
// }
//
// if (scale == 0)
// scale = 1;
// // else
// // scale = Math.round(256.0f * scale) / 256.0f;
//
// mMapViewPosition.setZoomLevel((byte) (mMapViewPosition.getZoomLevel() + zoomLevelDiff));
//
// // mapZoomControls.onZoomLevelChange(mapViewPosition.getZoomLevel());
//
// // zoomAnimator.setParameters(zoomStart, matrixScaleFactor,
// // getWidth() >> 1, getHeight() >> 1);
// // zoomAnimator.startAnimation();
//
// // if (scale > MAX_ZOOM) {
// // scale = MAX_ZOOM;
// // }
//
// if (zoomLevelDiff != 0 || mZoomFactor != scale) {
// mZoomFactor = scale;
// redrawTiles();
// }
//
// return true;
// }
}

View File

@@ -0,0 +1,125 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import android.graphics.Point;
class MapViewProjection implements Projection {
private static final String INVALID_MAP_VIEW_DIMENSIONS = "invalid MapView dimensions";
private final MapView mMapView;
MapViewProjection(MapView mapView) {
mMapView = mapView;
}
@Override
public GeoPoint fromPixels(int x, int y) {
if (mMapView.getWidth() <= 0 || mMapView.getHeight() <= 0) {
return null;
}
MapPosition mapPosition = mMapView.getMapPosition().getMapPosition();
// calculate the pixel coordinates of the top left corner
double pixelX = MercatorProjection.longitudeToPixelX(mapPosition);
double pixelY = MercatorProjection.latitudeToPixelY(mapPosition);
pixelX -= mMapView.getWidth() >> 1;
pixelY -= mMapView.getHeight() >> 1;
// convert the pixel coordinates to a GeoPoint and return it
return new GeoPoint(MercatorProjection.pixelYToLatitude(pixelY + y,
mapPosition.zoomLevel),
MercatorProjection.pixelXToLongitude(pixelX + x, mapPosition.zoomLevel));
}
@Override
public int getLatitudeSpan() {
if (mMapView.getWidth() > 0 && mMapView.getWidth() > 0) {
GeoPoint top = fromPixels(0, 0);
GeoPoint bottom = fromPixels(0, mMapView.getHeight());
return Math.abs(top.latitudeE6 - bottom.latitudeE6);
}
throw new IllegalStateException(INVALID_MAP_VIEW_DIMENSIONS);
}
@Override
public int getLongitudeSpan() {
if (mMapView.getWidth() > 0 && mMapView.getWidth() > 0) {
GeoPoint left = fromPixels(0, 0);
GeoPoint right = fromPixels(mMapView.getWidth(), 0);
return Math.abs(left.longitudeE6 - right.longitudeE6);
}
throw new IllegalStateException(INVALID_MAP_VIEW_DIMENSIONS);
}
@Override
public float metersToPixels(float meters, byte zoom) {
double latitude = mMapView.getMapPosition().getMapCenter().getLatitude();
double groundResolution = MercatorProjection.calculateGroundResolution(latitude,
zoom);
return (float) (meters * (1 / groundResolution));
}
@Override
public Point toPixels(GeoPoint in, Point out) {
if (mMapView.getWidth() <= 0 || mMapView.getHeight() <= 0) {
return null;
}
MapPosition mapPosition = mMapView.getMapPosition().getMapPosition();
// calculate the pixel coordinates of the top left corner
double pixelX = MercatorProjection.longitudeToPixelX(mapPosition);
double pixelY = MercatorProjection.latitudeToPixelY(mapPosition);
pixelX -= mMapView.getWidth() >> 1;
pixelY -= mMapView.getHeight() >> 1;
if (out == null) {
// create a new point and return it
return new Point(
(int) (MercatorProjection.longitudeToPixelX(in.getLongitude(),
mapPosition.zoomLevel) - pixelX),
(int) (MercatorProjection.latitudeToPixelY(in.getLatitude(),
mapPosition.zoomLevel) - pixelY));
}
// reuse the existing point
out.x = (int) (MercatorProjection.longitudeToPixelX(in.getLongitude(),
mapPosition.zoomLevel) - pixelX);
out.y = (int) (MercatorProjection.latitudeToPixelY(in.getLatitude(),
mapPosition.zoomLevel) - pixelY);
return out;
}
@Override
public Point toPoint(GeoPoint in, Point out, byte zoom) {
if (out == null) {
// create a new point and return it
return new Point((int) MercatorProjection.longitudeToPixelX(
in.getLongitude(), zoom),
(int) MercatorProjection.latitudeToPixelY(in.getLatitude(), zoom));
}
// reuse the existing point
out.x = (int) MercatorProjection.longitudeToPixelX(in.getLongitude(), zoom);
out.y = (int) MercatorProjection.latitudeToPixelY(in.getLatitude(), zoom);
return out;
}
}

View File

@@ -0,0 +1,313 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import org.oscim.view.mapgenerator.IMapGenerator;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.ZoomControls;
/**
* A MapZoomControls instance displays buttons for zooming in and out in a map.
*/
public class MapZoomControls {
private static class ZoomControlsHideHandler extends Handler {
private final ZoomControls mZoomControls;
ZoomControlsHideHandler(ZoomControls zoomControls) {
super();
mZoomControls = zoomControls;
}
@Override
public void handleMessage(Message message) {
mZoomControls.hide();
}
}
private static class ZoomInClickListener implements View.OnClickListener {
private final MapView mMapView;
ZoomInClickListener(MapView mapView) {
mMapView = mapView;
}
@Override
public void onClick(View view) {
mMapView.zoom((byte) 1);
}
}
private static class ZoomOutClickListener implements View.OnClickListener {
private final MapView mMapView;
ZoomOutClickListener(MapView mapView) {
mMapView = mapView;
}
@Override
public void onClick(View view) {
mMapView.zoom((byte) -1);
}
}
/**
* Default {@link Gravity} of the zoom controls.
*/
private static final int DEFAULT_ZOOM_CONTROLS_GRAVITY = Gravity.BOTTOM
| Gravity.RIGHT;
/**
* Default maximum zoom level.
*/
private static final byte DEFAULT_ZOOM_LEVEL_MAX = 22;
/**
* Default minimum zoom level.
*/
private static final byte DEFAULT_ZOOM_LEVEL_MIN = 0;
/**
* Message code for the handler to hide the zoom controls.
*/
private static final int MSG_ZOOM_CONTROLS_HIDE = 0;
/**
* Horizontal padding for the zoom controls.
*/
private static final int ZOOM_CONTROLS_HORIZONTAL_PADDING = 5;
/**
* Delay in milliseconds after which the zoom controls disappear.
*/
private static final long ZOOM_CONTROLS_TIMEOUT = ViewConfiguration
.getZoomControlsTimeout();
private boolean mGravityChanged;
private boolean mShowMapZoomControls;
private final ZoomControls mZoomControls;
private int mZoomControlsGravity;
private final Handler mZoomControlsHideHandler;
private byte mZoomLevelMax;
private byte mZoomLevelMin;
MapZoomControls(Context context, final MapView mapView) {
mZoomControls = new ZoomControls(context);
mShowMapZoomControls = true;
mZoomLevelMax = DEFAULT_ZOOM_LEVEL_MAX;
mZoomLevelMin = DEFAULT_ZOOM_LEVEL_MIN;
mZoomControls.setVisibility(View.GONE);
mZoomControlsGravity = DEFAULT_ZOOM_CONTROLS_GRAVITY;
mZoomControls.setOnZoomInClickListener(new ZoomInClickListener(mapView));
mZoomControls.setOnZoomOutClickListener(new ZoomOutClickListener(mapView));
mZoomControlsHideHandler = new ZoomControlsHideHandler(mZoomControls);
// int wrapContent = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
// LayoutParams layoutParams = new LayoutParams(wrapContent, wrapContent);
// mapView.addView(zoomControls, layoutParams);
}
/**
* @return the current gravity for the placing of the zoom controls.
* @see Gravity
*/
public int getZoomControlsGravity() {
return mZoomControlsGravity;
}
/**
* @return the maximum zoom level of the map.
*/
public byte getZoomLevelMax() {
return mZoomLevelMax;
}
/**
* @return the minimum zoom level of the map.
*/
public byte getZoomLevelMin() {
return mZoomLevelMin;
}
/**
* @return true if the zoom controls are visible, false otherwise.
*/
public boolean isShowMapZoomControls() {
return mShowMapZoomControls;
}
/**
* @param showMapZoomControls
* true if the zoom controls should be visible, false otherwise.
*/
public void setShowMapZoomControls(boolean showMapZoomControls) {
mShowMapZoomControls = false;
}
/**
* Sets the gravity for the placing of the zoom controls. Supported values are {@link Gravity#TOP},
* {@link Gravity#CENTER_VERTICAL}, {@link Gravity#BOTTOM}, {@link Gravity#LEFT}, {@link Gravity#CENTER_HORIZONTAL}
* and {@link Gravity#RIGHT}.
*
* @param zoomControlsGravity
* a combination of {@link Gravity} constants describing the desired placement.
*/
public void setZoomControlsGravity(int zoomControlsGravity) {
if (mZoomControlsGravity != zoomControlsGravity) {
mZoomControlsGravity = zoomControlsGravity;
mGravityChanged = true;
}
}
/**
* Sets the maximum zoom level of the map.
* <p>
* The maximum possible zoom level of the MapView depends also on the current {@link IMapGenerator}. For example,
* downloading map tiles may only be possible up to a certain zoom level. Setting a higher maximum zoom level has no
* effect in this case.
*
* @param zoomLevelMax
* the maximum zoom level.
* @throws IllegalArgumentException
* if the maximum zoom level is smaller than the current minimum zoom level.
*/
public void setZoomLevelMax(byte zoomLevelMax) {
if (zoomLevelMax < mZoomLevelMin) {
throw new IllegalArgumentException();
}
mZoomLevelMax = zoomLevelMax;
}
/**
* Sets the minimum zoom level of the map.
*
* @param zoomLevelMin
* the minimum zoom level.
* @throws IllegalArgumentException
* if the minimum zoom level is larger than the current maximum zoom level.
*/
public void setZoomLevelMin(byte zoomLevelMin) {
if (zoomLevelMin > mZoomLevelMax) {
throw new IllegalArgumentException();
}
mZoomLevelMin = zoomLevelMin;
}
private int calculatePositionLeft(int left, int right, int zoomControlsWidth) {
int gravity = mZoomControlsGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
switch (gravity) {
case Gravity.LEFT:
return ZOOM_CONTROLS_HORIZONTAL_PADDING;
case Gravity.CENTER_HORIZONTAL:
return (right - left - zoomControlsWidth) / 2;
case Gravity.RIGHT:
return right - left - zoomControlsWidth
- ZOOM_CONTROLS_HORIZONTAL_PADDING;
}
throw new IllegalArgumentException("unknown horizontal gravity: " + gravity);
}
private int calculatePositionTop(int top, int bottom, int zoomControlsHeight) {
int gravity = mZoomControlsGravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (gravity) {
case Gravity.TOP:
return 0;
case Gravity.CENTER_VERTICAL:
return (bottom - top - zoomControlsHeight) / 2;
case Gravity.BOTTOM:
return bottom - top - zoomControlsHeight;
}
throw new IllegalArgumentException("unknown vertical gravity: " + gravity);
}
private void showZoomControls() {
mZoomControlsHideHandler.removeMessages(MSG_ZOOM_CONTROLS_HIDE);
if (mZoomControls.getVisibility() != View.VISIBLE) {
mZoomControls.show();
}
}
private void showZoomControlsWithTimeout() {
showZoomControls();
mZoomControlsHideHandler.sendEmptyMessageDelayed(MSG_ZOOM_CONTROLS_HIDE,
ZOOM_CONTROLS_TIMEOUT);
}
int getMeasuredHeight() {
return mZoomControls.getMeasuredHeight();
}
int getMeasuredWidth() {
return mZoomControls.getMeasuredWidth();
}
void measure(int widthMeasureSpec, int heightMeasureSpec) {
mZoomControls.measure(widthMeasureSpec, heightMeasureSpec);
}
void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (!changed && !mGravityChanged) {
return;
}
int zoomControlsWidth = mZoomControls.getMeasuredWidth();
int zoomControlsHeight = mZoomControls.getMeasuredHeight();
int positionLeft = calculatePositionLeft(left, right, zoomControlsWidth);
int positionTop = calculatePositionTop(top, bottom, zoomControlsHeight);
int positionRight = positionLeft + zoomControlsWidth;
int positionBottom = positionTop + zoomControlsHeight;
mZoomControls.layout(positionLeft, positionTop, positionRight, positionBottom);
mGravityChanged = false;
}
void onMapViewTouchEvent(int action) {
if (mShowMapZoomControls) {
switch (action) {
case MotionEvent.ACTION_DOWN:
showZoomControls();
break;
case MotionEvent.ACTION_CANCEL:
showZoomControlsWithTimeout();
break;
case MotionEvent.ACTION_UP:
showZoomControlsWithTimeout();
break;
}
}
}
void onZoomLevelChange(int zoomLevel) {
boolean zoomInEnabled = zoomLevel < mZoomLevelMax;
boolean zoomOutEnabled = zoomLevel > mZoomLevelMin;
mZoomControls.setIsZoomInEnabled(zoomInEnabled);
mZoomControls.setIsZoomOutEnabled(zoomOutEnabled);
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import org.oscim.core.GeoPoint;
import android.graphics.Point;
/**
* A Projection translates between the pixel coordinate system on the screen and geographical points on the earth. To
* retrieve the currently used Projection for a given MapView, call the {@link MapView#getProjection()} method.
*/
public interface Projection {
/**
* Translates the given screen coordinates to a {@link GeoPoint}. If the corresponding MapView has no valid
* dimensions (width and height > 0), null is returned.
*
* @param x
* the pixel x coordinate on the screen.
* @param y
* the pixel y coordinate on the screen.
* @return a new {@link GeoPoint} or null, if the corresponding MapView has no valid dimensions.
*/
GeoPoint fromPixels(int x, int y);
/**
* @return the latitude span from the top to the bottom of the map in microdegrees (degrees * 10^6).
* @throws IllegalStateException
* if the MapView dimensions are not valid (width and height > 0).
*/
int getLatitudeSpan();
/**
* @return the longitude span from the left to the right of the map in microdegrees (degrees * 10^6).
* @throws IllegalStateException
* if the MapView dimensions are not valid (width and height > 0).
*/
int getLongitudeSpan();
/**
* Converts the given distance in meters at the given zoom level to the corresponding number of horizontal pixels.
* The calculation is carried out at the current latitude coordinate.
*
* @param meters
* the distance in meters.
* @param zoomLevel
* the zoom level at which the distance should be calculated.
* @return the number of pixels at the current map position and the given zoom level.
*/
float metersToPixels(float meters, byte zoomLevel);
/**
* Translates the given {@link GeoPoint} to relative pixel coordinates on the screen. If the corresponding MapView
* has no valid dimensions (width and height > 0), null is returned.
*
* @param in
* the geographical point to convert.
* @param out
* an already existing object to use for the output. If this parameter is null, a new Point object will
* be created and returned.
* @return a Point which is relative to the top-left of the MapView or null, if the corresponding MapView has no
* valid dimensions.
*/
Point toPixels(GeoPoint in, Point out);
/**
* Translates the given {@link GeoPoint} to absolute pixel coordinates on the world map.
*
* @param in
* the geographical point to convert.
* @param out
* an already existing object to use for the output. If this parameter is null, a new Point object will
* be created and returned.
* @param zoomLevel
* the zoom level at which the point should be converted.
* @return a Point which is relative to the top-left of the world map.
*/
Point toPoint(GeoPoint in, Point out, byte zoomLevel);
}

View File

@@ -0,0 +1,544 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.view;
import org.oscim.core.Tile;
import android.content.Context;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ViewConfiguration;
import android.view.animation.DecelerateInterpolator;
import android.widget.Scroller;
/**
* Implementation for multi-touch capable devices.
*/
public class TouchHandler {
private static final int INVALID_POINTER_ID = -1;
/* package */final MapView mMapView;
/* package */final MapViewPosition mMapPosition;
private final float mMapMoveDelta;
private boolean mMoveStart;
private boolean mRotationStart;
private float mPosX;
private float mPosY;
private double mAngle;
private int mActivePointerId;
private final ScaleGestureDetector mScaleGestureDetector;
private final GestureDetector mGestureDetector;
/**
* @param context
* the Context
* @param mapView
* the MapView
*/
public TouchHandler(Context context, MapView mapView) {
ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
mMapView = mapView;
mMapPosition = mapView.getMapPosition();
mMapMoveDelta = viewConfiguration.getScaledTouchSlop();
mActivePointerId = INVALID_POINTER_ID;
mScaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());
mGestureDetector = new GestureDetector(context, new MapGestureDetector());
}
private static int getAction(MotionEvent motionEvent) {
return motionEvent.getAction() & MotionEvent.ACTION_MASK;
}
private boolean onActionCancel() {
mActivePointerId = INVALID_POINTER_ID;
return true;
}
private boolean onActionDown(MotionEvent event) {
mPosX = event.getX();
mPosY = event.getY();
mMoveStart = false;
mRotationStart = false;
// save the ID of the pointer
mActivePointerId = event.getPointerId(0);
// Log.d("...", "set active pointer" + mActivePointerId);
return true;
}
private boolean mScaling = false;
private boolean onActionMove(MotionEvent event) {
int pointerIndex = event.findPointerIndex(mActivePointerId);
// calculate the distance between previous and current position
float moveX = event.getX(pointerIndex) - mPosX;
float moveY = event.getY(pointerIndex) - mPosY;
boolean scaling = mScaleGestureDetector.isInProgress();
if (!mScaling) {
mScaling = scaling;
}
if (!scaling && !mMoveStart) {
if (Math.abs(moveX) > 3 * mMapMoveDelta
|| Math.abs(moveY) > 3 * mMapMoveDelta) {
// the map movement threshold has been reached
// longPressDetector.pressStop();
mMoveStart = true;
// save the position of the event
mPosX = event.getX(pointerIndex);
mPosY = event.getY(pointerIndex);
}
return true;
}
if (mMapView.enableRotation) {
if (multi > 0) {
double x1 = event.getX(0);
double x2 = event.getX(1);
double y1 = event.getY(0);
double y2 = event.getY(1);
double dx = x1 - x2;
double dy = y1 - y2;
double rad = Math.atan2(dy, dx);
// focus point relative to center
double cx = (mMapView.getWidth() >> 1) - (x1 + x2) / 2;
double cy = (mMapView.getHeight() >> 1) - (y1 + y2) / 2;
double r = rad - mAngle;
double rsin = Math.sin(r);
double rcos = Math.cos(r);
float x = (float) (cx * rcos + cy * -rsin - cx);
float y = (float) (cx * rsin + cy * rcos - cy);
// Log.d("...", "move " + x + " " + y + " " + cx + " " + cy);
if (!mRotationStart) {
if (Math.abs(rad - mAngle) > 0.001)
mRotationStart = true;
}
else {
mMapPosition.rotateMap((float) Math.toDegrees(rad - mAngle), x, y);
mAngle = rad;
mMapView.redrawTiles();
}
}
}
// save the position of the event
mPosX = event.getX(pointerIndex);
mPosY = event.getY(pointerIndex);
if (scaling) {
return true;
}
mMapPosition.moveMap(moveX, moveY);
mMapView.redrawTiles();
return true;
}
private int multi = 0;
private boolean onActionPointerDown(MotionEvent event) {
// longPressDetector.pressStop();
// multiTouchDownTime = motionEvent.getEventTime();
multi++;
if (multi == 1) {
double dx = event.getX(0) - event.getX(1);
double dy = event.getY(0) - event.getY(1);
mAngle = Math.atan2(dy, dx);
}
return true;
}
private boolean onActionPointerUp(MotionEvent motionEvent) {
// extract the index of the pointer that left the touch sensor
int pointerIndex = (motionEvent.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
if (motionEvent.getPointerId(pointerIndex) == mActivePointerId) {
// the active pointer has gone up, choose a new one
if (pointerIndex == 0) {
pointerIndex = 1;
} else {
pointerIndex = 0;
}
// save the position of the event
mPosX = motionEvent.getX(pointerIndex);
mPosY = motionEvent.getY(pointerIndex);
mActivePointerId = motionEvent.getPointerId(pointerIndex);
}
multi--;
return true;
}
/**
* @param motionEvent
* ...
* @return ...
*/
private boolean onActionUp(MotionEvent motionEvent) {
mActivePointerId = INVALID_POINTER_ID;
mScaling = false;
multi = 0;
return true;
}
/**
* @param event
* ...
* @return ...
*/
public boolean handleMotionEvent(MotionEvent event) {
// workaround for a bug in the ScaleGestureDetector, see Android issue
// #12976
// if (event.getAction() != MotionEvent.ACTION_MOVE
// || event.getPointerCount() > 1) {
mScaleGestureDetector.onTouchEvent(event);
// }
if (!mScaling)
mGestureDetector.onTouchEvent(event);
int action = getAction(event);
boolean ret = false;
if (action == MotionEvent.ACTION_DOWN) {
ret = onActionDown(event);
} else if (action == MotionEvent.ACTION_MOVE) {
ret = onActionMove(event);
} else if (action == MotionEvent.ACTION_UP) {
ret = onActionUp(event);
} else if (action == MotionEvent.ACTION_CANCEL) {
ret = onActionCancel();
} else if (action == MotionEvent.ACTION_POINTER_DOWN) {
return onActionPointerDown(event);
} else if (action == MotionEvent.ACTION_POINTER_UP) {
ret = onActionPointerUp(event);
}
return ret;
}
class MapGestureDetector extends SimpleOnGestureListener {
private Scroller mScroller;
private float mPrevX, mPrevY, mPrevScale;
private CountDownTimer mTimer = null;
private boolean fling = false;
public MapGestureDetector() {
mScroller = new Scroller(mMapView.getContext(),
new android.view.animation.LinearInterpolator());
}
@Override
public boolean onDown(MotionEvent e) {
if (fling) {
mScroller.forceFinished(true);
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
fling = false;
}
// Log.d("mapsforge", "onDown");
return true;
}
boolean scroll() {
if (mScroller.isFinished()) {
return false;
}
mScroller.computeScrollOffset();
float moveX = mScroller.getCurrX() - mPrevX;
float moveY = mScroller.getCurrY() - mPrevY;
if (moveX >= 1 || moveY >= 1 || moveX <= -1 || moveY <= -1) {
mMapPosition.moveMap(moveX, moveY);
mMapView.redrawTiles();
mPrevX = mScroller.getCurrX();
mPrevY = mScroller.getCurrY();
}
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
int w = Tile.TILE_SIZE * 20;
int h = Tile.TILE_SIZE * 20;
mPrevX = 0;
mPrevY = 0;
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
mScroller.fling(0, 0, Math.round(velocityX) / 2, Math.round(velocityY) / 2,
-w, w, -h, h);
// animate for two seconds
mTimer = new CountDownTimer(1500, 50) {
@Override
public void onTick(long tick) {
scroll();
}
@Override
public void onFinish() {
// do nothing
}
}.start();
fling = true;
return true;
}
private DecelerateInterpolator mBounce = new DecelerateInterpolator();
private boolean mZooutOut = true;
@Override
public void onLongPress(MotionEvent e) {
Log.d("mapsforge", "long press");
// mMapView.zoom((byte) -1);
mPrevScale = 0;
mTimer = new CountDownTimer((int) mScaleDuration, 30) {
@Override
public void onTick(long tick) {
scale2(tick);
}
@Override
public void onFinish() {
scale2(0);
}
}.start();
}
boolean scale2(long tick) {
if (mPrevScale >= 1) {
mTimer = null;
return false;
}
float adv = (mScaleDuration - tick) / mScaleDuration;
adv = mBounce.getInterpolation(adv);
float scale = adv - mPrevScale;
mPrevScale += scale;
if (mZooutOut) {
mMapPosition.scaleMap(1 - scale, 0, 0);
}
// } else {
// mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
// }
mMapView.redrawTiles();
if (tick == 0)
mTimer = null;
return true;
}
private final float mScaleDuration = 300;
boolean scale(long tick) {
fling = true;
if (mPrevScale >= 1)
return false;
float adv = (mScaleDuration - tick) / mScaleDuration;
adv = mBounce.getInterpolation(adv);
float scale = adv - mPrevScale;
mPrevScale += scale;
scale += 1;
adv += 1;
if (scale > 1) {
mMapPosition.scaleMap(scale, mPrevX / adv, mPrevY / adv);
mMapView.redrawTiles();
}
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// Log.d("mapsforge", "double tap");
mPrevX = (e.getX(0) - (mMapView.getWidth() >> 1)) * 2f;
mPrevY = (e.getY(0) - (mMapView.getHeight() >> 1)) * 2f;
mPrevScale = 0;
mTimer = new CountDownTimer((int) mScaleDuration, 30) {
@Override
public void onTick(long tick) {
scale(tick);
}
@Override
public void onFinish() {
scale(0);
}
}.start();
return true;
}
}
class ScaleListener implements ScaleGestureDetector.OnScaleGestureListener {
private float mCenterX;
private float mCenterY;
private float mFocusX;
private float mFocusY;
private float mScale;
private boolean mBeginScale;
@Override
public boolean onScale(ScaleGestureDetector gd) {
mScale = gd.getScaleFactor();
mFocusX = gd.getFocusX() - mCenterX;
mFocusY = gd.getFocusY() - mCenterY;
mSumScale *= mScale;
mTimeEnd = SystemClock.elapsedRealtime();
if (!mBeginScale) {
if (mTimeEnd - mTimeStart > 100) {
mBeginScale = true;
mScale = mSumScale;
}
else
return true;
}
mMapPosition.scaleMap(mScale, mFocusX, mFocusY);
mMapView.redrawTiles();
return true;
}
private long mTimeStart;
private long mTimeEnd;
private float mSumScale;
@Override
public boolean onScaleBegin(ScaleGestureDetector gd) {
mTimeEnd = mTimeStart = SystemClock.elapsedRealtime();
mSumScale = 1;
mBeginScale = false;
mCenterX = mMapView.getWidth() >> 1;
mCenterY = mMapView.getHeight() >> 1;
mScale = 1;
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector gd) {
// Log.d("ScaleListener", "Sum " + mSumScale + " " + (mTimeEnd - mTimeStart));
if (mTimer == null && mTimeEnd - mTimeStart < 150
&& (mSumScale < 0.99 || mSumScale > 1.01)) {
mPrevScale = 0;
mZooutOut = mSumScale < 0.99;
mTimer = new CountDownTimer((int) mScaleDuration, 30) {
@Override
public void onTick(long tick) {
scale(tick);
}
@Override
public void onFinish() {
scale(0);
}
}.start();
}
}
private DecelerateInterpolator mBounce = new DecelerateInterpolator();
private float mPrevScale;
private CountDownTimer mTimer;
boolean mZooutOut;
private final float mScaleDuration = 350;
boolean scale(long tick) {
if (mPrevScale >= 1) {
mTimer = null;
return false;
}
float adv = (mScaleDuration - tick) / mScaleDuration;
adv = mBounce.getInterpolation(adv);
float scale = adv - mPrevScale;
mPrevScale += scale;
if (mZooutOut) {
mMapPosition.scaleMap(1 - scale, 0, 0);
} else {
mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
}
mMapView.redrawTiles();
if (tick == 0)
mTimer = null;
return true;
}
}
}

View File

@@ -0,0 +1,489 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General 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 License for more details.
*
* You should have received a copy of the GNU Lesser General License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.view.glrenderer;
import org.oscim.core.Tile;
import org.oscim.theme.renderinstruction.Line;
import android.graphics.Paint.Cap;
import android.util.FloatMath;
class LineLayer {
private static final float COORD_SCALE = MapRenderer.COORD_MULTIPLIER;
// scale factor mapping extrusion vector to short values
private static final float DIR_SCALE = 2048;
// mask for packing last two bits of extrusion vector with texture coordinates
private static final int DIR_MASK = 0xFFFFFFFC;
// next layer
LineLayer next;
// lines referenced by this outline layer
LineLayer outlines;
Line line;
float width;
boolean isOutline;
int layer;
ShortItem pool;
protected ShortItem curItem;
// number of vertices this layer holds
int verticesCnt;
// vertices offset of this layer in VBO
int offset;
LineLayer(int layer, Line line, float width, boolean outline) {
this.layer = layer;
this.width = width;
this.line = line;
this.isOutline = outline;
}
void addOutline(LineLayer link) {
for (LineLayer l = outlines; l != null; l = l.outlines)
if (link == l)
return;
link.outlines = outlines;
outlines = link;
}
/*
* line extrusion is based on code from GLMap (https://github.com/olofsj/GLMap/) by olofsj
*/
void addLine(float[] points, short[] index) {
float x, y, nextX, nextY, prevX, prevY;
float a, ux, uy, vx, vy, wx, wy;
int tmax = Tile.TILE_SIZE + 10;
int tmin = -10;
boolean rounded = false;
boolean squared = false;
if (line.cap == Cap.ROUND)
rounded = true;
else if (line.cap == Cap.SQUARE)
squared = true;
if (pool == null) {
pool = curItem = ShortPool.get();
}
ShortItem si = curItem;
short v[] = si.vertices;
int opos = si.used;
for (int i = 0, pos = 0, n = index.length; i < n; i++) {
int length = index[i];
if (length < 0)
break;
// save some vertices
if (rounded && i > 200)
rounded = false;
int ipos = pos;
// need at least two points
if (length < 4) {
pos += length;
continue;
}
// amount of vertices used
verticesCnt += length + (rounded ? 6 : 2);
x = points[ipos++];
y = points[ipos++];
nextX = points[ipos++];
nextY = points[ipos++];
// Calculate triangle corners for the given width
vx = nextX - x;
vy = nextY - y;
a = FloatMath.sqrt(vx * vx + vy * vy);
vx = (vx / a);
vy = (vy / a);
ux = -vy;
uy = vx;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
short ox, oy, dx, dy;
int ddx, ddy;
ox = (short) (x * COORD_SCALE);
oy = (short) (y * COORD_SCALE);
boolean outside = (x < tmin || x > tmax || y < tmin || y > tmax);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
if (rounded && !outside) {
// add first vertex twice
ddx = (int) ((ux - vx) * DIR_SCALE);
ddy = (int) ((uy - vy) * DIR_SCALE);
// last two bit encode texture coord (-1)
dx = (short) (0 | ddx & DIR_MASK);
dy = (short) (2 | ddy & DIR_MASK);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
ddx = (int) (-(ux + vx) * DIR_SCALE);
ddy = (int) (-(uy + vy) * DIR_SCALE);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (2 | ddx & DIR_MASK);
v[opos++] = (short) (2 | ddy & DIR_MASK);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
// Start of line
ddx = (int) (ux * DIR_SCALE);
ddy = (int) (uy * DIR_SCALE);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (0 | ddx & DIR_MASK);
v[opos++] = (short) (1 | ddy & DIR_MASK);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (2 | -ddx & DIR_MASK);
v[opos++] = (short) (1 | -ddy & DIR_MASK);
} else {
// outside means line is probably clipped
// TODO should align ending with tile boundary
// for now, just extend the line a little
if (squared) {
vx = 0;
vy = 0;
} else if (!outside) {
vx *= 0.5;
vy *= 0.5;
}
if (rounded)
verticesCnt -= 2;
// add first vertex twice
ddx = (int) ((ux - vx) * DIR_SCALE);
ddy = (int) ((uy - vy) * DIR_SCALE);
dx = (short) (0 | ddx & DIR_MASK);
dy = (short) (1 | ddy & DIR_MASK);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
ddx = (int) (-(ux + vx) * DIR_SCALE);
ddy = (int) (-(uy + vy) * DIR_SCALE);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (2 | ddx & DIR_MASK);
v[opos++] = (short) (1 | ddy & DIR_MASK);
}
prevX = x;
prevY = y;
x = nextX;
y = nextY;
for (; ipos < pos + length;) {
nextX = points[ipos++];
nextY = points[ipos++];
// Unit vector pointing back to previous node
vx = prevX - x;
vy = prevY - y;
a = FloatMath.sqrt(vx * vx + vy * vy);
vx = (vx / a);
vy = (vy / a);
// Unit vector pointing forward to next node
wx = nextX - x;
wy = nextY - y;
a = FloatMath.sqrt(wx * wx + wy * wy);
wx = (wx / a);
wy = (wy / a);
// Sum of these two vectors points
ux = vx + wx;
uy = vy + wy;
a = -wy * ux + wx * uy;
// boolean split = false;
if (a < 0.01f && a > -0.01f) {
// Almost straight
ux = -wy;
uy = wx;
} else {
ux = (ux / a);
uy = (uy / a);
// hack to avoid miter going to infinity
if (ux > 2.0f || ux < -2.0f || uy > 2.0f || uy < -2.0f) {
ux = -wy;
uy = wx;
}
}
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
ox = (short) (x * COORD_SCALE);
oy = (short) (y * COORD_SCALE);
ddx = (int) (ux * DIR_SCALE);
ddy = (int) (uy * DIR_SCALE);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (0 | ddx & DIR_MASK);
v[opos++] = (short) (1 | ddy & DIR_MASK);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (2 | -ddx & DIR_MASK);
v[opos++] = (short) (1 | -ddy & DIR_MASK);
prevX = x;
prevY = y;
x = nextX;
y = nextY;
}
vx = prevX - x;
vy = prevY - y;
a = FloatMath.sqrt(vx * vx + vy * vy);
vx = (vx / a);
vy = (vy / a);
ux = vy;
uy = -vx;
outside = (x < tmin || x > tmax || y < tmin || y > tmax);
if (opos == ShortItem.SIZE) {
si.next = ShortPool.get();
si = si.next;
opos = 0;
v = si.vertices;
}
ox = (short) (x * COORD_SCALE);
oy = (short) (y * COORD_SCALE);
if (rounded && !outside) {
ddx = (int) (ux * DIR_SCALE);
ddy = (int) (uy * DIR_SCALE);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (0 | ddx & DIR_MASK);
v[opos++] = (short) (1 | ddy & DIR_MASK);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (2 | -ddx & DIR_MASK);
v[opos++] = (short) (1 | -ddy & DIR_MASK);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
// For rounded line edges
ddx = (int) ((ux - vx) * DIR_SCALE);
ddy = (int) ((uy - vy) * DIR_SCALE);
dx = (short) (0 | ddx & DIR_MASK);
dy = (short) (0 | ddy & DIR_MASK);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
// add last vertex twice
ddx = (int) (-(ux + vx) * DIR_SCALE);
ddy = (int) (-(uy + vy) * DIR_SCALE);
dx = (short) (2 | ddx & DIR_MASK);
dy = (short) (0 | ddy & DIR_MASK);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
} else {
if (squared) {
vx = 0;
vy = 0;
} else if (!outside) {
vx *= 0.5;
vy *= 0.5;
}
if (rounded)
verticesCnt -= 2;
ddx = (int) ((ux - vx) * DIR_SCALE);
ddy = (int) ((uy - vy) * DIR_SCALE);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = (short) (0 | ddx & DIR_MASK);
v[opos++] = (short) (1 | ddy & DIR_MASK);
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
// add last vertex twice
ddx = (int) (-(ux + vx) * DIR_SCALE);
ddy = (int) (-(uy + vy) * DIR_SCALE);
dx = (short) (2 | ddx & DIR_MASK);
dy = (short) (1 | ddy & DIR_MASK);
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
if (opos == ShortItem.SIZE) {
si = si.next = ShortPool.get();
v = si.vertices;
opos = 0;
}
v[opos++] = ox;
v[opos++] = oy;
v[opos++] = dx;
v[opos++] = dy;
}
pos += length;
}
si.used = opos;
curItem = si;
}
}

Some files were not shown because too many files have changed in this diff Show More