Skip to content

Commit

Permalink
Merge branch 'osmandapp:master' into hardy_Afa
Browse files Browse the repository at this point in the history
  • Loading branch information
sonora authored Aug 7, 2024
2 parents e3445c6 + d3c4c22 commit 2b625b2
Show file tree
Hide file tree
Showing 177 changed files with 3,170 additions and 1,871 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ build

#Rendering test files
OsmAnd-java/src/test/resources/rendering/*

# ApproximationTest resources
OsmAnd-java/src/test/resources/approximation/*
1 change: 1 addition & 0 deletions OsmAnd-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ tasks.register('collectTestResources', Copy) {
include "*"
include "/search/*"
include "/routing/*"
include "/approximation/*"
}
from("../../resources/poi") {
include "poi_types.xml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void putObjects(long t, List<T> r) {

public List<T> getAllObjects() {
List<T> l = new ArrayList<>();
for (List<T> s : objects.valueCollection()) {
for (List<T> s : getAllEditObjects()) {
l.addAll(s);
}
return l;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public int compareTo(DownloadMapWorker o) {

public void fireLoadCallback(DownloadRequest request) {
for (WeakReference<IMapDownloaderCallback> callback : callbacks) {
IMapDownloaderCallback c = callback.get();
IMapDownloaderCallback c = callback != null ? callback.get() : null;
if (c != null) {
c.tileDownloaded(request);
}
Expand Down
4 changes: 3 additions & 1 deletion OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ public Amenity parseAmenity(String tag, String val, boolean relation, Map<String
if (!hasName && pt.isNameOnly()) {
return null;
}
if (relation && !pt.isRelation()) {
boolean multy = "multipolygon".equals(otherTags.get("type")) || "site".equals(otherTags.get("type"));
// example of site is scottish parliament POI
if (!multy && relation && !pt.isRelation()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public void init(Map<String, String> attributes) {
attributesRef = new RenderingRule[attributes.size()];
}
attributesRef[i] = storage.getRenderingAttributeRule(vl.substring(1));
if (attributesRef[i] == null) {
attributesRef[i] = storage.getRenderingAssociationRule(vl.substring(1));
}
} else if (property.isString()) {
intProperties[i] = storage.getDictionaryValue(vl);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public boolean searchRenderingAttribute(String attribute) {
return searchResult;
}

public boolean searchRenderingAssociation(String association) {
searchResult = false;
RenderingRule rule = storage.getRenderingAssociationRule(association);
if (rule == null) {
return false;
}
searchResult = visitRule(rule, true);
return searchResult;
}

public boolean search(int state) {
return search(state, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class RenderingRuleStorageProperties {
public static final String ATTR_STRING_VALUE = "attrStringValue";
public static final String TEST = "test";
public static final String DISABLE = "disable";



public static final String ASSOCIATION = "association";


public static final String INTERSECTION_MARGIN = "intersectionMargin";
public static final String INTERSECTION_SIZE_FACTOR = "intersectionSizeFactor";
Expand Down Expand Up @@ -100,7 +101,8 @@ public class RenderingRuleStorageProperties {
public static final String ADD_POINT = "addPoint";
public static final String ORDER_BY_DENSITY = "orderByDensity";


public RenderingRuleProperty R_ASSOCIATION;

public RenderingRuleProperty R_TEST;
public RenderingRuleProperty R_DISABLE;
public RenderingRuleProperty R_ATTR_INT_VALUE;
Expand Down Expand Up @@ -228,6 +230,7 @@ public void createDefaultRenderingRuleProperties() {
R_NAME_TAG = registerRuleInternal(RenderingRuleProperty.createInputStringProperty(NAME_TAG));
R_NAME_TAG2 = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(NAME_TAG2));

R_ASSOCIATION = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ASSOCIATION));
R_DISABLE = registerRuleInternal(RenderingRuleProperty.createOutputBooleanProperty(DISABLE));
R_ATTR_INT_VALUE = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ATTR_INT_VALUE));
R_ATTR_BOOL_VALUE = registerRuleInternal(RenderingRuleProperty.createOutputBooleanProperty(ATTR_BOOL_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class RenderingRulesStorage {
public TIntObjectHashMap<RenderingRule>[] tagValueGlobalRules = new TIntObjectHashMap[LENGTH_RULES];

protected Map<String, RenderingRule> renderingAttributes = new LinkedHashMap<String, RenderingRule>();
protected Map<String, RenderingRule> renderingAssociations = new LinkedHashMap<String, RenderingRule>();
protected Map<String, String> renderingConstants = new LinkedHashMap<String, String>();

protected String renderingName;
Expand Down Expand Up @@ -97,6 +98,7 @@ public RenderingRulesStorage copy() {
}
}
storage.renderingAttributes.putAll(renderingAttributes);
storage.renderingAssociations.putAll(renderingAssociations);
return storage;
}

Expand Down Expand Up @@ -159,6 +161,20 @@ public void mergeDependsOrAddon(RenderingRulesStorage depends) {
renderingAttributes.put(e.getKey(), e.getValue());
}
}
it = depends.renderingAssociations.entrySet().iterator();
while (it.hasNext()) {
Entry<String, RenderingRule> e = it.next();
if (renderingAssociations.containsKey(e.getKey())) {
RenderingRule root = renderingAssociations.get(e.getKey());
List<RenderingRule> list = e.getValue().getIfElseChildren();
for (RenderingRule every : list) {
root.addIfElseChildren(every);
}
e.getValue().addToBeginIfElseChildren(root);
} else {
renderingAssociations.put(e.getKey(), e.getValue());
}
}
for (int i = 0; i < LENGTH_RULES; i++) {
if (depends.tagValueGlobalRules[i] == null || depends.tagValueGlobalRules[i].isEmpty()) {
continue;
Expand Down Expand Up @@ -367,6 +383,15 @@ public void startElement(Map<String, String> attrsMap, String name) throws XmlPu
renderingAttributes.put(attr, root);
}
stack.push(root);
} else if("renderingAssociation".equals(name)){ //$NON-NLS-1$
String attr = attrsMap.get("name");
RenderingRule root = new RenderingRule(new HashMap<String, String>(), false, RenderingRulesStorage.this);
if (renderingAssociations.containsKey(attr)) {
renderingAssociations.get(attr).addIfElseChildren(root);
} else {
renderingAssociations.put(attr, root);
}
stack.push(root);
} else if("renderingProperty".equals(name)){ //$NON-NLS-1$
String attr = attrsMap.get("attr");
RenderingRuleProperty prop;
Expand Down Expand Up @@ -433,8 +458,7 @@ private Map<String, String> parseAttributes(XmlPullParser parser, Map<String, St
String vl = parser.getAttributeValue(i);
if (vl != null && vl.startsWith("$")) {
String cv = vl.substring(1);
if (!renderingConstants.containsKey(cv) &&
!renderingAttributes.containsKey(cv)) {
if (!renderingConstants.containsKey(cv) && !renderingAttributes.containsKey(cv) && !renderingAssociations.containsKey(cv)) {
throw new IllegalStateException("Rendering constant or attribute '" + cv + "' was not specified.");
}
if(renderingConstants.containsKey(cv)){
Expand All @@ -457,6 +481,8 @@ public void endElement(String name) throws XmlPullParserException {
stack.pop();
} else if ("renderingAttribute".equals(name)) { //$NON-NLS-1$
stack.pop();
} else if ("renderingAssociation".equals(name)) { //$NON-NLS-1$
stack.pop();
}
}
}
Expand Down Expand Up @@ -540,7 +566,15 @@ public String[] getRenderingAttributeNames() {
public RenderingRule[] getRenderingAttributeValues() {
return renderingAttributes.values().toArray(new RenderingRule[0]);
}


public RenderingRule getRenderingAssociationRule(String association) {
return renderingAssociations.get(association);
}

public String[] getRenderingAssociationNames() {
return renderingAssociations.keySet().toArray(new String[0]);
}

public RenderingRule[] getRules(int state){
if(state >= tagValueGlobalRules.length || tagValueGlobalRules[state] == null) {
return new RenderingRule[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1531,13 +1531,14 @@ protected TurnType createKeepLeftRightTurnBasedOnTurnTypes(RoadSplitStructure rs
int[] act = findActiveIndex(prevSegm, currentSegm, rawLanes, rs, turnLanes);
int activeBeginIndex = act[0];
int activeEndIndex = act[1];
int activeTurn = act[2];
if (activeBeginIndex == -1 || activeEndIndex == -1 || activeBeginIndex > activeEndIndex) {
// something went wrong
return createSimpleKeepLeftRightTurn(leftSide, prevSegm, currentSegm, rs);
}
boolean leftOrRightKeep = (rs.keepLeft && !rs.keepRight) || (!rs.keepLeft && rs.keepRight);
if (leftOrRightKeep) {
setActiveLanesRange(rawLanes, activeBeginIndex, activeEndIndex);
setActiveLanesRange(rawLanes, activeBeginIndex, activeEndIndex, activeTurn);
int tp = inferSlightTurnFromActiveLanes(rawLanes, rs.keepLeft, rs.keepRight);
// Checking to see that there is only one unique turn
if (tp != 0) {
Expand All @@ -1563,18 +1564,16 @@ protected TurnType createKeepLeftRightTurnBasedOnTurnTypes(RoadSplitStructure rs
}
}
} else {
if (activeBeginIndex != -1 && activeEndIndex != -1) {
setActiveLanesRange(rawLanes, activeBeginIndex, activeEndIndex);
t = getActiveTurnType(rawLanes, leftSide, t);
}
setActiveLanesRange(rawLanes, activeBeginIndex, activeEndIndex, activeTurn);
t = getActiveTurnType(rawLanes, leftSide, t);
}
t.setLanes(rawLanes);
t.setPossibleLeftTurn(possiblyLeftTurn);
t.setPossibleRightTurn(possiblyRightTurn);
return t;
}

private void setActiveLanesRange(int[] rawLanes, int activeBeginIndex, int activeEndIndex) {
private void setActiveLanesRange(int[] rawLanes, int activeBeginIndex, int activeEndIndex, int activeTurn) {
Set<Integer> possibleTurns = new TreeSet<>();
Set<Integer> upossibleTurns = new TreeSet<>();
for (int k = activeBeginIndex; k < rawLanes.length && k <= activeEndIndex; k++) {
Expand All @@ -1593,15 +1592,6 @@ private void setActiveLanesRange(int[] rawLanes, int activeBeginIndex, int activ
possibleTurns.retainAll(upossibleTurns);
}
}
int activeTurn = 0;
// rough guess
if(possibleTurns.size() >= 1) {
activeTurn = possibleTurns.iterator().next();
} else if (activeBeginIndex == 0) {
activeTurn = TurnType.getPrimaryTurn(rawLanes[activeBeginIndex]);
} else {
activeTurn = TurnType.getPrimaryTurn(rawLanes[activeEndIndex]);
}
for (int k = activeBeginIndex; k < rawLanes.length && k <= activeEndIndex; k++) {
if(TurnType.getPrimaryTurn(rawLanes[k]) != activeTurn) {
if(TurnType.getSecondaryTurn(rawLanes[k]) == activeTurn) {
Expand Down Expand Up @@ -2243,6 +2233,9 @@ private void avoidKeepForThroughMoving(List<RouteSegmentResult> result) {
if (isKeepTurn(turnType) && isHighSpeakPriority(curr)) {
continue;
}
if (isForkByLanes(curr, result.get(i - 1))) {
continue;
}
int cnt = turnType.countTurnTypeDirections(TurnType.C, true);
int cntAll = turnType.countTurnTypeDirections(TurnType.C, false);
if(cnt > 0 && cnt == cntAll) {
Expand Down Expand Up @@ -2306,7 +2299,7 @@ private int[] getUniqTurnTypes(String turnLanes) {
}

private int[] findActiveIndex(RouteSegmentResult prevSegm, RouteSegmentResult currentSegm, int[] rawLanes, RoadSplitStructure rs, String turnLanes) {
int[] pair = {-1, -1};
int[] pair = {-1, -1, 0};
if (turnLanes == null) {
return pair;
}
Expand All @@ -2329,6 +2322,7 @@ private int[] findActiveIndex(RouteSegmentResult prevSegm, RouteSegmentResult cu
int t = TurnType.getTertiaryTurn(rawLanes[i]);
if (p == startDirection || s == startDirection || t == startDirection) {
pair[0] = i;
pair[2] = startDirection;
break;
}
}
Expand Down Expand Up @@ -2460,6 +2454,17 @@ private boolean isHighSpeakPriority(RouteSegmentResult curr) {
return false;
}

private boolean isForkByLanes(RouteSegmentResult curr, RouteSegmentResult prev) {
//check for Y-intersections with many lanes
if (countLanesMinOne(curr) < countLanesMinOne(prev)) {
List<RouteSegmentResult> attachedRoutes = curr.getAttachedRoutes(curr.getStartPointIndex());
if (attachedRoutes.size() == 1) {
return countLanesMinOne(attachedRoutes.get(0)) >= 2;
}
}
return false;
}

private boolean isKeepTurn(TurnType t) {
return t.keepRight() || t.keepLeft();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -196,6 +197,8 @@ public boolean accept(TIntArrayList types, BinaryMapIndexReader.MapIndex index)

private NetworkRoutesTile loadRoutingDataTile(SearchRequest<RouteDataObject> req, long tileId) throws IOException {
NetworkRoutesTile osmcRoutesTile = new NetworkRoutesTile(tileId);
HashSet<Long> deletedIds = new HashSet<>();
Map<Long, RouteRegion> usedIds = new HashMap<>();
for (Map.Entry<BinaryMapIndexReader, List<RouteSubregion>> readerSubregions : readers.entrySet()) {
req.clearSearchResults();
long nt = System.nanoTime();
Expand All @@ -216,12 +219,25 @@ private NetworkRoutesTile loadRoutingDataTile(SearchRequest<RouteDataObject> req
if (obj == null) {
continue;
}
if (deletedIds.contains(obj.id)) {
// live-updates, osmand_change=delete
continue;
}
if (obj.isRoadDeleted()) {
deletedIds.add(obj.id);
continue;
}
if (usedIds.containsKey(obj.id) && usedIds.get(obj.id) != obj.region) {
// live-update, changed tags
continue;
}
stats.loadedObjects++;
List<RouteKey> keys = filter.convert(obj);
for (RouteKey rk : keys) {
stats.loadedRoutes++;
osmcRoutesTile.add(obj, rk);
}
usedIds.put(obj.id, obj.region);
}
}
}
Expand Down
Loading

0 comments on commit 2b625b2

Please sign in to comment.