Support maxspeed:forward /backward
This commit is contained in:
parent
d065ba8c3e
commit
27385b6664
6 changed files with 38 additions and 7 deletions
|
@ -57,6 +57,7 @@ public class BinaryMapRouteReaderAdapter {
|
|||
private float floatValue;
|
||||
private int type;
|
||||
private List<RouteTypeCondition> conditions = null;
|
||||
private int forward;
|
||||
|
||||
public RouteTypeRule(String t, String v) {
|
||||
this.t = t.intern();
|
||||
|
@ -75,6 +76,10 @@ public class BinaryMapRouteReaderAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
public int isForward() {
|
||||
return forward;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return t;
|
||||
}
|
||||
|
@ -174,6 +179,14 @@ public class BinaryMapRouteReaderAdapter {
|
|||
} else if(t.equalsIgnoreCase("maxspeed") && v != null){
|
||||
type = MAXSPEED;
|
||||
floatValue = RouteDataObject.parseSpeed(v, 0);
|
||||
} else if(t.equalsIgnoreCase("maxspeed:forward") && v != null){
|
||||
type = MAXSPEED;
|
||||
forward = 1;
|
||||
floatValue = RouteDataObject.parseSpeed(v, 0);
|
||||
} else if(t.equalsIgnoreCase("maxspeed:backward") && v != null){
|
||||
type = MAXSPEED;
|
||||
forward = -1;
|
||||
floatValue = RouteDataObject.parseSpeed(v, 0);
|
||||
} else if (t.equalsIgnoreCase("lanes") && v != null) {
|
||||
intValue = -1;
|
||||
int i = 0;
|
||||
|
|
|
@ -204,11 +204,16 @@ public class RouteDataObject {
|
|||
return types;
|
||||
}
|
||||
|
||||
public float getMaximumSpeed(){
|
||||
public float getMaximumSpeed(boolean direction){
|
||||
int sz = types.length;
|
||||
float maxSpeed = 0;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
RouteTypeRule r = region.quickGetEncodingRule(types[i]);
|
||||
if(r.isForward() != 0) {
|
||||
if((r.isForward() > 1) != direction) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
float mx = r.maxSpeed();
|
||||
if (mx > 0) {
|
||||
maxSpeed = mx;
|
||||
|
|
|
@ -310,7 +310,7 @@ public class RouteResultPreparation {
|
|||
additional.append("rtime = \"").append(res.getRoutingTime()).append("\" ");
|
||||
additional.append("name = \"").append(name).append("\" ");
|
||||
// float ms = res.getSegmentSpeed();
|
||||
float ms = res.getObject().getMaximumSpeed();
|
||||
float ms = res.getObject().getMaximumSpeed(res.isForwardDirection());
|
||||
if(ms > 0) {
|
||||
additional.append("maxspeed = \"").append(ms * 3.6f).append("\" ").append(res.getObject().getHighway()).append(" ");
|
||||
}
|
||||
|
|
|
@ -11,14 +11,13 @@ import java.util.List;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.Amenity.AmenityRoutePoint;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -258,7 +257,13 @@ public class WaypointHelper {
|
|||
|
||||
public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc,
|
||||
MetricsConstants mc, boolean showCameras) {
|
||||
float mxspeed = ro.getMaximumSpeed();
|
||||
boolean direction = true;
|
||||
if(loc.hasBearing()) {
|
||||
double diff = MapUtils.alignAngleDifference(ro.directionRoute(0, true) -
|
||||
loc.getBearing() / (2 * Math.PI));
|
||||
direction = Math.abs(diff) < Math.PI;
|
||||
}
|
||||
float mxspeed = ro.getMaximumSpeed(direction);
|
||||
float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
|
||||
AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta);
|
||||
if (speedAlarm != null) {
|
||||
|
|
|
@ -666,7 +666,7 @@ public class RouteCalculationResult {
|
|||
public float getCurrentMaxSpeed() {
|
||||
RouteSegmentResult res = getCurrentSegmentResult();
|
||||
if(res != null) {
|
||||
return res.getObject().getMaximumSpeed();
|
||||
return res.getObject().getMaximumSpeed(res.isForwardDirection());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import net.osmand.plus.views.controls.MapRouteInfoControl;
|
|||
import net.osmand.router.RouteResultPreparation;
|
||||
import net.osmand.router.TurnType;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
|
@ -298,7 +299,14 @@ public class RouteInfoWidgetsFactory {
|
|||
if ((rh == null || !rh.isFollowingMode()) && trackingUtilities.isMapLinkedToLocation()) {
|
||||
RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
|
||||
if(ro != null) {
|
||||
mx = ro.getMaximumSpeed();
|
||||
boolean direction = true;
|
||||
Location loc = locationProvider.getLastKnownLocation();
|
||||
if(loc != null && loc.hasBearing()) {
|
||||
double diff = MapUtils.alignAngleDifference(ro.directionRoute(0, true) -
|
||||
loc.getBearing() / (2 * Math.PI));
|
||||
direction = Math.abs(diff) < Math.PI;
|
||||
}
|
||||
mx = ro.getMaximumSpeed(direction);
|
||||
}
|
||||
} else {
|
||||
mx = rh.getCurrentMaxSpeed();
|
||||
|
|
Loading…
Reference in a new issue