Merge branch 'master' into color-pic
This commit is contained in:
commit
a4291472ad
9 changed files with 225 additions and 123 deletions
|
@ -4,6 +4,7 @@ import net.osmand.Location;
|
|||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import net.osmand.util.TransliterationHelper;
|
||||
|
@ -37,7 +38,9 @@ public class RouteDataObject {
|
|||
public int[] nameIds;
|
||||
// mixed array [0, height, cumulative_distance height, cumulative_distance, height, ...] - length is length(points)*2
|
||||
public float[] heightDistanceArray = null;
|
||||
public float heightByCurrentLocation;
|
||||
private static final Log LOG = PlatformUtil.getLog(RouteDataObject.class);
|
||||
|
||||
public RouteDataObject(RouteRegion region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
@ -124,7 +127,7 @@ public class RouteDataObject {
|
|||
equals = this.pointTypes[i] == thatObj.pointTypes[i];
|
||||
} else if (pointTypes[i].length != thatObj.pointTypes[i].length) {
|
||||
equals = false;
|
||||
} else {
|
||||
} else {
|
||||
for (int j = 0; j < this.pointTypes[i].length && equals; j++) {
|
||||
String thisTag = region.routeEncodingRules.get(pointTypes[i][j]).getTag();
|
||||
String thisValue = region.routeEncodingRules.get(pointTypes[i][j]).getValue();
|
||||
|
@ -147,7 +150,7 @@ public class RouteDataObject {
|
|||
equals = this.pointNameTypes[i] == thatObj.pointNameTypes[i];
|
||||
} else if (pointNameTypes[i].length != thatObj.pointNameTypes[i].length) {
|
||||
equals = false;
|
||||
} else {
|
||||
} else {
|
||||
for (int j = 0; j < this.pointNameTypes[i].length && equals; j++) {
|
||||
String thisTag = region.routeEncodingRules.get(pointNameTypes[i][j]).getTag();
|
||||
String thisValue = pointNames[i][j];
|
||||
|
@ -165,53 +168,67 @@ public class RouteDataObject {
|
|||
}
|
||||
|
||||
public float[] calculateHeightArray() {
|
||||
if(heightDistanceArray != null) {
|
||||
return calculateHeightArray(null);
|
||||
}
|
||||
|
||||
public float[] calculateHeightArray(LatLon currentLocation) {
|
||||
if (heightDistanceArray != null) {
|
||||
return heightDistanceArray;
|
||||
}
|
||||
int startHeight = Algorithms.parseIntSilently(getValue("osmand_ele_start"), HEIGHT_UNDEFINED);
|
||||
int endHeight = Algorithms.parseIntSilently(getValue("osmand_ele_end"), startHeight);
|
||||
if(startHeight == HEIGHT_UNDEFINED) {
|
||||
if (startHeight == HEIGHT_UNDEFINED) {
|
||||
heightDistanceArray = new float[0];
|
||||
return heightDistanceArray;
|
||||
}
|
||||
|
||||
heightDistanceArray = new float[2*getPointsLength()];
|
||||
heightDistanceArray = new float[2 * getPointsLength()];
|
||||
double plon = 0;
|
||||
double plat = 0;
|
||||
float prevHeight = startHeight;
|
||||
for(int k = 0; k < getPointsLength(); k++) {
|
||||
float prevHeight = heightByCurrentLocation = startHeight;
|
||||
double prevDistance = 0;
|
||||
for (int k = 0; k < getPointsLength(); k++) {
|
||||
double lon = MapUtils.get31LongitudeX(getPoint31XTile(k));
|
||||
double lat = MapUtils.get31LatitudeY(getPoint31YTile(k));
|
||||
if(k > 0) {
|
||||
if (k > 0) {
|
||||
double dd = MapUtils.getDistance(plat, plon, lat, lon);
|
||||
float height = HEIGHT_UNDEFINED;
|
||||
if(k == getPointsLength() - 1) {
|
||||
if (k == getPointsLength() - 1) {
|
||||
height = endHeight;
|
||||
} else {
|
||||
String asc = getValue(k, "osmand_ele_asc");
|
||||
if(asc != null && asc.length() > 0) {
|
||||
if (asc != null && asc.length() > 0) {
|
||||
height = (prevHeight + Float.parseFloat(asc));
|
||||
} else {
|
||||
String desc = getValue(k, "osmand_ele_desc");
|
||||
if(desc != null && desc.length() > 0) {
|
||||
if (desc != null && desc.length() > 0) {
|
||||
height = (prevHeight - Float.parseFloat(desc));
|
||||
}
|
||||
}
|
||||
}
|
||||
heightDistanceArray[2*k] = (float) dd;
|
||||
heightDistanceArray[2*k+1] = height;
|
||||
if(height != HEIGHT_UNDEFINED) {
|
||||
heightDistanceArray[2 * k] = (float) dd;
|
||||
heightDistanceArray[2 * k + 1] = height;
|
||||
|
||||
if (currentLocation != null) {
|
||||
double distance = MapUtils.getDistance(currentLocation, lat, lon);
|
||||
if (height != HEIGHT_UNDEFINED && distance < prevDistance) {
|
||||
prevDistance = distance;
|
||||
heightByCurrentLocation = height;
|
||||
}
|
||||
}
|
||||
|
||||
if (height != HEIGHT_UNDEFINED) {
|
||||
// interpolate undefined
|
||||
double totalDistance = dd;
|
||||
int startUndefined = k;
|
||||
while(startUndefined - 1 >= 0 && heightDistanceArray[2*(startUndefined - 1)+1] == HEIGHT_UNDEFINED) {
|
||||
startUndefined --;
|
||||
totalDistance += heightDistanceArray[2*(startUndefined)];
|
||||
while (startUndefined - 1 >= 0 && heightDistanceArray[2 * (startUndefined - 1) + 1] == HEIGHT_UNDEFINED) {
|
||||
startUndefined--;
|
||||
totalDistance += heightDistanceArray[2 * (startUndefined)];
|
||||
}
|
||||
if(totalDistance > 0) {
|
||||
if (totalDistance > 0) {
|
||||
double angle = (height - prevHeight) / totalDistance;
|
||||
for(int j = startUndefined; j < k; j++) {
|
||||
heightDistanceArray[2*j+1] = (float) ((heightDistanceArray[2*j] * angle) + heightDistanceArray[2*j-1]);
|
||||
for (int j = startUndefined; j < k; j++) {
|
||||
heightDistanceArray[2 * j + 1] = (float) ((heightDistanceArray[2 * j] * angle) + heightDistanceArray[2 * j - 1]);
|
||||
}
|
||||
}
|
||||
prevHeight = height;
|
||||
|
@ -223,6 +240,9 @@ public class RouteDataObject {
|
|||
}
|
||||
plat = lat;
|
||||
plon = lon;
|
||||
if (currentLocation != null) {
|
||||
prevDistance = MapUtils.getDistance(currentLocation, plat, plon);
|
||||
}
|
||||
}
|
||||
return heightDistanceArray;
|
||||
}
|
||||
|
@ -231,34 +251,34 @@ public class RouteDataObject {
|
|||
return id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
if(names != null ) {
|
||||
public String getName() {
|
||||
if (names != null) {
|
||||
return names.get(region.nameTypeRule);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getName(String lang){
|
||||
public String getName(String lang) {
|
||||
return getName(lang, false);
|
||||
}
|
||||
|
||||
public String getName(String lang, boolean transliterate){
|
||||
if(names != null ) {
|
||||
if(Algorithms.isEmpty(lang)) {
|
||||
public String getName(String lang, boolean transliterate) {
|
||||
if (names != null) {
|
||||
if (Algorithms.isEmpty(lang)) {
|
||||
return names.get(region.nameTypeRule);
|
||||
}
|
||||
int[] kt = names.keys();
|
||||
for(int i = 0 ; i < kt.length; i++) {
|
||||
for (int i = 0; i < kt.length; i++) {
|
||||
int k = kt[i];
|
||||
if(region.routeEncodingRules.size() > k) {
|
||||
if(("name:"+lang).equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (region.routeEncodingRules.size() > k) {
|
||||
if (("name:" + lang).equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
return names.get(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
String nmDef = names.get(region.nameTypeRule);
|
||||
if(transliterate && nmDef != null && nmDef.length() > 0) {
|
||||
if (transliterate && nmDef != null && nmDef.length() > 0) {
|
||||
return TransliterationHelper.transliterate(nmDef);
|
||||
}
|
||||
return nmDef;
|
||||
|
@ -279,20 +299,20 @@ public class RouteDataObject {
|
|||
// return getDestinationRef(direction);
|
||||
//}
|
||||
if (names != null) {
|
||||
if(Algorithms.isEmpty(lang)) {
|
||||
if (Algorithms.isEmpty(lang)) {
|
||||
return names.get(region.refTypeRule);
|
||||
}
|
||||
int[] kt = names.keys();
|
||||
for(int i = 0 ; i < kt.length; i++) {
|
||||
for (int i = 0; i < kt.length; i++) {
|
||||
int k = kt[i];
|
||||
if(region.routeEncodingRules.size() > k) {
|
||||
if(("ref:"+lang).equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (region.routeEncodingRules.size() > k) {
|
||||
if (("ref:" + lang).equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
return names.get(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
String refDefault = names.get(region.refTypeRule);
|
||||
if(transliterate && refDefault != null && refDefault.length() > 0) {
|
||||
if (transliterate && refDefault != null && refDefault.length() > 0) {
|
||||
return TransliterationHelper.transliterate(refDefault);
|
||||
}
|
||||
return refDefault;
|
||||
|
@ -307,13 +327,13 @@ public class RouteDataObject {
|
|||
String refTagDefault = "destination:ref";
|
||||
String refDefault = null;
|
||||
|
||||
for(int i = 0 ; i < kt.length; i++) {
|
||||
for (int i = 0; i < kt.length; i++) {
|
||||
int k = kt[i];
|
||||
if(region.routeEncodingRules.size() > k) {
|
||||
if(refTag.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (region.routeEncodingRules.size() > k) {
|
||||
if (refTag.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
return names.get(k);
|
||||
}
|
||||
if(refTagDefault.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (refTagDefault.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
refDefault = names.get(k);
|
||||
}
|
||||
}
|
||||
|
@ -326,12 +346,12 @@ public class RouteDataObject {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String getDestinationName(String lang, boolean transliterate, boolean direction){
|
||||
public String getDestinationName(String lang, boolean transliterate, boolean direction) {
|
||||
//Issue #3289: Treat destination:ref like a destination, not like a ref
|
||||
String destRef = ((getDestinationRef(direction) == null) || getDestinationRef(direction).equals(getRef(lang, transliterate, direction))) ? "" : getDestinationRef(direction);
|
||||
String destRef1 = Algorithms.isEmpty(destRef) ? "" : destRef + ", ";
|
||||
|
||||
if(names != null) {
|
||||
if (names != null) {
|
||||
int[] kt = names.keys();
|
||||
|
||||
// Issue #3181: Parse destination keys in this order:
|
||||
|
@ -341,35 +361,35 @@ public class RouteDataObject {
|
|||
// destination
|
||||
|
||||
String destinationTagLangFB = "destination:lang:XX";
|
||||
if(!Algorithms.isEmpty(lang)) {
|
||||
if (!Algorithms.isEmpty(lang)) {
|
||||
destinationTagLangFB = (direction == true) ? "destination:lang:" + lang + ":forward" : "destination:lang:" + lang + ":backward";
|
||||
}
|
||||
String destinationTagFB = (direction == true) ? "destination:forward" : "destination:backward";
|
||||
String destinationTagLang = "destination:lang:XX";
|
||||
if(!Algorithms.isEmpty(lang)) {
|
||||
if (!Algorithms.isEmpty(lang)) {
|
||||
destinationTagLang = "destination:lang:" + lang;
|
||||
}
|
||||
String destinationTagDefault = "destination";
|
||||
String destinationDefault = null;
|
||||
|
||||
for(int i = 0 ; i < kt.length; i++) {
|
||||
for (int i = 0; i < kt.length; i++) {
|
||||
int k = kt[i];
|
||||
if(region.routeEncodingRules.size() > k) {
|
||||
if(!Algorithms.isEmpty(lang) && destinationTagLangFB.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (region.routeEncodingRules.size() > k) {
|
||||
if (!Algorithms.isEmpty(lang) && destinationTagLangFB.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(names.get(k)) : names.get(k));
|
||||
}
|
||||
if(destinationTagFB.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (destinationTagFB.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(names.get(k)) : names.get(k));
|
||||
}
|
||||
if(!Algorithms.isEmpty(lang) && destinationTagLang.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (!Algorithms.isEmpty(lang) && destinationTagLang.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(names.get(k)) : names.get(k));
|
||||
}
|
||||
if(destinationTagDefault.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
if (destinationTagDefault.equals(region.routeEncodingRules.get(k).getTag())) {
|
||||
destinationDefault = names.get(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(destinationDefault != null) {
|
||||
if (destinationDefault != null) {
|
||||
return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(destinationDefault) : destinationDefault);
|
||||
}
|
||||
}
|
||||
|
@ -400,14 +420,14 @@ public class RouteDataObject {
|
|||
RestrictionInfo ri = new RestrictionInfo();
|
||||
ri.toWay = getRestrictionId(k);
|
||||
ri.type = getRestrictionType(k);
|
||||
if(restrictionsVia != null && k < restrictionsVia.length) {
|
||||
if (restrictionsVia != null && k < restrictionsVia.length) {
|
||||
ri.viaWay = restrictionsVia[k];
|
||||
}
|
||||
return ri;
|
||||
}
|
||||
|
||||
public long getRestrictionVia(int i) {
|
||||
if(restrictionsVia != null && restrictionsVia.length > i) {
|
||||
if (restrictionsVia != null && restrictionsVia.length > i) {
|
||||
return restrictionsVia[i];
|
||||
}
|
||||
return 0;
|
||||
|
@ -441,7 +461,7 @@ public class RouteDataObject {
|
|||
}
|
||||
if (insNames) {
|
||||
pointNames = new String[opointNames.length + 1][];
|
||||
pointNameTypes = new int[opointNameTypes.length +1][];
|
||||
pointNameTypes = new int[opointNameTypes.length + 1][];
|
||||
}
|
||||
int i = 0;
|
||||
for (; i < pos; i++) {
|
||||
|
@ -590,7 +610,7 @@ public class RouteDataObject {
|
|||
}
|
||||
|
||||
public static float parseSpeed(String v, float def) {
|
||||
if(v.equals("none")) {
|
||||
if (v.equals("none")) {
|
||||
return RouteDataObject.NONE_MAX_SPEED;
|
||||
} else {
|
||||
int i = Algorithms.findFirstNumberEndIndex(v);
|
||||
|
@ -614,20 +634,20 @@ public class RouteDataObject {
|
|||
f += Float.parseFloat(v.substring(0, i));
|
||||
String pref = v.substring(i, v.length()).trim();
|
||||
float add = 0;
|
||||
for(int ik = 0; ik < pref.length(); ik++) {
|
||||
if(Algorithms.isDigit(pref.charAt(ik)) || pref.charAt(ik) == '.' || pref.charAt(ik) == '-') {
|
||||
for (int ik = 0; ik < pref.length(); ik++) {
|
||||
if (Algorithms.isDigit(pref.charAt(ik)) || pref.charAt(ik) == '.' || pref.charAt(ik) == '-') {
|
||||
int first = Algorithms.findFirstNumberEndIndex(pref.substring(ik));
|
||||
if(first != -1) {
|
||||
if (first != -1) {
|
||||
add = parseLength(pref.substring(ik), 0);
|
||||
pref = pref.substring(0, ik);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(pref.contains("km")) {
|
||||
if (pref.contains("km")) {
|
||||
f *= 1000;
|
||||
}
|
||||
if(pref.contains("\"") || pref.contains("in")) {
|
||||
if (pref.contains("\"") || pref.contains("in")) {
|
||||
f *= 0.0254;
|
||||
} else if (pref.contains("\'") || pref.contains("ft") || pref.contains("feet")) {
|
||||
// foot to meters
|
||||
|
@ -673,27 +693,27 @@ public class RouteDataObject {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean roundabout(){
|
||||
public boolean roundabout() {
|
||||
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.roundabout()) {
|
||||
if (r.roundabout()) {
|
||||
return true;
|
||||
} else if(r.onewayDirection() != 0 && loop()) {
|
||||
} else if (r.onewayDirection() != 0 && loop()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tunnel(){
|
||||
public boolean tunnel() {
|
||||
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.getTag().equals("tunnel") && r.getValue().equals("yes")) {
|
||||
if (r.getTag().equals("tunnel") && r.getValue().equals("yes")) {
|
||||
return true;
|
||||
}
|
||||
if(r.getTag().equals("layer") && r.getValue().equals("-1")) {
|
||||
if (r.getTag().equals("layer") && r.getValue().equals("-1")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -882,7 +902,7 @@ public class RouteDataObject {
|
|||
|
||||
public boolean bearingVsRouteDirection(Location loc) {
|
||||
boolean direction = true;
|
||||
if(loc != null && loc.hasBearing()) {
|
||||
if (loc != null && loc.hasBearing()) {
|
||||
double diff = MapUtils.alignAngleDifference(directionRoute(0, true) - loc.getBearing() / 180f * Math.PI);
|
||||
direction = Math.abs(diff) < Math.PI / 2f;
|
||||
}
|
||||
|
@ -932,13 +952,13 @@ public class RouteDataObject {
|
|||
}
|
||||
|
||||
public double distance(int startPoint, int endPoint) {
|
||||
if(startPoint > endPoint) {
|
||||
if (startPoint > endPoint) {
|
||||
int k = endPoint;
|
||||
endPoint = startPoint;
|
||||
startPoint = k;
|
||||
}
|
||||
double d = 0;
|
||||
for(int k = startPoint; k < endPoint && k < getPointsLength() -1; k++) {
|
||||
for (int k = startPoint; k < endPoint && k < getPointsLength() - 1; k++) {
|
||||
int x = getPoint31XTile(k);
|
||||
int y = getPoint31YTile(k);
|
||||
int kx = getPoint31XTile(k + 1);
|
||||
|
@ -974,16 +994,16 @@ public class RouteDataObject {
|
|||
// translate into meters
|
||||
total += simplifyDistance(x, y, px, py);
|
||||
} while (total < dist);
|
||||
return -Math.atan2( x - px, y - py );
|
||||
return -Math.atan2(x - px, y - py);
|
||||
}
|
||||
|
||||
private double simplifyDistance(int x, int y, int px, int py) {
|
||||
return Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d;
|
||||
}
|
||||
|
||||
private static void assertTrueLength(String vl, float exp){
|
||||
private static void assertTrueLength(String vl, float exp) {
|
||||
float dest = parseLength(vl, 0);
|
||||
if(exp != dest) {
|
||||
if (exp != dest) {
|
||||
System.err.println("FAIL " + vl + " " + dest);
|
||||
} else {
|
||||
System.out.println("OK " + vl);
|
||||
|
@ -992,24 +1012,24 @@ public class RouteDataObject {
|
|||
|
||||
public static void main(String[] args) {
|
||||
assertTrueLength("10 km", 10000);
|
||||
assertTrueLength("0.01 km", 10);
|
||||
assertTrueLength("0.01 km 10 m", 20);
|
||||
assertTrueLength("10 m", 10);
|
||||
assertTrueLength("10m", 10);
|
||||
assertTrueLength("3.4 m", 3.4f);
|
||||
assertTrueLength("3.40 m", 3.4f);
|
||||
assertTrueLength("10 m 10m", 20);
|
||||
assertTrueLength("14'10\"", 4.5212f);
|
||||
assertTrueLength("14.5'", 4.4196f);
|
||||
assertTrueLength("14.5 ft", 4.4196f);
|
||||
assertTrueLength("14'0\"", 4.2672f);
|
||||
assertTrueLength("15ft", 4.572f);
|
||||
assertTrueLength("15 ft 1 in", 4.5974f);
|
||||
assertTrueLength("4.1 metres", 4.1f);
|
||||
assertTrueLength("14'0''", 4.2672f);
|
||||
assertTrueLength("14 feet", 4.2672f);
|
||||
assertTrueLength("14 mile", 22530.76f);
|
||||
assertTrueLength("14 cm", 0.14f);
|
||||
assertTrueLength("0.01 km", 10);
|
||||
assertTrueLength("0.01 km 10 m", 20);
|
||||
assertTrueLength("10 m", 10);
|
||||
assertTrueLength("10m", 10);
|
||||
assertTrueLength("3.4 m", 3.4f);
|
||||
assertTrueLength("3.40 m", 3.4f);
|
||||
assertTrueLength("10 m 10m", 20);
|
||||
assertTrueLength("14'10\"", 4.5212f);
|
||||
assertTrueLength("14.5'", 4.4196f);
|
||||
assertTrueLength("14.5 ft", 4.4196f);
|
||||
assertTrueLength("14'0\"", 4.2672f);
|
||||
assertTrueLength("15ft", 4.572f);
|
||||
assertTrueLength("15 ft 1 in", 4.5974f);
|
||||
assertTrueLength("4.1 metres", 4.1f);
|
||||
assertTrueLength("14'0''", 4.2672f);
|
||||
assertTrueLength("14 feet", 4.2672f);
|
||||
assertTrueLength("14 mile", 22530.76f);
|
||||
assertTrueLength("14 cm", 0.14f);
|
||||
|
||||
// float badValue = -1;
|
||||
// assertTrueLength("none", badValue);
|
||||
|
@ -1054,7 +1074,7 @@ public class RouteDataObject {
|
|||
public RestrictionInfo next; // optional to simulate linked list
|
||||
|
||||
public int length() {
|
||||
if(next == null) {
|
||||
if (next == null) {
|
||||
return 1;
|
||||
}
|
||||
return next.length() + 1;
|
||||
|
@ -1064,16 +1084,16 @@ public class RouteDataObject {
|
|||
public void setRestriction(int k, long to, int type, long viaWay) {
|
||||
long valto = (to << RouteDataObject.RESTRICTION_SHIFT) | ((long) type & RouteDataObject.RESTRICTION_MASK);
|
||||
restrictions[k] = valto;
|
||||
if(viaWay != 0) {
|
||||
if (viaWay != 0) {
|
||||
setRestrictionVia(k, viaWay);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRestrictionVia(int k, long viaWay) {
|
||||
if(restrictionsVia != null) {
|
||||
if (restrictionsVia != null) {
|
||||
long[] nrestrictionsVia = new long[Math.max(k + 1, restrictions.length)];
|
||||
System.arraycopy(restrictions, 0, nrestrictionsVia, 0, restrictions.length);
|
||||
restrictionsVia = nrestrictionsVia;
|
||||
restrictionsVia = nrestrictionsVia;
|
||||
} else {
|
||||
restrictionsVia = new long[k + 1];
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ import androidx.annotation.Nullable;
|
|||
import androidx.annotation.StringRes;
|
||||
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.BooleanPreference;
|
||||
|
@ -42,6 +45,8 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
private boolean visible = true;
|
||||
private SpecialPointType specialPointType = null;
|
||||
private BackgroundType backgroundType = null;
|
||||
private double altitude;
|
||||
private long timestamp;
|
||||
|
||||
public FavouritePoint() {
|
||||
}
|
||||
|
@ -50,10 +55,24 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.category = category;
|
||||
if(name == null) {
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
this.name = name;
|
||||
timestamp = System.currentTimeMillis();
|
||||
initPersonalType();
|
||||
}
|
||||
|
||||
public FavouritePoint(double latitude, double longitude, String name, String category, double altitude, long timestamp) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.category = category;
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
this.name = name;
|
||||
this.altitude = altitude;
|
||||
this.timestamp = timestamp != 0 ? timestamp : System.currentTimeMillis();
|
||||
initPersonalType();
|
||||
}
|
||||
|
||||
|
@ -69,25 +88,56 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
this.address = favouritePoint.address;
|
||||
this.iconId = favouritePoint.iconId;
|
||||
this.backgroundType = favouritePoint.backgroundType;
|
||||
this.altitude = favouritePoint.altitude;
|
||||
this.timestamp = favouritePoint.timestamp;
|
||||
initPersonalType();
|
||||
}
|
||||
|
||||
private void initPersonalType() {
|
||||
if(FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY.equals(category)) {
|
||||
for(SpecialPointType p : SpecialPointType.values()) {
|
||||
if(p.typeName.equals(this.name)) {
|
||||
if (FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY.equals(category)) {
|
||||
for (SpecialPointType p : SpecialPointType.values()) {
|
||||
if (p.typeName.equals(this.name)) {
|
||||
this.specialPointType = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initAltitude(OsmandApplication app) {
|
||||
initAltitude(app, null);
|
||||
}
|
||||
|
||||
public void initAltitude(OsmandApplication app, final Runnable callback) {
|
||||
Location location = new Location("", latitude, longitude);
|
||||
app.getLocationProvider().getRouteSegment(location, null, false,
|
||||
new ResultMatcher<RouteDataObject>() {
|
||||
|
||||
@Override
|
||||
public boolean publish(RouteDataObject routeDataObject) {
|
||||
if (routeDataObject != null) {
|
||||
LatLon latLon = new LatLon(latitude, longitude);
|
||||
routeDataObject.calculateHeightArray(latLon);
|
||||
altitude = routeDataObject.heightByCurrentLocation;
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public SpecialPointType getSpecialPointType() {
|
||||
return specialPointType;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
return color;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -171,6 +221,22 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public void setAltitude(double altitude) {
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
@ -200,7 +266,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
initPersonalType();
|
||||
}
|
||||
|
||||
public String getDescription () {
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
@ -256,7 +322,8 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
} else if (!originObjectName.equals(fp.originObjectName))
|
||||
return false;
|
||||
|
||||
return (this.latitude == fp.latitude) && (this.longitude == fp.longitude);
|
||||
return (this.latitude == fp.latitude) && (this.longitude == fp.longitude) &&
|
||||
(this.altitude == fp.altitude) && (this.timestamp == fp.timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -265,6 +332,8 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
int result = 1;
|
||||
result = prime * result + (int) Math.floor(latitude * 10000);
|
||||
result = prime * result + (int) Math.floor(longitude * 10000);
|
||||
result = prime * result + (int) Math.floor(altitude * 10000);
|
||||
result = prime * result + (int) Math.floor(timestamp * 10000);
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((category == null) ? 0 : category.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
|
@ -289,7 +358,9 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public String getCategory() { return FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY; }
|
||||
public String getCategory() {
|
||||
return FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return typeName;
|
||||
|
@ -384,7 +455,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
name = "";
|
||||
}
|
||||
FavouritePoint fp;
|
||||
fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName);
|
||||
fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName, pt.ele, pt.time);
|
||||
fp.setDescription(pt.desc);
|
||||
if (pt.comment != null) {
|
||||
fp.setOriginObjectName(pt.comment);
|
||||
|
@ -405,6 +476,8 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
WptPt pt = new WptPt();
|
||||
pt.lat = getLatitude();
|
||||
pt.lon = getLongitude();
|
||||
pt.ele = getAltitude();
|
||||
pt.time = getTimestamp();
|
||||
if (!isVisible()) {
|
||||
pt.getExtensionsToWrite().put(HIDDEN, "true");
|
||||
}
|
||||
|
|
|
@ -361,6 +361,9 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
|
||||
public boolean addFavourite(FavouritePoint p, boolean saveImmediately) {
|
||||
if (Double.isNaN(p.getAltitude()) || p.getAltitude() == 0) {
|
||||
p.initAltitude(context);
|
||||
}
|
||||
if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) {
|
||||
return true;
|
||||
}
|
||||
|
@ -545,6 +548,7 @@ public class FavouritesDbHelper {
|
|||
cancelAddressRequest(p);
|
||||
p.setLatitude(lat);
|
||||
p.setLongitude(lon);
|
||||
p.initAltitude(context);
|
||||
if (description != null) {
|
||||
p.setDescription(description);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class FavoritesImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
|
|||
private boolean forceImportFavourites;
|
||||
|
||||
public FavoritesImportTask(@NonNull FragmentActivity activity, @NonNull GPXFile gpxFile,
|
||||
@NonNull String fileName, boolean forceImportFavourites) {
|
||||
@NonNull String fileName, boolean forceImportFavourites) {
|
||||
super(activity);
|
||||
this.gpxFile = gpxFile;
|
||||
this.fileName = fileName;
|
||||
|
|
|
@ -215,7 +215,7 @@ public class ImportHelper {
|
|||
public static String getNameFromContentUri(OsmandApplication app, Uri contentUri) {
|
||||
try {
|
||||
String name;
|
||||
Cursor returnCursor = app.getContentResolver().query(contentUri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
|
||||
Cursor returnCursor = app.getContentResolver().query(contentUri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null);
|
||||
if (returnCursor != null && returnCursor.moveToFirst()) {
|
||||
int columnIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if (columnIndex != -1) {
|
||||
|
@ -690,7 +690,7 @@ public class ImportHelper {
|
|||
} else {
|
||||
fpCat = p.category;
|
||||
}
|
||||
FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat);
|
||||
FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, 0);
|
||||
if (p.desc != null) {
|
||||
point.setDescription(p.desc);
|
||||
}
|
||||
|
|
|
@ -1036,6 +1036,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
title = "";
|
||||
}
|
||||
String originObjectName = "";
|
||||
double altitude = 0;
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Object object = getObject();
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
|
@ -1043,10 +1045,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
} else if (object instanceof TransportStop) {
|
||||
originObjectName = ((TransportStop) object).toStringEn();
|
||||
}
|
||||
if (object instanceof WptPt) {
|
||||
altitude = ((WptPt) object).ele;
|
||||
}
|
||||
}
|
||||
FavoritePointEditor favoritePointEditor = getFavoritePointEditor();
|
||||
if (favoritePointEditor != null) {
|
||||
favoritePointEditor.add(getLatLon(), title, getStreetStr(), originObjectName);
|
||||
favoritePointEditor.add(getLatLon(), title, getStreetStr(), originObjectName, altitude, timestamp);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1074,7 +1079,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
|
||||
layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity);
|
||||
}
|
||||
mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, configure ? null : getObject(), configure); }
|
||||
mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, configure ? null : getObject(), configure);
|
||||
}
|
||||
return menuAdapter;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class FavoritePointEditor extends PointEditor {
|
|||
return favorite;
|
||||
}
|
||||
|
||||
public void add(LatLon latLon, String title, String address, String originObjectName) {
|
||||
public void add(LatLon latLon, String title, String address, String originObjectName, double altitude, long timestamp) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (latLon == null || mapActivity == null) {
|
||||
return;
|
||||
|
@ -37,7 +37,7 @@ public class FavoritePointEditor extends PointEditor {
|
|||
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) {
|
||||
lastCategory = "";
|
||||
}
|
||||
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory);
|
||||
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory, altitude, timestamp);
|
||||
favorite.setDescription("");
|
||||
favorite.setAddress(address.isEmpty() ? title : address);
|
||||
favorite.setOriginObjectName(originObjectName);
|
||||
|
@ -64,7 +64,6 @@ public class FavoritePointEditor extends PointEditor {
|
|||
favorite.setDescription("");
|
||||
favorite.setAddress("");
|
||||
favorite.setOriginObjectName(originObjectName);
|
||||
|
||||
FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill);
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
final FavouritePoint favorite = getFavorite();
|
||||
if (favorite != null) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
getNameTextValue(), getCategoryTextValue(), favorite.getAltitude(), favorite.getTimestamp());
|
||||
point.setDescription(getDescriptionTextValue());
|
||||
point.setAddress(getAddressTextValue());
|
||||
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
|
||||
|
@ -198,7 +198,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
if (favorite.getName().equals(point.getName()) &&
|
||||
favorite.getCategory().equals(point.getCategory()) &&
|
||||
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription()) &&
|
||||
Algorithms.stringsEqual(favorite.getAddress(),point.getAddress())) {
|
||||
Algorithms.stringsEqual(favorite.getAddress(), point.getAddress())) {
|
||||
if (needDismiss) {
|
||||
dismiss(false);
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),point.getAddress(), needDismiss);
|
||||
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), point.getAddress(), needDismiss);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
|
@ -225,9 +225,9 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
FavoritePointEditor editor = getFavoritePointEditor();
|
||||
if (editor != null && helper != null) {
|
||||
if (editor.isNew()) {
|
||||
doAddFavorite(name, category, description,address);
|
||||
doAddFavorite(name, category, description, address);
|
||||
} else {
|
||||
helper.editFavouriteName(favorite, name, category, description,address);
|
||||
helper.editFavouriteName(favorite, name, category, description, address);
|
||||
}
|
||||
}
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
|
|
|
@ -251,7 +251,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
|||
final FavouritePoint favorite = getFavorite();
|
||||
if (favorite != null) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
getNameTextValue(), getCategoryTextValue(), favorite.getAltitude(), favorite.getTimestamp());
|
||||
point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null);
|
||||
point.setAddress(isAddressAvailable() ? getAddressTextValue() : null);
|
||||
point.setColor(color);
|
||||
|
@ -267,7 +267,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
|||
final FavouritePoint favorite = getFavorite();
|
||||
if (favorite != null) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
getNameTextValue(), getCategoryTextValue(), favorite.getAltitude(), favorite.getTimestamp());
|
||||
point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null);
|
||||
point.setAddress(isAddressAvailable() ? getAddressTextValue() : null);
|
||||
point.setColor(color);
|
||||
|
@ -311,7 +311,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
|||
}
|
||||
|
||||
private void doSave(FavouritePoint favorite, String name, String category, String description, String address,
|
||||
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) {
|
||||
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) {
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
FavoritePointEditor editor = getFavoritePointEditor();
|
||||
if (editor != null && helper != null) {
|
||||
|
@ -338,8 +338,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
|||
}
|
||||
|
||||
private void doEditFavorite(FavouritePoint favorite, String name, String category, String description, String address,
|
||||
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId,
|
||||
FavouritesDbHelper helper) {
|
||||
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId,
|
||||
FavouritesDbHelper helper) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
|
||||
|
@ -351,7 +351,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
|||
}
|
||||
|
||||
private void doAddFavorite(String name, String category, String description, String address, @ColorInt int color,
|
||||
BackgroundType backgroundType, @DrawableRes int iconId) {
|
||||
BackgroundType backgroundType, @DrawableRes int iconId) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
FavouritePoint favorite = getFavorite();
|
||||
|
|
Loading…
Reference in a new issue