Add Alarm info

This commit is contained in:
Victor Shcherb 2012-07-10 00:33:50 +02:00
parent cb631db11e
commit 2d53daa8e2
6 changed files with 117 additions and 33 deletions

View file

@ -158,13 +158,13 @@ public class RouteDataObject {
return false;
}
public int getOneway(){
public int getOneway() {
int sz = types.length;
for(int i=0; i<sz; i++) {
for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if(r.onewayDirection() != 0) {
if (r.onewayDirection() != 0) {
return r.onewayDirection();
} else if(r.roundabout()) {
} else if (r.roundabout()) {
return 1;
}
}

View file

@ -51,6 +51,7 @@ public class MapRoutingTypes {
TAGS_TO_SAVE.add("route");
TAGS_TO_SAVE.add("service");
TAGS_TO_SAVE.add("toll");
TAGS_TO_SAVE.add("toll_booth");
TAGS_TO_SAVE.add("tracktype");
TAGS_TO_SAVE.add("traffic_calming");
TAGS_TO_SAVE.add("turn:lanes");

View file

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.android.ide.eclipse.adt.debug.LaunchConfigType">
<intAttribute key="com.android.ide.eclipse.adt.action" value="0"/>
<stringAttribute key="com.android.ide.eclipse.adt.commandline" value=""/>
<intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/>
<booleanAttribute key="com.android.ide.eclipse.adt.nobootanim" value="false"/>
<intAttribute key="com.android.ide.eclipse.adt.speed" value="0"/>
<booleanAttribute key="com.android.ide.eclipse.adt.target" value="true"/>
<booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/OsmAnd"/>
<listEntry value="/OsmAnd/AndroidManifest.xml"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ALLOW_TERMINATE" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="OsmAnd"/>
</launchConfiguration>

View file

@ -0,0 +1,81 @@
package net.osmand.plus.routing;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
public class AlarmInfo {
public static int SPEED_CAMERA = 1;
public static int SPEED_LIMIT = SPEED_CAMERA + 1;
public static int BORDER_CONTROL = SPEED_LIMIT + 1;
public static int BARRIER = BORDER_CONTROL + 1;
public static int TRAFFIC_CALMING = BARRIER + 1;
public static int TOLL_BOOTH = TRAFFIC_CALMING + 1;
public static int STOP = TOLL_BOOTH + 1;
private int type;
private float distance;
private float time;
protected final int locationIndex;
private int intValue;
public AlarmInfo(int type, int locationIndex){
this.type = type;
this.locationIndex = locationIndex;
}
public float getDistance() {
return distance;
}
public float getTime() {
return time;
}
public void setTime(float time) {
this.time = time;
}
public void setDistance(float distance) {
this.distance = distance;
}
public int getType() {
return type;
}
public int getIntValue() {
return intValue;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
public boolean isSpeedLimit(){
return type == SPEED_LIMIT;
}
public boolean isSpeedCamera(){
return type == SPEED_CAMERA;
}
public static AlarmInfo createAlarmInfo(RouteTypeRule ruleType, int locInd) {
if("highway".equals(ruleType.getTag())) {
if("speed_camera".equals(ruleType.getValue())) {
return new AlarmInfo(SPEED_CAMERA, locInd);
} else if("stop".equals(ruleType.getValue())) {
return new AlarmInfo(STOP, locInd);
}
} else if("barrier".equals(ruleType.getTag())) {
if("toll_booth".equals(ruleType.getValue())) {
return new AlarmInfo(TOLL_BOOTH, locInd);
} else if("border_control".equals(ruleType.getValue())) {
return new AlarmInfo(BORDER_CONTROL, locInd);
}
} else if("traffic_calming".equals(ruleType.getTag())) {
return new AlarmInfo(TRAFFIC_CALMING, locInd);
}
return null;
}
}

View file

@ -5,6 +5,8 @@ import java.util.Collections;
import java.util.List;
import net.osmand.OsmAndFormatter;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
import net.osmand.plus.OsmandApplication;
@ -21,6 +23,7 @@ public class RouteCalculationResult {
private final List<Location> locations;
private final List<RouteDirectionInfo> directions;
private final List<RouteSegmentResult> segments;
private final List<AlarmInfo> alarmInfo;
private final String errorMessage;
private final int[] listDistance;
@ -29,6 +32,7 @@ public class RouteCalculationResult {
// but currentRoute <= get(currentDirectionInfo+1).routeOffset
protected int currentDirectionInfo = 0;
protected int currentRoute = 0;
protected int nextAlarmInfo = 0;
public RouteCalculationResult(String errorMessage) {
this(null, null, null, null, errorMessage, null, false, false);
@ -51,9 +55,10 @@ public class RouteCalculationResult {
}
this.locations = Collections.unmodifiableList(locations);
this.segments = new ArrayList<RouteSegmentResult>(locations.size());
this.segments = new ArrayList<RouteSegmentResult>();
this.listDistance = new int[locations.size()];
updateListDistanceTime();
this.alarmInfo = new ArrayList<AlarmInfo>();
this.directions = Collections.unmodifiableList(localDirections);
updateDirectionsTime();
@ -64,7 +69,8 @@ public class RouteCalculationResult {
List<RouteDirectionInfo> computeDirections = new ArrayList<RouteDirectionInfo>();
this.errorMessage = null;
List<Location> locations = new ArrayList<Location>();
List<RouteSegmentResult> segments = convertVectorResult(computeDirections, locations, list, ctx);
ArrayList<AlarmInfo> alarms = new ArrayList<AlarmInfo>();
List<RouteSegmentResult> segments = convertVectorResult(computeDirections, locations, list, alarms, ctx);
introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end);
this.locations = Collections.unmodifiableList(locations);
@ -74,12 +80,28 @@ public class RouteCalculationResult {
this.directions = Collections.unmodifiableList(computeDirections);
updateDirectionsTime();
this.alarmInfo = Collections.unmodifiableList(alarms);
}
private void attachAlarmInfo(List<AlarmInfo> alarms, RouteSegmentResult res, int intId, int locInd) {
int[] pointTypes = res.getObject().getPointTypes(intId);
RouteRegion reg = res.getObject().region;
if (pointTypes != null) {
for (int r = 0; r < pointTypes.length; r++) {
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, locInd);
if(info != null) {
alarms.add(info);
}
}
}
}
/**
* PREPARATION
*/
private List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list, Context ctx) {
private List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list,
List<AlarmInfo> alarms, Context ctx) {
float prevDirectionTime = 0;
float prevDirectionDistance = 0;
List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
@ -97,6 +119,7 @@ public class RouteCalculationResult {
break;
}
locations.add(n);
attachAlarmInfo(alarms, s, i, locations.size());
segmentsToPopulate.add(s);
if (i == s.getEndPointIndex() ) {
break;
@ -525,6 +548,9 @@ public class RouteCalculationResult {
while (currentDirectionInfo < directions.size() - 1 && directions.get(currentDirectionInfo + 1).routePointOffset < currentRoute) {
currentDirectionInfo++;
}
while (nextAlarmInfo < alarmInfo.size() && alarmInfo.get(nextAlarmInfo).locationIndex < currentRoute) {
nextAlarmInfo++;
}
}
public Location getLocationFromRouteDirection(RouteDirectionInfo i){

View file

@ -116,14 +116,14 @@ public class VoiceRouter {
}
}
private boolean isDistanceLess(float currentSpeed, double dist, double etalon){
protected boolean isDistanceLess(float currentSpeed, double dist, double etalon){
if(dist < etalon || ((dist / currentSpeed) < (etalon / DEFAULT_SPEED))){
return true;
}
return false;
}
private boolean isDistanceLess(float currentSpeed, double dist, double etalon, double defSpeed){
protected boolean isDistanceLess(float currentSpeed, double dist, double etalon, double defSpeed){
if(dist < etalon || ((dist / currentSpeed) < (etalon / defSpeed))){
return true;
}