diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java index ecb4e5b1ba..634dd7219e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java @@ -11,7 +11,6 @@ import java.util.Map; public class RouteDataResources { private Map rules = new LinkedHashMap<>(); - private Map> segmentRules = new LinkedHashMap<>(); private List locations; private int currentLocation; @@ -28,15 +27,6 @@ public class RouteDataResources { return rules; } - public Map getSegmentRules(RouteSegmentResult segmentResult) { - Map ruleMap = segmentRules.get(segmentResult); - if (ruleMap == null) { - ruleMap = new LinkedHashMap<>(); - segmentRules.put(segmentResult, ruleMap); - } - return ruleMap; - } - public List getLocations() { return locations; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java index e02d67c46d..2635328d4c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java @@ -50,7 +50,11 @@ public class RouteImporter { List locations = resources.getLocations(); if (res.tracks.size() > 0 && res.tracks.get(0).segments.size() > 0 && res.tracks.get(0).segments.get(0).points.size() > 0) { for (WptPt point : res.tracks.get(0).segments.get(0).points) { - locations.add(new Location("", point.getLatitude(), point.getLongitude())); + Location loc = new Location("", point.getLatitude(), point.getLongitude()); + if (!Double.isNaN(point.ele)) { + loc.setAltitude(point.ele); + } + locations.add(loc); } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index 9a521548b0..56bc5beac4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -47,9 +47,8 @@ public class RouteSegmentResult implements StringExternalizable void collectTypes(RouteDataResources resources) { Map rules = resources.getRules(); - Map segmentRules = resources.getSegmentRules(this); if (object.types != null) { - collectRules(rules, segmentRules, object.types); + collectRules(rules, object.types); } if (object.pointTypes != null) { int start = Math.min(startPointIndex, endPointIndex); @@ -57,7 +56,7 @@ public class RouteSegmentResult implements StringExternalizable for (int i = start; i <= end && i < object.pointTypes.length; i++) { int[] types = object.pointTypes[i]; if (types != null) { - collectRules(rules, segmentRules, types); + collectRules(rules, types); } } } @@ -90,55 +89,43 @@ public class RouteSegmentResult implements StringExternalizable } } - private void collectRules(Map rules, Map segmentRules, int[] types) { + private void collectRules(Map rules, int[] types) { RouteRegion region = object.region; for (int type : types) { RouteTypeRule rule = region.quickGetEncodingRule(type); - RouteTypeRule segmentRule = null; String tag = rule.getTag(); - if (tag.equals("osmand_ele_start")) { - if (object.heightDistanceArray != null && object.heightDistanceArray.length > startPointIndex * 2 + 1) { - float h = object.heightDistanceArray[startPointIndex * 2 + 1]; - segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h))); - } - } else if (tag.equals("osmand_ele_end")) { - if (object.heightDistanceArray != null && object.heightDistanceArray.length > endPointIndex * 2 + 1) { - float h = object.heightDistanceArray[endPointIndex * 2 + 1]; - segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h))); - } + if (tag.equals("osmand_ele_start") || tag.equals("osmand_ele_end") + || tag.equals("osmand_ele_asc") || tag.equals("osmand_ele_desc")) + { + continue; } - if (segmentRule != null) { - segmentRules.put(rule, segmentRule); - } else if (!rules.containsKey(rule)) { + if (!rules.containsKey(rule)) { rules.put(rule, rules.size()); } } } - private int[] convertTypes(int[] types, Map rules, Map segmentRules) { + private int[] convertTypes(int[] types, Map rules) { if (types == null || types.length == 0) { return null; } - int[] res = new int[types.length]; + List arr = new ArrayList<>(); for (int i = 0; i < types.length; i++) { int type = types[i]; RouteTypeRule rule = object.region.quickGetEncodingRule(type); - RouteTypeRule segmentRule = segmentRules.get(rule); - if (segmentRule != null) { - res[i] = rules.size(); - rules.put(segmentRule, rules.size()); - } else { - Integer ruleId = rules.get(rule); - if (ruleId == null) { - throw new IllegalArgumentException("Cannot find collected rule: " + rule.toString()); - } - res[i] = ruleId; + Integer ruleId = rules.get(rule); + if (ruleId != null) { + arr.add(ruleId); } } + int[] res = new int[arr.size()]; + for (int i = 0; i < arr.size(); i++) { + res[i] = arr.get(i); + } return res; } - private int[][] convertTypes(int[][] types, Map rules, Map segmentRules) { + private int[][] convertTypes(int[][] types, Map rules) { if (types == null || types.length == 0) { return null; } @@ -146,7 +133,7 @@ public class RouteSegmentResult implements StringExternalizable for (int i = 0; i < types.length; i++) { int[] typesArr = types[i]; if (typesArr != null) { - res[i] = convertTypes(typesArr, rules, segmentRules); + res[i] = convertTypes(typesArr, rules); } } return res; @@ -194,7 +181,6 @@ public class RouteSegmentResult implements StringExternalizable @Override public void writeToBundle(RouteDataBundle bundle) { Map rules = bundle.getResources().getRules(); - Map segmentRules = bundle.getResources().getSegmentRules(this); bundle.putInt("length", (Math.abs(endPointIndex - startPointIndex) + 1) * (endPointIndex >= startPointIndex ? 1 : -1)); bundle.putFloat("segmentTime", segmentTime, 2); bundle.putFloat("speed", speed, 2); @@ -212,11 +198,11 @@ public class RouteSegmentResult implements StringExternalizable } } bundle.putLong("id", object.id); - bundle.putArray("types", convertTypes(object.types, rules, segmentRules)); + bundle.putArray("types", convertTypes(object.types, rules)); int start = Math.min(startPointIndex, endPointIndex); int end = Math.max(startPointIndex, endPointIndex); bundle.putArray("pointTypes", convertTypes(Arrays.copyOfRange(object.pointTypes, start, - Math.min(end + 1, object.pointTypes.length)), rules, segmentRules)); + Math.min(end + 1, object.pointTypes.length)), rules)); bundle.putArray("names", convertNameIds(object.nameIds, rules)); } @@ -245,17 +231,22 @@ public class RouteSegmentResult implements StringExternalizable RouteDataResources resources = bundle.getResources(); object.pointsX = new int[length]; object.pointsY = new int[length]; + object.heightDistanceArray = new float[length * 2]; int index = plus ? 0 : length - 1; float distance = 0; Location prevLocation = null; for (int i = 0; i < length; i++) { Location location = resources.getLocation(index); + double dist = 0; if (prevLocation != null) { - distance += MapUtils.getDistance(prevLocation.getLatitude(), prevLocation.getLongitude(), location.getLatitude(), location.getLongitude()); + dist = MapUtils.getDistance(prevLocation.getLatitude(), prevLocation.getLongitude(), location.getLatitude(), location.getLongitude()); + distance += dist; } prevLocation = location; object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude()); object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude()); + object.heightDistanceArray[i * 2] = (float) dist; + object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude(); if (plus) { index++; } else {