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"?>
<resources>
<string name="stop_routing">Stop routing</string>
<string name="sd_unmounted">Карточка SD недоступна. \nВы не сможете работать с картой.</string>
<string name="sd_mounted_ro">Карточка SD доступна только для чтения. \nВы не сможете загружать карты из интернета.</string>
<string name="unzipping_file">Файл распаковывается</string>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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_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>

View file

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

View file

@ -57,14 +57,14 @@ public class RouteProvider {
private int[] listDistance = null;
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.errorMessage = errorMessage;
this.locations = list;
if (list != null) {
prepareResult();
prepareResult(start, end);
}
}
@ -80,7 +80,41 @@ public class RouteProvider {
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()];
if (!locations.isEmpty()) {
listDistance[locations.size() - 1] = 0;
@ -121,11 +155,11 @@ public class RouteProvider {
RouteCalculationResult res;
if (type == RouteService.YOURS) {
res = findYOURSRoute(start, end, mode);
addMissingTurnsToRoute(res, mode, ctx);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else {
res = findCloudMadeRoute(start, end, mode);
res = findCloudMadeRoute(start, end, mode, ctx);
// for test purpose
addMissingTurnsToRoute(res, mode, ctx);
addMissingTurnsToRoute(res, start, end, mode, ctx);
}
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$
@ -149,7 +183,7 @@ public class RouteProvider {
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()){
return;
}
@ -164,6 +198,8 @@ public class RouteProvider {
minDistanceForTurn = 12;
}
// add start point if needed
List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>();
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 {
List<Location> res = new ArrayList<Location>();
List<RouteDirectionInfo> directions = null;
@ -506,8 +542,7 @@ public class RouteProvider {
}
return new RouteCalculationResult(res, directions, null);
return new RouteCalculationResult(res, directions, start, end, null);
}
private String getContentFromNode(Element item, String tagName){

View file

@ -165,10 +165,22 @@ public class RoutingHelper {
boolean proccesed = false;
if (newDist < dist){
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$
}
proccesed = true;
} else {
// case if you are getting close to the next point after turn
// 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.setShowPoiOverMap(SearchPOIActivity.this, true);
}
int z = OsmandSettings.getLastKnownMapZoom(this);
Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
OsmandSettings.setMapLocationToShow(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), 16,
getString(R.string.poi)+" : " + amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(this))); //$NON-NLS-1$
OsmandSettings.setMapLocationToShow(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(),
Math.max(16, z), getString(R.string.poi)+" : " + amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(this))); //$NON-NLS-1$
Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class);
startActivity(newIntent);
}
@ -439,7 +440,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
public void setNewModel(List<Amenity> amenityList) {
setNotifyOnChange(false);
((AmenityAdapter) getListAdapter()).clear();
clear();
for (Amenity obj : amenityList) {
this.add(obj);
}

View file

@ -1,5 +1,7 @@
package com.osmand.views;
import android.util.FloatMath;
import com.osmand.osm.MapUtils;
/**
@ -181,19 +183,22 @@ public class AnimateDraggingMapThread implements Runnable {
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();
this.notifyListener = notifyListener;
curZ = curZoom;
intZ = curZoom;
moveX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize);
moveY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize);
float mX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize);
float mY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize);
// 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--;
moveX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * tileSize);
moveY = (float) ((MapUtils.getTileNumberY(intZ, curLat) - MapUtils.getTileNumberY(intZ, finalLat)) * tileSize);
mX = (float) ((MapUtils.getTileNumberX(intZ, curLon) - MapUtils.getTileNumberX(intZ, finalLon)) * 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){
dirIntZ = 1;
} else {
@ -209,6 +214,9 @@ public class AnimateDraggingMapThread implements Runnable {
endZ = endZoom;
timeZInt = Math.abs(curZoom - intZ) * 300;
if (timeZInt > 1200) {
timeZInt = 1200;
}
timeZEnd = 500;
timeMove = (int) (Math.abs(moveX) + Math.abs(moveY) * 4);
if(timeMove > 2000){

View file

@ -446,7 +446,7 @@ public class MapInfoLayer implements OsmandMapLayer {
if(pointToNavigate != null){
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
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;