Skip to content

Commit

Permalink
Merge branch 'master' of github.com:osmandapp/OsmAnd into nearby_plac…
Browse files Browse the repository at this point in the history
…es_clear
  • Loading branch information
Corwin-Kh committed Feb 6, 2025
2 parents 7230464 + 84866af commit 4f3706b
Show file tree
Hide file tree
Showing 376 changed files with 20,488 additions and 3,066 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/2-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ body:
```
OsmAnd Version:
Android/iOS version:
Android version:
Device model:
Crash-Logs: ?
```
Expand Down
17 changes: 13 additions & 4 deletions OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.osmand;

import net.osmand.util.ArabicNormalizer;

import java.util.Locale;


Expand Down Expand Up @@ -55,9 +57,16 @@ public Collator getCollator() {
public boolean matches(String name) {
return cmatches(collator, name, part, mode);
}


public static boolean cmatches(Collator collator, String fullName, String part, StringMatcherMode mode){

public static boolean cmatches(Collator collator, String fullName, String part, StringMatcherMode mode) {
if (ArabicNormalizer.isSpecialArabic(fullName)) {
String normalized = ArabicNormalizer.normalize(fullName);
fullName = normalized == null ? fullName : normalized;
}
if (ArabicNormalizer.isSpecialArabic(part)) {
String normalized = ArabicNormalizer.normalize(part);
part = normalized == null ? part : normalized;
}
switch (mode) {
case CHECK_CONTAINS:
return ccontains(collator, fullName, part);
Expand Down Expand Up @@ -195,7 +204,7 @@ private static String alignChars(String fullText) {
return fullText;
}

public static boolean isSpace(char c){
private static boolean isSpace(char c){
return !Character.isLetter(c) && !Character.isDigit(c);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.osmand.binary;

import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
Expand Down Expand Up @@ -200,7 +199,7 @@ public List<String> prepareStreetName(String s, boolean addCommonWords) {
List<String> ls = new ArrayList<String>();
int beginning = 0;
for (int i = 1; i < s.length(); i++) {
if (CollatorStringMatcher.isSpace(s.charAt(i))) {
if (Character.isWhitespace(s.charAt(i))) {
addWord(ls, s.substring(beginning, i), addCommonWords);
beginning = i + 1;
} else if (s.charAt(i) == '(') {
Expand Down
158 changes: 158 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/binary/HeightDataLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package net.osmand.binary;

import static net.osmand.router.RouteResultPreparation.SHIFT_ID;

import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion;
import net.osmand.data.QuadRect;
import net.osmand.shared.gpx.primitives.WptPt;
import net.osmand.util.MapUtils;

import org.apache.commons.logging.Log;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class HeightDataLoader {
public static final int ZOOM_TO_LOAD_TILES = 15;
public static final int ZOOM_TO_LOAD_TILES_SHIFT_L = ZOOM_TO_LOAD_TILES + 1;
public static final int ZOOM_TO_LOAD_TILES_SHIFT_R = 31 - ZOOM_TO_LOAD_TILES;

public interface InterfaceIsCancelled {
boolean isCancelled();
}

public interface InterfaceCancellableCallback<T> {
boolean callback(T object, InterfaceIsCancelled canceller);
}

private final static Log log = PlatformUtil.getLog(HeightDataLoader.class);
private final Map<RouteSubregion, List<RouteDataObject>> loadedSubregions = new HashMap<>();
private final Map<BinaryMapIndexReader, List<RouteSubregion>> readers = new LinkedHashMap<>();

public HeightDataLoader(BinaryMapIndexReader[] readers) {
for (BinaryMapIndexReader r : readers) {
List<RouteSubregion> subregions = new ArrayList<>();
for (BinaryMapRouteReaderAdapter.RouteRegion rInd : r.getRoutingIndexes()) {
List<RouteSubregion> subregs = rInd.getSubregions();
// create a copy to avoid leaks to the original structure
for (RouteSubregion rs : subregs) {
subregions.add(new RouteSubregion(rs));
}
}
this.readers.put(r, subregions);
}
}

public List<WptPt> loadHeightDataAsWaypoints(long osmId, QuadRect bbox31, InterfaceIsCancelled canceller) {
Map<Long, RouteDataObject> results = new HashMap<>();
ResultMatcher<RouteDataObject> matcher = new ResultMatcher<>() {
@Override
public boolean publish(RouteDataObject routeDataObject) {
return routeDataObject != null && routeDataObject.getId() >> SHIFT_ID == osmId;
}

@Override
public boolean isCancelled() {
return results.containsKey(osmId) || (canceller != null && canceller.isCancelled());
}
};

try {
loadRouteDataObjects(bbox31, results, matcher);
} catch (IOException e) {
log.error(e);
}

RouteDataObject found = results.get(osmId);
if (found != null && found.getPointsLength() > 0) {
List<WptPt> waypoints = new ArrayList<>();
float[] heightArray = found.calculateHeightArray();
for (int i = 0; i < found.getPointsLength(); i++) {
WptPt point = new WptPt();
point.setLat(MapUtils.get31LatitudeY(found.getPoint31YTile(i)));
point.setLon(MapUtils.get31LongitudeX(found.getPoint31XTile(i)));
if (heightArray != null && heightArray.length > i * 2 + 1) {
point.setEle(heightArray[i * 2 + 1]);
}
waypoints.add(point);
}
return waypoints;
}

return null;
}

private boolean loadRouteDataObjects(QuadRect bbox31,
Map<Long, RouteDataObject> results,
ResultMatcher<RouteDataObject> matcher) throws IOException {
int loaded = 0;
int left = (int) bbox31.left >> ZOOM_TO_LOAD_TILES_SHIFT_R;
int top = (int) bbox31.top >> ZOOM_TO_LOAD_TILES_SHIFT_R;
int right = (int) bbox31.right >> ZOOM_TO_LOAD_TILES_SHIFT_R;
int bottom = (int) bbox31.bottom >> ZOOM_TO_LOAD_TILES_SHIFT_R;
for (int x = left; x <= right; x++) {
for (int y = top; y <= bottom; y++) {
if (matcher != null && matcher.isCancelled()) {
return loaded > 0;
}
loaded += loadRouteDataObjects(x, y, results, matcher);
}
}
return loaded > 0;
}

private int loadRouteDataObjects(int x, int y,
Map<Long, RouteDataObject> results,
ResultMatcher<RouteDataObject> matcher) throws IOException {
int loaded = 0;
HashSet<Long> deletedIds = new HashSet<>();
Map<Long, BinaryMapRouteReaderAdapter.RouteRegion> usedIds = new HashMap<>();
BinaryMapIndexReader.SearchRequest<RouteDataObject> req = BinaryMapIndexReader.buildSearchRouteRequest(
x << ZOOM_TO_LOAD_TILES_SHIFT_L, (x + 1) << ZOOM_TO_LOAD_TILES_SHIFT_L,
y << ZOOM_TO_LOAD_TILES_SHIFT_L, (y + 1) << ZOOM_TO_LOAD_TILES_SHIFT_L, null);
for (Map.Entry<BinaryMapIndexReader, List<RouteSubregion>> readerSubregions : readers.entrySet()) {
req.clearSearchResults();
BinaryMapIndexReader reader = readerSubregions.getKey();
synchronized (reader) {
List<RouteSubregion> routeSubregions = readerSubregions.getValue();
List<RouteSubregion> subregions = reader.searchRouteIndexTree(req, routeSubregions);
for (RouteSubregion sub : subregions) {
List<RouteDataObject> objects = loadedSubregions.get(sub);
if (objects == null) {
objects = reader.loadRouteIndexData(sub);
loadedSubregions.put(sub, objects);
}
for (RouteDataObject obj : objects) {
if (matcher != null && matcher.isCancelled()) {
return loaded;
}
if (matcher == null || matcher.publish(obj)) {
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;
}
loaded += (results.put(obj.getId() >> SHIFT_ID, obj) == null) ? 1 : 0;
usedIds.put(obj.id, obj.region);
}
}
}
}
}
return loaded;
}
}
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 Expand Up @@ -804,7 +809,7 @@ public static String getRestrictionValue(int i) {
case RESTRICTION_ONLY_STRAIGHT_ON:
return "ONLY_STRAIGHT_ON".toLowerCase();
}
return "unkonwn";
return "unknown";

}

Expand Down
19 changes: 13 additions & 6 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 @@ -61,6 +60,8 @@ public class OsmRouteType {
public static final OsmRouteType TRACKS = createType("tracks").reg();
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 @@ -156,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 @@ -305,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 @@ -322,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 Expand Up @@ -459,5 +465,6 @@ protected static class RenderingPropertyAttr {
static final String RUNNING_ROUTES = "showRunningRoutes";
static final String FITNESS_TRAILS = "showFitnessTrails";
static final String DIRTBIKE_ROUTES = "showDirtbikeTrails";
static final String CLIMBING_ROUTES = "showClimbingRoutes";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public enum OSMTagKey {
PUBLIC_TRANSPORT("public_transport"), //$NON-NLS-1$
ENTRANCE("entrance"), //$NON-NLS-1$
COLOUR("colour"),
RELATION_ID("relation_id");
RELATION_ID("relation_id"),
CLIMBING("climbing"),
OSMAND_CLIMBING("osmand_climbing");


private final String value;
Expand Down
Loading

0 comments on commit 4f3706b

Please sign in to comment.