fix small issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@319 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-11 22:30:41 +00:00
parent 0d3650e693
commit d5692b938e
8 changed files with 103 additions and 31 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="stop_routing">Stop routing</string>
<string name="sd_unmounted">Карточка SD недоступна. \nВы не сможете работать с картой.</string> <string name="sd_unmounted">Карточка SD недоступна. \nВы не сможете работать с картой.</string>
<string name="sd_mounted_ro">Карточка SD доступна только для чтения. \nВы не сможете загружать карты из интернета.</string> <string name="sd_mounted_ro">Карточка SD доступна только для чтения. \nВы не сможете загружать карты из интернета.</string>
<string name="unzipping_file">Файл распаковывается</string> <string name="unzipping_file">Файл распаковывается</string>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="stop_routing">Отменить маршрут</string>
<string name="sd_unmounted">SD card is not accessible. \nYou can\'t see map and find anything.</string> <string name="sd_unmounted">SD card is not accessible. \nYou can\'t see map and find anything.</string>
<string name="sd_mounted_ro">SD card is read-only accessible. \nYou can see only preloaded map and can\'t download from internet.</string> <string name="sd_mounted_ro">SD card is read-only accessible. \nYou can see only preloaded map and can\'t download from internet.</string>
<string name="unzipping_file">File is unzipping</string> <string name="unzipping_file">File is unzipping</string>

View file

@ -264,7 +264,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
int fZoom = mapView.getZoom() < 15 ? 15 : mapView.getZoom(); int fZoom = mapView.getZoom() < 15 ? 15 : mapView.getZoom();
thread.startMoving(mapView.getLatitude(), mapView.getLongitude(), thread.startMoving(mapView.getLatitude(), mapView.getLongitude(),
lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), mapView.getZoom(), fZoom, lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), mapView.getZoom(), fZoom,
mapView.getSourceTileSize(), false); mapView.getSourceTileSize(), mapView.getRotate(), false);
} }
} }
} }
@ -656,7 +656,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
if(latLon != null && !latLon.equals(cur)){ if(latLon != null && !latLon.equals(cur)){
mapView.getAnimatedDraggingThread().startMoving(cur.getLatitude(), cur.getLongitude(), mapView.getAnimatedDraggingThread().startMoving(cur.getLatitude(), cur.getLongitude(),
latLon.getLatitude(), latLon.getLongitude(), latLon.getLatitude(), latLon.getLongitude(),
mapView.getZoom(), OsmandSettings.getMapZoomToShow(this), mapView.getSourceTileSize(), true); mapView.getZoom(), OsmandSettings.getMapZoomToShow(this),
mapView.getSourceTileSize(), mapView.getRotate(), true);
} }
} }
checkExternalStorage(); checkExternalStorage();
@ -739,6 +740,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private void updateNavigateToPointMenu(){ private void updateNavigateToPointMenu(){
if (navigateToPointMenu != null) { if (navigateToPointMenu != null) {
navigateToPointMenu.setTitle(routingHelper.isFollowingMode() ? R.string.stop_routing : R.string.stop_navigation);
if (OsmandSettings.getPointToNavigate(this) != null) { if (OsmandSettings.getPointToNavigate(this) != null) {
navigateToPointMenu.setVisible(true); navigateToPointMenu.setVisible(true);
} else { } else {
@ -785,7 +787,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
return true; return true;
} else if (item.getItemId() == R.id.map_navigate_to_point) { } else if (item.getItemId() == R.id.map_navigate_to_point) {
if(navigationLayer.getPointToNavigate() != null){ if(navigationLayer.getPointToNavigate() != null){
navigateToPoint(null); if(routingHelper.getFinalLocation() != null){
routingHelper.setFinalAndCurrentLocation(null, null);
routingHelper.setFollowingMode(false);
mapView.refreshMap();
updateNavigateToPointMenu();
} else {
navigateToPoint(null);
}
} else { } else {
navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude())); navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude()));
} }
@ -804,11 +813,15 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
builder.setPositiveButton(R.string.follow, new DialogInterface.OnClickListener(){ builder.setPositiveButton(R.string.follow, new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Location map = new Location("map"); //$NON-NLS-1$ Location location = locationLayer.getLastKnownLocation();
map.setLatitude(lat); if(location == null){
map.setLongitude(lon); location = new Location("map"); //$NON-NLS-1$
location.setLatitude(lat);
location.setLongitude(lon);
}
routingHelper.setFollowingMode(true); routingHelper.setFollowingMode(true);
routingHelper.setFinalAndCurrentLocation(navigationLayer.getPointToNavigate(), map); routingHelper.setFinalAndCurrentLocation(navigationLayer.getPointToNavigate(), location);
updateNavigateToPointMenu();
} }
}); });
if(routingHelper.isRouterEnabled()){ if(routingHelper.isRouterEnabled()){
@ -828,6 +841,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
map.setLatitude(lat); map.setLatitude(lat);
map.setLongitude(lon); map.setLongitude(lon);
routingHelper.setFollowingMode(false); routingHelper.setFollowingMode(false);
updateNavigateToPointMenu();
routingHelper.setFinalAndCurrentLocation(navigationLayer.getPointToNavigate(), map); routingHelper.setFinalAndCurrentLocation(navigationLayer.getPointToNavigate(), map);
} }
}); });

View file

@ -57,14 +57,14 @@ public class RouteProvider {
private int[] listDistance = null; private int[] listDistance = null;
public RouteCalculationResult(String errorMessage) { public RouteCalculationResult(String errorMessage) {
this(null, null, errorMessage); this(null, null, null, null, errorMessage);
} }
public RouteCalculationResult(List<Location> list, List<RouteDirectionInfo> directions, String errorMessage) { public RouteCalculationResult(List<Location> list, List<RouteDirectionInfo> directions, Location start, LatLon end, String errorMessage) {
this.directions = directions; this.directions = directions;
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
this.locations = list; this.locations = list;
if (list != null) { if (list != null) {
prepareResult(); prepareResult(start, end);
} }
} }
@ -80,7 +80,41 @@ public class RouteProvider {
return listDistance; return listDistance;
} }
private void prepareResult() { private void prepareResult(Location start, LatLon end) {
if (locations != null && !locations.isEmpty()) {
// if there is no closest points to start - add it
if (locations.get(0).distanceTo(start) > 200) {
// add start point
locations.add(0, start);
}
if (directions != null) {
for (RouteDirectionInfo i : directions) {
i.routePointOffset++;
}
RouteDirectionInfo info = new RouteDirectionInfo();
info.turnType = TurnType.valueOf(TurnType.C);
info.routePointOffset = 0;
info.descriptionRoute = "" ;//getString(ctx, R.string.route_head); //$NON-NLS-1$
directions.add(0, info);
}
// check points for duplicates (it is very bad for routing) - cloudmade could return it
for (int i = 0; i < locations.size() - 1; ) {
if(locations.get(i).distanceTo(locations.get(i+1)) == 0){
locations.remove(i);
if (directions != null) {
for (RouteDirectionInfo info : directions) {
if(info.routePointOffset > i){
info.routePointOffset--;
}
}
}
} else {
i++;
}
}
}
listDistance = new int[locations.size()]; listDistance = new int[locations.size()];
if (!locations.isEmpty()) { if (!locations.isEmpty()) {
listDistance[locations.size() - 1] = 0; listDistance[locations.size() - 1] = 0;
@ -121,11 +155,11 @@ public class RouteProvider {
RouteCalculationResult res; RouteCalculationResult res;
if (type == RouteService.YOURS) { if (type == RouteService.YOURS) {
res = findYOURSRoute(start, end, mode); res = findYOURSRoute(start, end, mode);
addMissingTurnsToRoute(res, mode, ctx); addMissingTurnsToRoute(res, start, end, mode, ctx);
} else { } else {
res = findCloudMadeRoute(start, end, mode); res = findCloudMadeRoute(start, end, mode, ctx);
// for test purpose // for test purpose
addMissingTurnsToRoute(res, mode, ctx); addMissingTurnsToRoute(res, start, end, mode, ctx);
} }
if(log.isInfoEnabled() && res.locations != null){ if(log.isInfoEnabled() && res.locations != null){
log.info("Finding route contained " + res.locations.size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ log.info("Finding route contained " + res.locations.size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -149,7 +183,7 @@ public class RouteProvider {
return ctx.getString(resId); return ctx.getString(resId);
} }
protected void addMissingTurnsToRoute(RouteCalculationResult res, ApplicationMode mode, Context ctx){ protected void addMissingTurnsToRoute(RouteCalculationResult res, Location start, LatLon end, ApplicationMode mode, Context ctx){
if(!res.isCalculated()){ if(!res.isCalculated()){
return; return;
} }
@ -164,6 +198,8 @@ public class RouteProvider {
minDistanceForTurn = 12; minDistanceForTurn = 12;
} }
// add start point if needed
List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>(); List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>();
int[] listDistance = res.getListDistance(); int[] listDistance = res.getListDistance();
@ -386,11 +422,11 @@ public class RouteProvider {
} }
} }
return new RouteCalculationResult(res, null, null); return new RouteCalculationResult(res, null, start, end, null);
} }
protected RouteCalculationResult findCloudMadeRoute(Location start, LatLon end, ApplicationMode mode) throws MalformedURLException, IOException, protected RouteCalculationResult findCloudMadeRoute(Location start, LatLon end, ApplicationMode mode, Context ctx) throws MalformedURLException, IOException,
ParserConfigurationException, FactoryConfigurationError, SAXException { ParserConfigurationException, FactoryConfigurationError, SAXException {
List<Location> res = new ArrayList<Location>(); List<Location> res = new ArrayList<Location>();
List<RouteDirectionInfo> directions = null; List<RouteDirectionInfo> directions = null;
@ -506,8 +542,7 @@ public class RouteProvider {
} }
return new RouteCalculationResult(res, directions, start, end, null);
return new RouteCalculationResult(res, directions, null);
} }
private String getContentFromNode(Element item, String tagName){ private String getContentFromNode(Element item, String tagName){

View file

@ -165,10 +165,22 @@ public class RoutingHelper {
boolean proccesed = false; boolean proccesed = false;
if (newDist < dist){ if (newDist < dist){
if(newDist > 150){ if(newDist > 150){
if(log.isDebugEnabled()){ // may be that check is really not needed ? only for start position
if(currentRoute > 0 ){
// check that we are not far from the route (if we are on the route distance doesn't matter)
float bearing = routeNodes.get(currentRoute - 1).bearingTo(routeNodes.get(currentRoute));
float bearingMovement = currentLocation.bearingTo(routeNodes.get(currentRoute));
float d = Math.abs(currentLocation.distanceTo(routeNodes.get(currentRoute)) * FloatMath.sin((bearingMovement - bearing)*3.14f/180f));
if(d > 50){
proccesed = true;
}
} else {
proccesed = true;
}
if(proccesed && log.isDebugEnabled()){
log.debug("Processed distance : " + newDist + " " + dist); //$NON-NLS-1$//$NON-NLS-2$ log.debug("Processed distance : " + newDist + " " + dist); //$NON-NLS-1$//$NON-NLS-2$
} }
proccesed = true;
} else { } else {
// case if you are getting close to the next point after turn // case if you are getting close to the next point after turn
// but you haven't turned before (could be checked bearing) // but you haven't turned before (could be checked bearing)

View file

@ -355,9 +355,10 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
OsmandSettings.setPoiFilterForMap(SearchPOIActivity.this, filter.getFilterId()); OsmandSettings.setPoiFilterForMap(SearchPOIActivity.this, filter.getFilterId());
OsmandSettings.setShowPoiOverMap(SearchPOIActivity.this, true); OsmandSettings.setShowPoiOverMap(SearchPOIActivity.this, true);
} }
int z = OsmandSettings.getLastKnownMapZoom(this);
Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position); Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
OsmandSettings.setMapLocationToShow(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), 16, OsmandSettings.setMapLocationToShow(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(),
getString(R.string.poi)+" : " + amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(this))); //$NON-NLS-1$ Math.max(16, z), getString(R.string.poi)+" : " + amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(this))); //$NON-NLS-1$
Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class); Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class);
startActivity(newIntent); startActivity(newIntent);
} }
@ -439,7 +440,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
public void setNewModel(List<Amenity> amenityList) { public void setNewModel(List<Amenity> amenityList) {
setNotifyOnChange(false); setNotifyOnChange(false);
((AmenityAdapter) getListAdapter()).clear(); clear();
for (Amenity obj : amenityList) { for (Amenity obj : amenityList) {
this.add(obj); this.add(obj);
} }

View file

@ -1,5 +1,7 @@
package com.osmand.views; package com.osmand.views;
import android.util.FloatMath;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
/** /**
@ -181,19 +183,22 @@ public class AnimateDraggingMapThread implements Runnable {
thread.start(); thread.start();
} }
public void startMoving(double curLat, double curLon, double finalLat, double finalLon, int curZoom, int endZoom, int tileSize, boolean notifyListener){ public void startMoving(double curLat, double curLon, double finalLat, double finalLon, int curZoom, int endZoom, int tileSize, float rotate, boolean notifyListener){
stopAnimatingSync(); stopAnimatingSync();
this.notifyListener = notifyListener; this.notifyListener = notifyListener;
curZ = curZoom; curZ = curZoom;
intZ = curZoom; intZ = curZoom;
moveX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize); float mX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize);
moveY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize); float mY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize);
// todo calculate right with rotated map!!! // todo calculate right with rotated map!!!
while (Math.abs(moveX) + Math.abs(moveY) > 1200 && intZ > 4) { while (Math.abs(mX) + Math.abs(mY) > 1200 && intZ > 4) {
intZ--; intZ--;
moveX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize); mX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize);
moveY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize); mY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize);
} }
float rad = (float) Math.toRadians(rotate);
moveX = FloatMath.cos(rad) * mX - FloatMath.sin(rad) * mY;
moveY = FloatMath.sin(rad) * mX + FloatMath.cos(rad) * mY;
if(curZoom < intZ){ if(curZoom < intZ){
dirIntZ = 1; dirIntZ = 1;
} else { } else {
@ -209,6 +214,9 @@ public class AnimateDraggingMapThread implements Runnable {
endZ = endZoom; endZ = endZoom;
timeZInt = Math.abs(curZoom - intZ) * 300; timeZInt = Math.abs(curZoom - intZ) * 300;
if (timeZInt > 1200) {
timeZInt = 1200;
}
timeZEnd = 500; timeZEnd = 500;
timeMove = (int) (Math.abs(moveX) + Math.abs(moveY) * 4); timeMove = (int) (Math.abs(moveX) + Math.abs(moveY) * 4);
if(timeMove > 2000){ if(timeMove > 2000){

View file

@ -446,7 +446,7 @@ public class MapInfoLayer implements OsmandMapLayer {
if(pointToNavigate != null){ if(pointToNavigate != null){
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom(); int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
thread.startMoving(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), thread.startMoving(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), pointToNavigate.getLongitude(),
view.getZoom(), fZoom, view.getSourceTileSize(), true); view.getZoom(), fZoom, view.getSourceTileSize(), view.getRotate(), true);
} }
} }
return false; return false;