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 Oct 31, 2024
2 parents 34407c1 + 2b14764 commit 74de444
Show file tree
Hide file tree
Showing 142 changed files with 3,493 additions and 1,432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2275,10 +2275,12 @@ public String toString() {
private static boolean testAddressSearch = false;
private static boolean testAddressSearchName = false;
private static boolean testAddressJustifySearch = false;
private static boolean testPoiSearch = true;
private static boolean testPoiSearch = false;
private static boolean testPoiSearchOnPath = false;
private static boolean testTransportSearch = false;

private static boolean testPoiRouteByName = true;
private static boolean testPoiRouteByType = true;

private static int sleft = MapUtils.get31TileNumberX(27.55079);
private static int sright = MapUtils.get31TileNumberX(27.55317);
private static int stop = MapUtils.get31TileNumberY(53.89378);
Expand Down Expand Up @@ -2319,13 +2321,25 @@ public static void main(String[] args) throws IOException {
PoiRegion poiRegion = reader.getPoiIndexes().get(0);
if (testPoiSearch) {
testPoiSearch(reader, poiRegion);
testPoiSearchByName(reader);
testPoiSearchByName(reader, "central ukraine", 0, 0);
}
if (testPoiSearchOnPath) {
testSearchOnthePath(reader);
}
}

if (testPoiRouteByName || testPoiRouteByType) {
int y = MapUtils.get31TileNumberY(36.023431);
int x = MapUtils.get31TileNumberX(14.298406);
if (testPoiRouteByName) {
testPoiSearchByName(reader, "Gozo Coastal Walk", x, y); // Malta - Gozo Island - osm_hiking track
}
if (testPoiRouteByType) {
testPoiSearchByType(reader, "routes", "osm_hiking", x, y);
// testPoiSearchByType(reader, "routes", null, x, y);
}
}

println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); //$NON-NLS-1$
println("Time " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
}
Expand Down Expand Up @@ -2436,16 +2450,49 @@ private static List<Location> readGPX(File f) {
}
return res;
}
private static void testPoiSearchByType(BinaryMapIndexReader reader, String askType, String askSubType, int x, int y) throws IOException {
println("Searching by type/subtype...");

SearchRequest<Amenity> req = buildSearchPoiRequest(x, y, "", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
new SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
return type.getKeyName().equals(askType) && (askSubType == null || subcategory.equals(askSubType));
}
@Override
public boolean isEmpty() {
return false;
}
}, null, null);

reader.searchPoi(req);
for (Amenity a : req.getSearchResults()) {
int distance = 0;
if (x > 0 && y > 0) {
distance = (int)MapUtils.getDistance(a.getLocation(),
MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x));
}
println(a.getType().getTranslation() +
" " + a.getSubType() + " " + a.getName() + " " + a.getLocation() +
(distance > 0 ? (" Dist " + distance + " m") : ""));
}
}

private static void testPoiSearchByName(BinaryMapIndexReader reader) throws IOException {
private static void testPoiSearchByName(BinaryMapIndexReader reader, String query, int x, int y) throws IOException {
println("Searching by name...");
SearchRequest<Amenity> req = buildSearchPoiRequest(0, 0, "central ukraine",
SearchRequest<Amenity> req = buildSearchPoiRequest(x, y, query,
0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, null);

reader.searchPoiByName(req);
for (Amenity a : req.getSearchResults()) {
int distance = 0;
if (x > 0 && y > 0) {
distance = (int)MapUtils.getDistance(a.getLocation(),
MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x));
}
println(a.getType().getTranslation() +
" " + a.getSubType() + " " + a.getName() + " " + a.getLocation());
" " + a.getSubType() + " " + a.getName() + " " + a.getLocation() +
(distance > 0 ? (" Dist " + distance + " m") : ""));
}
}

Expand Down
9 changes: 7 additions & 2 deletions OsmAnd-java/src/main/java/net/osmand/data/Amenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ public String getAdditionalInfo(String key) {
return null;
}
String str = additionalInfo.get(key);
str = unzipContent(str);
if (str == null && key.contains(":")) {
str = additionalInfo.get(key.replaceAll(":", "_-_")); // try content_-_uk after content:uk
}
if (str != null) {
str = unzipContent(str);
}
return str;
}

Expand Down Expand Up @@ -425,7 +430,7 @@ public String getTagContent(String tag, String lang) {
return translateName;
}
for (String nm : getAdditionalInfoKeys()) {
if (nm.startsWith(tag + ":")) {
if (nm.startsWith(tag + ":") || nm.startsWith(tag + "_-_")) {
return getAdditionalInfo(nm);
}
}
Expand Down
2 changes: 2 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/map/OsmandRegions.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ public void structureWorldRegions(List<WorldRegion> loadedItems) {
it.remove();
} else if (region.getRegionId().contains("basemap")) {
it.remove();
} else if (region.getRegionId().startsWith("World_")) {
it.remove();
}
} else {
it.remove();
Expand Down
9 changes: 6 additions & 3 deletions OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,13 @@ public void initFromInputStream(InputStream is) {
}
}
}
default -> log.warn("Unknown start tag encountered: " + name);
case "poi_types" -> {
// just ignore the root tag of poi_types.xml
}
default -> log.warn("Unknown start tag encountered: " + name);
}
} else if (tok == XmlPullParser.END_TAG) {
String name = parser.getName();
} else if (tok == XmlPullParser.END_TAG) {
String name = parser.getName();
switch (name) {
case "poi_filter" -> {
if (!lastFilterPoiAdditionalsCategories.isEmpty()) {
Expand Down
21 changes: 21 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/osm/OsmRouteType.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "btt":
case "vth":
case "mtb ride":
case "disused:mtb":
case "abandoned:mtb":
return MOUNTAINBIKE;
case "hiking":
case "route=hiking":
Expand All @@ -164,6 +166,13 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "randonnée":
case "trekking":
case "climbing":
case "ferrata":
case "via_ferrata":
case "proposed:hiking":
case "deprecated:hiking":
case "abandoned:hiking":
case "old_hiking":
case "canyoning":
return HIKING;
case "bike":
case "biking":
Expand Down Expand Up @@ -194,6 +203,8 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "network=ncn":
case "network=icn":
case "network=lcn":
case "proposed:bicycle":
case "old_bicycle":
return CYCLING;
case "car":
case "motorcar":
Expand Down Expand Up @@ -249,6 +260,8 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "network=iwn":
case "network=lwn":
case "network=rwn":
case "unmarked:foot":
case "nordic_walking":
return WALKING;
case "ling-moto":
case "motorbiking":
Expand Down Expand Up @@ -277,6 +290,9 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "lake":
case "lakes":
case "canal":
case "waterway":
case "motorboat":
case "canoe":
return WATER;
case "ski":
case "skiing":
Expand All @@ -289,6 +305,7 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "лыжня":
case "nordic":
case "piste":
case "piste:type=nordic":
return WINTER;
case "snowmobile=designated":
case "snowmobile=permissive":
Expand All @@ -301,6 +318,10 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
return RIDING;
case "racing":
return RACING;
case "inline_skates":
return INLINE_SKATES;
case "fitness_trail":
return FITNESS;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import net.osmand.binary.BinaryMapDataObject;
import net.osmand.util.Algorithms;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class RenderingRuleSearchRequest {

Expand Down Expand Up @@ -54,6 +58,29 @@ public RenderingRuleSearchRequest(RenderingRuleSearchRequest searchRequest) {
saveState();
}

public static RenderingRuleSearchRequest initWithCustomProperties(RenderingRulesStorage renderingRules, int zoom,
Map<String, String> customProperties) {
RenderingRuleSearchRequest searchRequest = new RenderingRuleSearchRequest(renderingRules);

for (RenderingRuleProperty customProp : renderingRules.PROPS.getCustomRules()) {
String custom = customProperties != null ? customProperties.get(customProp.getAttrName()) : null;
if (customProp.isBoolean()) {
searchRequest.setBooleanFilter(customProp, custom != null ? "true".equals(custom) : false);
} else {
searchRequest.setStringFilter(customProp, custom != null ? custom : "");
}
}

if (zoom > 0) {
searchRequest.setIntFilter(renderingRules.PROPS.R_MINZOOM, zoom);
searchRequest.setIntFilter(renderingRules.PROPS.R_MAXZOOM, zoom);
}

searchRequest.saveState();

return searchRequest;
}

RenderingRulesStorage getStorage() {
return storage;
}
Expand Down Expand Up @@ -348,4 +375,68 @@ public String toString() {
}
return builder.toString();
}
}

public String searchIconByTags(Map<String, String> transformedTags) {
return searchTopOrderedPropertyByTags(transformedTags, RenderingRulesStorage.POINT_RULES,
storage.PROPS.R_ICON, storage.PROPS.R_ICON_ORDER);
}

private String searchTopOrderedPropertyByTags(Map<String, String> transformedTags, int rulesNumber,
RenderingRuleProperty mainStringProperty,
RenderingRuleProperty orderIntProperty) {

Map<String, Integer> resultOrderMap = new HashMap<>();

for (Map.Entry<String, String> entry : transformedTags.entrySet()) {
final String tag = entry.getKey();
final String value = entry.getValue();
clearState();
setStringFilter(storage.PROPS.R_TAG, tag);
setStringFilter(storage.PROPS.R_VALUE, value);
clearValue(storage.PROPS.R_ADDITIONAL); // parent - no additional

int order = 0;
String result = null;
search(rulesNumber);

if (isSpecified(mainStringProperty)) {
result = getStringPropertyValue(mainStringProperty);
order = orderIntProperty != null ? getIntPropertyValue(orderIntProperty) : 0;
}

// Cycle tags to visit "additional" rules. XXX: think how to optimize.
for (Map.Entry<String, String> additional : transformedTags.entrySet()) {
final String aTag = additional.getKey();
final String aValue = additional.getValue();

if (aTag.equals(tag) && aValue.equals(value)) {
continue;
}

setStringFilter(storage.PROPS.R_ADDITIONAL, aTag + "=" + aValue);
search(rulesNumber);

if (isSpecified(mainStringProperty)) {
String childResult = getStringPropertyValue(mainStringProperty);
if (childResult != null && (result == null || !result.equals(childResult))) {
order = orderIntProperty != null ? getIntPropertyValue(orderIntProperty) : 0;
result = childResult;
break; // enough
}
}
}

if (result != null) {
resultOrderMap.put(result, order);
}
}

if (!resultOrderMap.isEmpty()) {
Map.Entry<String, Integer> bestResult =
Collections.min(resultOrderMap.entrySet(), Comparator.comparingInt(Map.Entry::getValue));
return bestResult.getKey();
}

return null;
}
}
Loading

0 comments on commit 74de444

Please sign in to comment.