fixing bugs implementing
first cut map git-svn-id: https://osmand.googlecode.com/svn/trunk@479 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
314216b763
commit
3171e9f781
4 changed files with 96 additions and 64 deletions
|
@ -10,7 +10,6 @@ import java.text.MessageFormat;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.NativeLibrary;
|
||||
import net.osmand.ProgressDialogImplementation;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
|
@ -56,7 +55,6 @@ public class MainMenuActivity extends Activity {
|
|||
|
||||
|
||||
public void startApplication(){
|
||||
System.out.println("NATIVE : " + new NativeLibrary().stringFromJNI());
|
||||
if(!applicationAlreadyStarted){
|
||||
// Algoritms.removeAllFiles(new File(Environment.getExternalStorageDirectory(), "/osmand/tiles/Mapnik/18"));
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.osmand.LogUtil;
|
|||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.R;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.views.OsmandMapTileView;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
|
@ -72,6 +73,8 @@ public class NavigatePointActivity extends Activity {
|
|||
}
|
||||
|
||||
public void initUI(double latitude, double longitude){
|
||||
latitude = MapUtils.checkLatitude(latitude);
|
||||
longitude = MapUtils.checkLongitude(longitude);
|
||||
((TextView)findViewById(R.id.LatitudeEdit)).setText(convert(latitude, Location.FORMAT_DEGREES));
|
||||
((TextView)findViewById(R.id.LongitudeEdit)).setText(convert(longitude, Location.FORMAT_DEGREES));
|
||||
((RadioButton)findViewById(R.id.Format1)).setChecked(true);
|
||||
|
|
|
@ -89,6 +89,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
private ListPreference routeServiceInterval;
|
||||
private ListPreference routeServiceWaitInterval;
|
||||
private ListPreference routeServiceProvider;
|
||||
|
||||
private CheckBoxPreference routeServiceEnabled;
|
||||
|
||||
private ProgressDialog progressDlg;
|
||||
|
@ -117,9 +118,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
addPreferencesFromResource(R.xml.settings_pref);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
|
||||
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
|
||||
applicationMode.setOnPreferenceChangeListener(this);
|
||||
|
||||
for(BooleanPreference b : booleanPreferences){
|
||||
CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId());
|
||||
p.setOnPreferenceChangeListener(this);
|
||||
|
@ -138,7 +136,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
userPassword = (EditTextPreference) screen.findPreference(OsmandSettings.USER_PASSWORD);
|
||||
userPassword.setOnPreferenceChangeListener(this);
|
||||
|
||||
|
||||
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
|
||||
applicationMode.setOnPreferenceChangeListener(this);
|
||||
rotateMap =(ListPreference) screen.findPreference(OsmandSettings.ROTATE_MAP);
|
||||
rotateMap.setOnPreferenceChangeListener(this);
|
||||
saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL);
|
||||
|
@ -155,13 +154,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
routerPreference.setOnPreferenceChangeListener(this);
|
||||
voicePreference =(ListPreference) screen.findPreference(OsmandSettings.VOICE_PROVIDER);
|
||||
voicePreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
routeServiceInterval =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_INTERVAL);
|
||||
routeServiceInterval.setOnPreferenceChangeListener(this);
|
||||
routeServiceWaitInterval =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL);
|
||||
routeServiceWaitInterval.setOnPreferenceChangeListener(this);
|
||||
routeServiceProvider =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_PROVIDER);
|
||||
routeServiceProvider.setOnPreferenceChangeListener(this);
|
||||
|
||||
routeServiceEnabled =(CheckBoxPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_ENABLED);
|
||||
routeServiceEnabled.setOnPreferenceChangeListener(this);
|
||||
|
||||
|
|
|
@ -1,51 +1,72 @@
|
|||
package net.osmand.render;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.data.index.IndexConstants;
|
||||
import net.osmand.osm.Node;
|
||||
import net.osmand.osm.Way;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
public class RenderMapsRepositories {
|
||||
|
||||
private final static Log log = LogUtil.getLog(RenderMapsRepositories.class);
|
||||
private SQLiteDatabase db;
|
||||
// private SQLiteDatabase db;
|
||||
private Connection conn;
|
||||
private double cTopLatitude;
|
||||
private double cBottomLatitude;
|
||||
private int cZoom;
|
||||
private double cLeftLongitude;
|
||||
private double cRightLongitude;
|
||||
private List<Way> cWays = new LinkedList<Way>();
|
||||
private PreparedStatement pStatement;
|
||||
|
||||
|
||||
public boolean initializeNewResource(final IProgress progress, File file) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
// TODO should support multiple db
|
||||
if(db != null){
|
||||
// close previous db
|
||||
db.close();
|
||||
}
|
||||
db = SQLiteDatabase.openOrCreateDatabase(file, null);
|
||||
|
||||
if(db.getVersion() != IndexConstants.MAP_TABLE_VERSION){
|
||||
db.close();
|
||||
db = null;
|
||||
// db = SQLiteDatabase.openOrCreateDatabase(file, null);
|
||||
//
|
||||
// if(db.getVersion() != IndexConstants.MAP_TABLE_VERSION){
|
||||
// db.close();
|
||||
// db = null;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// TODO should support multiple db
|
||||
if (conn != null) {
|
||||
// close previous db
|
||||
conn.close();
|
||||
conn = null;
|
||||
pStatement = null;
|
||||
}
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
} catch (Exception e) {
|
||||
log.error("Could not load driver", e);
|
||||
return false;
|
||||
}
|
||||
conn = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
|
||||
pStatement = conn.prepareStatement(loadMapQuery);
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.error("No connection", e);
|
||||
return false;
|
||||
} catch (java.sql.SQLException e) {
|
||||
log.error("No connection", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} catch(SQLException e){
|
||||
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
@ -59,18 +80,26 @@ public class RenderMapsRepositories {
|
|||
|
||||
|
||||
public void clearAllResources(){
|
||||
if(db != null){
|
||||
// close previous db
|
||||
db.close();
|
||||
db = null;
|
||||
if(conn != null){
|
||||
try {
|
||||
conn.close();
|
||||
} catch (java.sql.SQLException e) {
|
||||
}
|
||||
conn = null;
|
||||
pStatement = null;
|
||||
}
|
||||
// if(db != null){
|
||||
// // close previous db
|
||||
// db.close();
|
||||
// db = null;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if no need to reevaluate map
|
||||
*/
|
||||
public boolean updateMap(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom){
|
||||
if (db == null) {
|
||||
if (conn == null) {
|
||||
return true;
|
||||
}
|
||||
boolean inside = cTopLatitude >= topLatitude && cLeftLongitude <= leftLongitude && cRightLongitude >= rightLongitude
|
||||
|
@ -78,6 +107,10 @@ public class RenderMapsRepositories {
|
|||
return inside;
|
||||
}
|
||||
|
||||
|
||||
private static String loadMapQuery = "SELECT "+IndexConstants.IndexMapWays.ID +", " + IndexConstants.IndexMapWays.NODES +", " + IndexConstants.IndexMapWays.TAGS +
|
||||
" FROM " + IndexConstants.IndexMapWays.getTable() + " WHERE "+IndexConstants.IndexMapWays.ID+" IN (SELECT id FROM "+IndexConstants.indexMapLocationsTable + //$NON-NLS-1$
|
||||
" WHERE ? < maxLat AND ? > minLat AND maxLon > ? AND minLon < ?)"; //$NON-NLS-1$
|
||||
|
||||
public void loadMap(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom) {
|
||||
cBottomLatitude = bottomLatitude - (topLatitude - bottomLatitude) / 2;
|
||||
|
@ -86,51 +119,50 @@ public class RenderMapsRepositories {
|
|||
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude) / 2;
|
||||
cZoom = zoom;
|
||||
|
||||
// String query = "SELECT ways.id way, node.id node, node.latitude, node.longitude FROM (" + //$NON-NLS-1$
|
||||
// "SELECT DISTINCT ways.id id FROM ways JOIN " + //$NON-NLS-1$
|
||||
// "(SELECT id, latitude, longitude FROM node WHERE ?< latitude AND latitude < ? AND ? < longitude AND longitude < ?) A "+ //$NON-NLS-1$
|
||||
// "ON A.id = ways.node) B "+ //$NON-NLS-1$
|
||||
// "JOIN ways ON B.id=ways.id JOIN node ON ways.node = node.id"; //$NON-NLS-1$
|
||||
|
||||
log.info(String.format(
|
||||
"BLat=%s, TLat=%s, LLong=%s, RLong=%s, zoom=%s", cBottomLatitude, cTopLatitude, cLeftLongitude, cRightLongitude, zoom)); //$NON-NLS-1$
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
// String query = "SELECT id, tags, nodes FROM ways WHERE ? < latitude AND latitude < ? AND ? < longitude AND longitude < ? "; //$NON-NLS-1$
|
||||
String query = "SELECT id FROM "+IndexConstants.indexMapLocationsTable + //$NON-NLS-1$
|
||||
" WHERE ? < maxLat AND ? > minLat AND maxLon > ? AND minLon < ?"; //$NON-NLS-1$
|
||||
|
||||
Cursor result = db.rawQuery(query, new String[]{Double.toString(cBottomLatitude),Double.toString(cTopLatitude),
|
||||
Double.toString(cLeftLongitude), Double.toString(cRightLongitude)});
|
||||
|
||||
List<Way> local = new LinkedList<Way>();
|
||||
if(pStatement == null){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int count = 0;
|
||||
if (result.moveToFirst()) {
|
||||
do {
|
||||
long id = result.getLong(0);
|
||||
pStatement.setDouble(1, cBottomLatitude);
|
||||
pStatement.setDouble(2, cTopLatitude);
|
||||
pStatement.setDouble(3, cLeftLongitude);
|
||||
pStatement.setDouble(4, cRightLongitude);
|
||||
ResultSet result = pStatement.executeQuery();
|
||||
|
||||
List<Way> local = new LinkedList<Way>();
|
||||
try {
|
||||
int count = 0;
|
||||
while (result.next()) {
|
||||
long id = result.getLong(1);
|
||||
Way way = new Way(id);
|
||||
// JSONArray nodes;
|
||||
// try {
|
||||
// nodes = new JSONArray(result.getString(2));
|
||||
// for (int i = 0; i < nodes.length(); i++) {
|
||||
// JSONArray obj = nodes.getJSONArray(i);
|
||||
// Node node = new Node(obj.getDouble(1), obj.getDouble(2), obj.getLong(0));
|
||||
// way.addNode(node);
|
||||
// }
|
||||
//
|
||||
// } catch (JSONException e) {
|
||||
// }
|
||||
JSONArray nodes;
|
||||
try {
|
||||
nodes = new JSONArray(result.getString(2));
|
||||
for (int i = 0; i < nodes.length(); i++) {
|
||||
JSONArray obj = nodes.getJSONArray(i);
|
||||
Node node = new Node(obj.getDouble(1), obj.getDouble(2), obj.getLong(0));
|
||||
way.addNode(node);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
count++;
|
||||
// local.add(way);
|
||||
} while (result.moveToNext());
|
||||
|
||||
local.add(way);
|
||||
}
|
||||
|
||||
cWays = local;
|
||||
log.info(String.format("Search has been done in %s ms. %s results were found.", System.currentTimeMillis() - now, count)); //$NON-NLS-1$
|
||||
} finally {
|
||||
result.close();
|
||||
}
|
||||
log.info(String.format("Search has been done in %s ms. %s results were found.", System.currentTimeMillis()-now, count)); //$NON-NLS-1$
|
||||
} finally {
|
||||
result.close();
|
||||
} catch (java.sql.SQLException e) {
|
||||
log.debug("Search failed", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue