Skip to content

Commit

Permalink
Merge branch 'master' into fix_#18357
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Dec 19, 2024
2 parents 164f291 + 2a2c8a9 commit b6dae98
Show file tree
Hide file tree
Showing 95 changed files with 2,074 additions and 1,227 deletions.
3 changes: 2 additions & 1 deletion OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.IndexConstants.GPX_GZ_FILE_EXT;
import static net.osmand.data.Amenity.ROUTE_ID;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -696,7 +697,7 @@ public List<String> getOriginalNames() {

public String getRouteID() {
for (Map.Entry<String, String> entry : getTags().entrySet()) {
if ("route_id".equals(entry.getKey())) {
if (ROUTE_ID.equals(entry.getKey())) {
return entry.getValue();
}
}
Expand Down
47 changes: 40 additions & 7 deletions OsmAnd-java/src/main/java/net/osmand/data/Amenity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.osmand.data;

import static net.osmand.gpx.GPXUtilities.AMENITY_PREFIX;
import static net.osmand.gpx.GPXUtilities.OSM_PREFIX;
import static net.osmand.gpx.GPXUtilities.*;
import static net.osmand.osm.MapPoiTypes.ROUTES_PREFIX;
import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE_POINT;
import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK;
import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK_POINT;
import static net.osmand.shared.gpx.GpxFile.XML_COLON;

import net.osmand.Location;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
Expand Down Expand Up @@ -48,6 +52,7 @@ public class Amenity extends MapObject {
public static final String IS_AGGR_PART = "is_aggr_part";
public static final String CONTENT_JSON = "content_json";
public static final String ROUTE_ID = "route_id";
public static final String ROUTE_ID_OSM_PREFIX = "OSM";
public static final String ROUTE_SOURCE = "route_source";
public static final String ROUTE_NAME = "route_name";
public static final String COLOR = "color";
Expand Down Expand Up @@ -169,7 +174,7 @@ public String getAdditionalInfo(String key) {
}
String str = additionalInfo.get(key);
if (str == null && key.contains(":")) {
str = additionalInfo.get(key.replaceAll(":", "_-_")); // try content_-_uk after content:uk
str = additionalInfo.get(key.replaceAll(":", XML_COLON)); // try content_-_uk after content:uk
}
if (str != null) {
str = unzipContent(str);
Expand Down Expand Up @@ -309,7 +314,7 @@ public StringBuilder printNamesAndAdditional() {
private void printNames(String prefix, Map<String, String> stringMap, StringBuilder s) {
for (Entry<String, String> e : stringMap.entrySet()) {
if (e.getValue().startsWith(" gz ")) {
s.append(prefix).append(e.getKey()).append("='gzip ...'");
s.append(prefix).append(e.getKey()).append("='gzip ...' ");
} else {
s.append(prefix).append(e.getKey()).append("='").append(e.getValue()).append("' ");
}
Expand Down Expand Up @@ -347,10 +352,11 @@ public String getColor() {
}

public String getGpxIcon() {
return getAdditionalInfo(GPX_ICON);
String wikiVoyageIcon = getAdditionalInfo(GPX_ICON);
String travelGpxIcon = getAdditionalInfo(ICON_NAME_EXTENSION);
return Algorithms.isEmpty(wikiVoyageIcon) ? travelGpxIcon : wikiVoyageIcon;
}


public String getContentLanguage(String tag, String lang, String defLang) {
if (lang != null) {
String translateName = getAdditionalInfo(tag + ":" + lang);
Expand Down Expand Up @@ -432,7 +438,7 @@ public String getTagContent(String tag, String lang) {
return translateName;
}
for (String nm : getAdditionalInfoKeys()) {
if (nm.startsWith(tag + ":") || nm.startsWith(tag + "_-_")) {
if (nm.startsWith(tag + ":") || nm.startsWith(tag + XML_COLON)) {
return getAdditionalInfo(nm);
}
}
Expand All @@ -447,6 +453,25 @@ public String getRouteId() {
return getAdditionalInfo(ROUTE_ID);
}

public boolean hasOsmRouteId() {
String routeId = getRouteId();
return routeId != null && routeId.startsWith(ROUTE_ID_OSM_PREFIX);
}

public String getGpxFileName(String lang) {
final String gpxFileName = lang != null ? getName(lang) : getEnName(true);
if (!Algorithms.isEmpty(gpxFileName)) {
return gpxFileName;
}
if (!Algorithms.isEmpty(getRouteId())) {
return getRouteId();
}
if (!Algorithms.isEmpty(getSubType())) {
return getType().getKeyName() + " " + getSubType();
}
return getType().getKeyName();
}

public String getStrictTagContent(String tag, String lang) {
if (lang != null) {
String translateName = getAdditionalInfo(tag + ":" + lang);
Expand Down Expand Up @@ -549,6 +574,14 @@ public boolean isPrivateAccess() {
return PRIVATE_VALUE.equals(getTagContent(ACCESS_PRIVATE_TAG));
}

public boolean isRouteTrack() {
return subType != null && (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTES_PREFIX));
}

public boolean isRoutePoint() {
return subType != null && (subType.equals(ROUTE_TRACK_POINT) || subType.equals(ROUTE_ARTICLE_POINT));
}

public JSONObject toJSON() {
JSONObject json = super.toJSON();
json.put("subType", subType);
Expand Down
3 changes: 2 additions & 1 deletion OsmAnd-java/src/main/java/net/osmand/gpx/GPXUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import static net.osmand.gpx.GPXUtilities.RouteSegment.START_TRKPT_IDX_ATTR;
import static net.osmand.shared.gpx.GpxFile.XML_COLON;
import static net.osmand.util.Algorithms.isDigit;

import net.osmand.IProgress;
Expand Down Expand Up @@ -1363,7 +1364,7 @@ private static String getOsmandTagKey(final Entry<String, String> entry) {
if (key.startsWith(OSMAND_EXTENSIONS_PREFIX)) {
key = key.replace(OSMAND_EXTENSIONS_PREFIX, "");
}
key = key.replace(":", "_-_");
key = key.replace(":", XML_COLON);
return OSMAND_EXTENSIONS_PREFIX + key;
}

Expand Down
24 changes: 17 additions & 7 deletions OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


public class MapPoiTypes {
private static final String OTHER_MAP_CATEGORY = "Other";
public static final String OTHER_MAP_CATEGORY = "Other";
private static MapPoiTypes DEFAULT_INSTANCE = null;
private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class);
private String resourceName;
Expand All @@ -48,7 +48,8 @@ public class MapPoiTypes {
public static final String ROUTE_ARTICLE = "route_article";
public static final String ROUTE_ARTICLE_POINT = "route_article_point";
public static final String CATEGORY = "category";
public static final String ROUTE_TRACK = "route_track";
public static final String ROUTE_TRACK = "route_track"; // routes:route_track (no activity)
public static final String ROUTES_PREFIX = "routes_"; // routes:routes_xxx (any activity type)
public static final String ROUTE_TRACK_POINT = "route_track_point";

private PoiTranslator poiTranslator = null;
Expand Down Expand Up @@ -970,11 +971,7 @@ public String replaceDeprecatedSubtype(PoiCategory type, String subtype) {
}

public Amenity parseAmenity(String tag, String val, boolean relation, Map<String, String> otherTags) {
initPoiTypesByTag();
PoiType pt = poiTypesByTag.get(tag + "/" + val);
if (pt == null) {
pt = poiTypesByTag.get(tag);
}
PoiType pt = getPoiTypeByTagValue(tag, val);
if (pt == null || pt.isAdditional()) {
return null;
}
Expand Down Expand Up @@ -1032,6 +1029,19 @@ public Amenity parseAmenity(String tag, String val, boolean relation, Map<String
return a;
}


public PoiType getPoiTypeByTagValue(String tag, String val) {
initPoiTypesByTag();
PoiType pt = poiTypesByTag.get(tag + "/" + val);
if (pt == null) {
pt = poiTypesByTag.get(tag);
}
// if (pt == null) {
// pt = poitypesbytag.get(tag + "/" + "null"); // required when no type="text" specified
// }
return pt;
}

public boolean isTextAdditionalInfo(String key, String value) {
if (key.startsWith("name:") || key.equals("name")) {
return true;
Expand Down
9 changes: 5 additions & 4 deletions OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package net.osmand.search;

import static net.osmand.data.Amenity.ROUTE_ID;
import static net.osmand.osm.MapPoiTypes.ROUTES_PREFIX;
import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK;

import net.osmand.CallbackWithObject;
import net.osmand.Collator;
import net.osmand.PlatformUtil;
Expand Down Expand Up @@ -289,11 +293,8 @@ public boolean sameSearchResult(SearchResult r1, SearchResult r2) {
|| (subType1.startsWith("route_hiking_") && subType1.endsWith("n_poi"))) {
similarityRadius = 50000;
}
final String ROUTE_ID = "route_id";
final String ROUTE_TRACK = "route_track";
final String ROUTE_TYPE_PREFIX = "activities_";
if (Algorithms.stringsEqual(a1.getAdditionalInfo(ROUTE_ID), a2.getAdditionalInfo(ROUTE_ID))
&& (subType1.startsWith(ROUTE_TYPE_PREFIX) || subType1.equals(ROUTE_TRACK))) {
&& (subType1.startsWith(ROUTES_PREFIX) || subType1.equals(ROUTE_TRACK))) {
similarityRadius = 50000;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,9 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase)
Collections.sort(possibleValues);
for (String s : possibleValues) {
translate = getTopIndexTranslation(s);
String normalizeBrand = s.toLowerCase(Locale.ROOT);
if (complete) {
if (CollatorStringMatcher.cmatches(collator, search, s, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
if (CollatorStringMatcher.cmatches(collator, search, normalizeBrand, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
topIndexValue = s;
break;
} else {
Expand Down Expand Up @@ -1171,7 +1172,7 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase)
private String getTopIndexTranslation(String value) {
String key = TopIndexFilter.getValueKey(value);
String translate = types.getPoiTranslation(key);
if (translate.toLowerCase().equals(key)) {
if (translate.toLowerCase(Locale.ROOT).equals(key)) {
translate = value;
}
return translate;
Expand Down
9 changes: 9 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/wiki/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Metadata {
private String date;
private String author;
private String license;
private String description;

public String getDate() {
return date;
Expand All @@ -29,4 +30,12 @@ public String getLicense() {
public void setLicense(String license) {
this.license = license;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
16 changes: 9 additions & 7 deletions OsmAnd-java/src/main/java/net/osmand/wiki/WikiCoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected static List<WikiImage> getWikidataImageWikidata(String wikidataId, Lis
private static List<WikiImage> getImagesOsmAndAPIRequestV2(String url, List<WikiImage> wikiImages) {
OsmandAPIResponseV2 response = sendWikipediaApiRequest(url, OsmandAPIResponseV2.class);
if (response != null && !Algorithms.isEmpty(response.images)) {
for (Map<String, Object> image : response.images) {
for (Map<String, String> image : response.images) {
WikiImage wikiImage = parseImageDataWithMetaData(image);
if (wikiImage != null && isUrlFileImage(wikiImage)) {
wikiImages.add(wikiImage);
Expand Down Expand Up @@ -187,25 +187,27 @@ private static List<WikiImage> getImagesOsmAndAPIRequest(String url, List<WikiIm
return wikiImages;
}

private static WikiImage parseImageDataWithMetaData(Map<String, Object> image) {
String imageUrl = (String) image.get("image");
private static WikiImage parseImageDataWithMetaData(Map<String, String> image) {
String imageUrl = image.get("image");
if (!Algorithms.isEmpty(image)) {
WikiImage wikiImage = parseImageDataFromFile(imageUrl);
if (wikiImage != null) {
Metadata metadata = wikiImage.getMetadata();

String date = (String) image.get("date");
String date = image.get("date");
if (date != null) {
metadata.setDate(date);
}
String author = (String) image.get("author");
String author = image.get("author");
if (date != null) {
metadata.setAuthor(author);
}
String license = (String) image.get("license");
String license = image.get("license");
if (date != null) {
metadata.setLicense(license);
}
long mediaId = Algorithms.parseLongSilently(image.get("mediaId"), -1);
wikiImage.setMediaId(mediaId);
return wikiImage;
}
}
Expand Down Expand Up @@ -258,7 +260,7 @@ private static <T> T sendWikipediaApiRequest(String url, Class<T> responseClass)
public static class OsmandAPIResponseV2 {
@SerializedName("features-v2")
@Expose
private final Set<Map<String, Object>> images = null;
private final Set<Map<String, String>> images = null;
}

public static class OsmandAPIResponse {
Expand Down
9 changes: 9 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/wiki/WikiImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class WikiImage {
private final String imageName;
private final String imageStubUrl;
private final String imageHiResUrl;
private long mediaId = -1;

private final Metadata metadata = new Metadata();

Expand All @@ -19,6 +20,14 @@ public WikiImage(String wikiMediaTag, String imageName, String imageStubUrl, Str
this.imageHiResUrl = imageHiResUrl;
}

public void setMediaId(long mediaId) {
this.mediaId = mediaId;
}

public long getMediaId() {
return mediaId;
}

public String getUrlWithCommonAttributions() {
return WIKIMEDIA_COMMONS_URL + WIKIMEDIA_FILE + wikiMediaTag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,5 +894,6 @@ class GpxFile : GpxExtensions {
companion object {
const val OSMAND_AUTHOR_PREFIX = "OsmAnd"
const val DEFAULT_WPT_GROUP_NAME = ""
const val XML_COLON = "_-_"
}
}
Loading

0 comments on commit b6dae98

Please sign in to comment.