Skip to content

Commit

Permalink
Merge branch 'master' into route_legend
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Feb 7, 2025
2 parents d4d9111 + bbd396a commit 4195b17
Show file tree
Hide file tree
Showing 277 changed files with 11,087 additions and 1,667 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ public boolean matches(String name) {

public static boolean cmatches(Collator collator, String fullName, String part, StringMatcherMode mode) {
if (ArabicNormalizer.isSpecialArabic(fullName)) {
fullName = ArabicNormalizer.normalize(fullName);
String normalized = ArabicNormalizer.normalize(fullName);
fullName = normalized == null ? fullName : normalized;
}
if (ArabicNormalizer.isSpecialArabic(part)) {
part = ArabicNormalizer.normalize(part);
String normalized = ArabicNormalizer.normalize(part);
part = normalized == null ? part : normalized;
}
switch (mode) {
case CHECK_CONTAINS:
Expand Down
8 changes: 8 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/binary/ObfConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public static String getOsmUrlForId(MapObject mapObject) {
return "";
}

public static long getOsmIdFromPrefixedRouteId(String routeId) {
long osmId = 0;
if (routeId.startsWith(Amenity.ROUTE_ID_OSM_PREFIX)) {
osmId = Algorithms.parseLongSilently(routeId.replace(Amenity.ROUTE_ID_OSM_PREFIX, ""), 0);
}
return osmId;
}

public static long getOsmObjectId(MapObject object) {
long originalId = -1;
Long id = object.getId();
Expand Down
30 changes: 28 additions & 2 deletions OsmAnd-java/src/main/java/net/osmand/data/MultipolygonBuilder.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.osmand.data;

import gnu.trove.map.hash.TLongObjectHashMap;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.osm.edit.*;
import net.osmand.util.JarvisAlgorithm;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;

import java.sql.SQLException;
import java.util.*;

/**
Expand Down Expand Up @@ -157,6 +158,31 @@ public ArrayList<Ring> combineToRings(List<Way> ways) {
return result;
}

public void createInnerAndOuterWays(Entity e) {
// fill the multipolygon with all ways from the Relation
for (Relation.RelationMember es : ((Relation) e).getMembers()) {
if (es.getEntity() instanceof Way) {
boolean inner = "inner".equals(es.getRole()); //$NON-NLS-1$
if (inner) {
addInnerWay((Way) es.getEntity());
} else if ("outer".equals(es.getRole())) {
addOuterWay((Way) es.getEntity());
}
}
}
}

public void createClimbingOuterWay(Entity e, List<Node> nodes) throws SQLException {
nodes = JarvisAlgorithm.createConvexPolygon(nodes);
int radius = "crag".equals(e.getTag(OSMSettings.OSMTagKey.CLIMBING)) ? 10 : 50;
nodes = JarvisAlgorithm.expandPolygon(nodes, radius);

if (nodes != null) {
Way w = new Way(e.getId(), nodes);
addOuterWay(w);
}
}

private Way merge(TLongObjectHashMap<List<Way>> endMap, long stNodeId, Way changedWay,
TLongObjectHashMap<List<Way>> startMap, long endNodeId) {
List<Way> lst = endMap.get(stNodeId);
Expand Down
8 changes: 8 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@ public void addExcludedPoiAdditionalCategories(String[] excludedPoiAdditionalCat
public String toString() {
return keyName;
}

@Override
public boolean equals(Object other) {
if (!(other instanceof AbstractPoiType that)) {
return false;
}
return keyName != null && keyName.equals(that.keyName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ protected PropagateToNode parsePropagateType(XmlPullParser parser) {
if (propagateToNodesPrefix != null) {
rtype.propagateToNodesPrefix = propagateToNodesPrefix;
}
String tags = parser.getAttributeValue("", "propagateAlsoTags");
if(tags != null) {
rtype.propagateAlsoTags = tags.split(",");
}
rtype.propagateIf = parseMultiTagValue(parser, "propagateIf");
rtype.propagateNetworkIf = parseMultiTagValue(parser, "propagateNetworkIf");
return rtype;
Expand Down Expand Up @@ -583,6 +587,7 @@ public static class PropagateToNode {
public String propagateToNodesPrefix;
public Map<String, String> propagateIf;
public Map<String, String> propagateNetworkIf;
public String[] propagateAlsoTags;
}

public static class MapRulType {
Expand Down
15 changes: 10 additions & 5 deletions OsmAnd-java/src/main/java/net/osmand/osm/OsmRouteType.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public class OsmRouteType {
public static final OsmRouteType FERRY = createType("ferry").reg();
public static final OsmRouteType FOOT = createType("foot").reg();
public static final OsmRouteType LIGHT_RAIL = createType("light_rail").reg();
public static final OsmRouteType PISTE = createType("piste").reg();
public static final OsmRouteType RAILWAY = createType("railway").reg();
public static final OsmRouteType SKI = createType("ski").renderingPropertyAttr(PISTE_ROUTES).reg();
public static final OsmRouteType SKI = createType("piste").renderingPropertyAttr(PISTE_ROUTES).reg();
public static final OsmRouteType ALPINE = createType("alpine").renderingPropertyAttr(ALPINE_HIKING).reg();
public static final OsmRouteType FITNESS = createType("fitness").renderingPropertyAttr(FITNESS_TRAILS).reg();
public static final OsmRouteType INLINE_SKATES = createType("inline_skates").reg();
Expand All @@ -62,6 +61,7 @@ public class OsmRouteType {
public static final OsmRouteType TRAM = createType("tram").reg();
public static final OsmRouteType TROLLEYBUS = createType("trolleybus").reg();
public static final OsmRouteType CLIMBING = createType("climbing").renderingPropertyAttr(CLIMBING_ROUTES).reg();
public static final OsmRouteType UNKNOWN = createType("unknown").reg();

// less specific bottom order
private final String name;
Expand Down Expand Up @@ -157,7 +157,8 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "mtb ride":
case "disused:mtb":
case "abandoned:mtb":
return MOUNTAINBIKE;
case "mtb:scale":
return MTB;
case "hiking":
case "route=hiking":
case "mountain hiking":
Expand Down Expand Up @@ -306,8 +307,9 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "лыжня":
case "nordic":
case "piste":
case "piste:type=nordic":
return WINTER;
case "piste:type":
case "piste:difficulty":
return SKI;
case "snowmobile=designated":
case "snowmobile=permissive":
case "snowmobile=yes":
Expand All @@ -323,6 +325,9 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
return INLINE_SKATES;
case "fitness_trail":
return FITNESS;
case "dirtbike":
case "dirtbike:scale":
return DIRTBIKE;
}
return null;
}
Expand Down
30 changes: 23 additions & 7 deletions OsmAnd-java/src/main/java/net/osmand/router/RoundaboutTurn.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;

import java.util.ArrayList;
import java.util.List;

public class RoundaboutTurn {
Expand Down Expand Up @@ -82,7 +83,7 @@ private TurnType processRoundaboutTurn() {
RouteSegmentResult last = current;
RouteSegmentResult firstRoundabout = current;
RouteSegmentResult lastRoundabout = current;

List<Float> turnAngles = new ArrayList<>();
for (int j = iteration; j < routeSegmentResults.size(); j++) {
RouteSegmentResult rnext = routeSegmentResults.get(j);
last = rnext;
Expand All @@ -96,8 +97,11 @@ private TurnType processRoundaboutTurn() {
}
while (k != rnext.getEndPointIndex()) {
int attachedRoads = rnext.getAttachedRoutes(k).size();
if(attachedRoads > 0) {
if (attachedRoads > 0) {
exit++;
// rnext.getAttachedRoutes(k).
float turnAngle = calculateRoundaboutTurnAngle(rnext, firstRoundabout, rnext, k);
turnAngles.add(turnAngle);
}
k = plus ? k + 1 : k - 1;
}
Expand All @@ -107,22 +111,34 @@ private TurnType processRoundaboutTurn() {
}
// combine all roundabouts
TurnType t = TurnType.getExitTurn(exit, 0, leftSide);
float turnAngle;
turnAngle = calculateRoundaboutTurnAngle(last, firstRoundabout, lastRoundabout, -1);
t.setTurnAngle(turnAngle);
t.setOtherTurnAngles(turnAngles);
return t;
}

private float calculateRoundaboutTurnAngle(RouteSegmentResult last, RouteSegmentResult firstRoundabout,
RouteSegmentResult lastRoundabout, int ind) {
float turnAngle;
// usually covers more than expected
float turnAngleBasedOnOutRoads = (float) MapUtils.degreesDiff(last.getBearingBegin(), prev.getBearingEnd());
float turnAngleBasedOnOutRoads = (float) MapUtils.degreesDiff(
ind < 0 ? last.getBearingBegin() : last.getBearingBegin(ind, RouteSegmentResult.DIST_BEARING_DETECT), prev.getBearingEnd());
// Angle based on circle method tries
// 1. to calculate antinormal to roundabout circle on roundabout entrance and
// 2. normal to roundabout circle on roundabout exit
// 3. calculate angle difference
// This method doesn't work if you go from S to N touching only 1 point of roundabout,
// but it is very important to identify very sharp or very large angle to understand did you pass whole roundabout or small entrance
float turnAngleBasedOnCircle = (float) -MapUtils.degreesDiff(firstRoundabout.getBearingBegin(), lastRoundabout.getBearingEnd() + 180);
float turnAngleBasedOnCircle = (float) -MapUtils.degreesDiff(firstRoundabout.getBearingBegin(),
ind < 0 ? last.getBearingEnd() : lastRoundabout.getBearingEnd(ind, RouteSegmentResult.DIST_BEARING_DETECT) + 180);
if (Math.abs(turnAngleBasedOnOutRoads) > 120) {
// correctly identify if angle is +- 180, so we approach from left or right side
t.setTurnAngle(turnAngleBasedOnCircle) ;
turnAngle = turnAngleBasedOnCircle;
} else {
t.setTurnAngle(turnAngleBasedOnOutRoads) ;
turnAngle = turnAngleBasedOnOutRoads;
}
return t;
return turnAngle;
}

private TurnType processMiniRoundaboutTurn() {
Expand Down
10 changes: 10 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/router/TurnType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;


public class TurnType {
Expand Down Expand Up @@ -137,6 +138,7 @@ public static TurnType valueOf(int vs, boolean leftSide) {
private int[] lanes;
private boolean possiblyLeftTurn;
private boolean possiblyRightTurn;
private List<Float> otherTurnAngles;

public TurnType(int value, int exitOut, float turnAngle, boolean skipToSpeak, int[] lanes,
boolean possiblyLeftTurn, boolean possiblyRightTurn) {
Expand Down Expand Up @@ -612,4 +614,12 @@ public static int getNext(int turn) {
}
return turn;
}

public List<Float> getOtherTurnAngles() {
return otherTurnAngles;
}

public void setOtherTurnAngles(List<Float> turnAngles) {
this.otherTurnAngles = turnAngles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ public String getKeyFromTag(String tag) {
String prefix = "route_" + type.getName() + ROUTE_KEY_VALUE_SEPARATOR;
if (tag.startsWith(prefix) && tag.length() > prefix.length()) {
int endIdx = tag.indexOf(ROUTE_KEY_VALUE_SEPARATOR, prefix.length());
return tag.substring(prefix.length(), endIdx);
return tag.substring(prefix.length(), endIdx != -1 ? endIdx : tag.length());
}
return "";
}
Expand Down Expand Up @@ -776,7 +776,18 @@ public String getRouteName(String localeId, boolean transliteration) {
return transliteration ? TransliterationHelper.transliterate(name) : name;
}
name = getValue("ref");
return !name.isEmpty() ? name : getRelationID();
if (!name.isEmpty()) {
return name;
}
name = getFromTo();
if (!name.isEmpty()) {
return name;
}
name = getRelationID();
if (!name.isEmpty()) {
return name;
}
return this.type.getName(); // avoid emptiness
}

public String getRelationID() {
Expand All @@ -803,6 +814,19 @@ public String getWikipedia() {
return getValue("wikipedia");
}

public String getRef() {
return getValue("ref");
}

public String getFromTo() {
String from = getValue("from");
String to = getValue("to");
if (!Algorithms.isEmpty(from) && !Algorithms.isEmpty(to)) {
return from + " - " + to;
}
return "";
}

public static RouteKey fromGpx(Map<String, String> networkRouteKeyTags) {
String type = networkRouteKeyTags.get(NETWORK_ROUTE_TYPE);
if (!Algorithms.isEmpty(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public boolean sameSearchResult(SearchResult r1, SearchResult r2) {
return MapUtils.getDistance(r1.location, r2.location) < similarityRadius;
}
} else if (r1.object != null && r2.object != null) {
return r1.object == r2.object;
return r1.object.equals(r2.object);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ public boolean isCancelled() {
SearchPhraseDataType.ADDRESS);
String wordToSearch = phrase.getUnknownWordToSearch();
if (ArabicNormalizer.isSpecialArabic(wordToSearch)) {
wordToSearch = ArabicNormalizer.normalize(wordToSearch);
String normalized = ArabicNormalizer.normalize(wordToSearch);
wordToSearch = normalized == null ? wordToSearch : normalized;
}
while (offlineIterator.hasNext() && wordToSearch.length() > 0) {
BinaryMapIndexReader r = offlineIterator.next();
Expand Down Expand Up @@ -609,7 +610,8 @@ public boolean search(final SearchPhrase phrase, final SearchResultMatcher resul
SearchPhraseDataType.POI);
String searchWord = phrase.getUnknownWordToSearch();
if (ArabicNormalizer.isSpecialArabic(searchWord)) {
searchWord = ArabicNormalizer.normalize(searchWord);
String normalized = ArabicNormalizer.normalize(searchWord);
searchWord = normalized == null ? searchWord : normalized;
}
final NameStringMatcher nm = phrase.getMainUnknownNameStringMatcher();
QuadRect bbox = phrase.getFileRequest() != null ? phrase.getRadiusBBoxToSearch(BBOX_RADIUS_POI_IN_CITY) : phrase.getRadiusBBoxToSearch(BBOX_RADIUS_INSIDE);
Expand Down Expand Up @@ -1682,6 +1684,17 @@ public Map<PoiCategory, LinkedHashSet<String>> putTypes(Map<PoiCategory, LinkedH
return acceptedTypes;
}

@Override
public boolean equals(Object other) {
if (super.equals(other)) {
if (!(other instanceof PoiAdditionalCustomFilter that)) {
return false;
}
return this.additionalPoiTypes.equals(that.additionalPoiTypes);
}
return false;
}

}

public static class SearchLocationAndUrlAPI extends SearchBaseAPI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;

import java.util.Objects;

public class TopIndexFilter implements BinaryMapIndexReader.SearchPoiAdditionalFilter {

private PoiSubType poiSubType;
Expand Down Expand Up @@ -50,6 +52,19 @@ public String getIconResource() {
return valueKey;
}

@Override
public boolean equals(Object other) {
if (!(other instanceof TopIndexFilter that)) {
return false;
}
return this.tag.equals(that.tag) && this.value.equals(that.value);
}

@Override
public int hashCode() {
return Objects.hash(tag, value);
}

public static String getValueKey(String value) {
return value.toLowerCase().replace(':', '_').replaceAll("\'", "").replace(' ', '_').replaceAll("\"", "");
}
Expand Down
Loading

0 comments on commit 4195b17

Please sign in to comment.