Skip to content

Commit

Permalink
Allow v2 getAmenity() to find route=point w/o name
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Nov 24, 2024
1 parent 7fd3bbc commit c22f9f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/data/Amenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE;
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 net.osmand.Location;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
Expand Down Expand Up @@ -571,6 +572,10 @@ 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
13 changes: 11 additions & 2 deletions OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.binary.BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER;
import static net.osmand.data.Amenity.ROUTE;
import static net.osmand.data.Amenity.ROUTE_ID;
import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE;
import static net.osmand.data.MapObject.AMENITY_ID_RIGHT_SHIFT;
import static net.osmand.osm.OsmRouteType.HIKING;
import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT;
import static net.osmand.plus.wikivoyage.data.TravelGpx.TRAVEL_OSM_ID_TAG;
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN;
import static net.osmand.router.network.NetworkRouteSelector.NetworkRouteSelectorFilter;
import static net.osmand.router.network.NetworkRouteSelector.RouteKey;
Expand Down Expand Up @@ -357,7 +359,7 @@ private void selectObjectsFromOpenGl(@NonNull MapSelectionResult result, @NonNul
latLon = l == null ? latLon : l;
tags.remove(TAG_POI_LAT_LON);
}
amenity = getAmenity(latLon, obfMapObject);
amenity = getAmenity(latLon, obfMapObject, tags);
if (amenity != null) {
amenity.setMapIconName(getMapIconName(symbolInfo));
} else if (!isOsmRoute && !isTravelGpx) {
Expand Down Expand Up @@ -438,13 +440,16 @@ private RasterMapSymbol getRasterMapSymbol(@NonNull MapSymbolInformation symbolI
return null;
}

private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject) {
private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject, Map<String, String> tags) {
Amenity amenity;
List<String> names = getValues(obfMapObject.getCaptionsInAllLanguages());
String caption = obfMapObject.getCaptionInNativeLanguage();
if (!caption.isEmpty()) {
names.add(caption);
}
if (!Algorithms.isEmpty(tags) && tags.containsKey(TRAVEL_OSM_ID_TAG) && "point".equals(tags.get(ROUTE))) {
names.add(tags.get(TRAVEL_OSM_ID_TAG)); // additional attribute for TravelGpx points (osm_id)
}
long id = obfMapObject.getId().getId().longValue();
amenity = findAmenity(app, latLon, names, id);
if (amenity != null && obfMapObject.getPoints31().size() > 1) {
Expand Down Expand Up @@ -711,10 +716,14 @@ public static Amenity findAmenityByOsmId(@NonNull List<Amenity> amenities, long
public static Amenity findAmenityByName(@NonNull List<Amenity> amenities, @Nullable List<String> names) {
if (!Algorithms.isEmpty(names)) {
for (Amenity amenity : amenities) {
String travelOsmId = amenity.isRoutePoint() ? amenity.getAdditionalInfo(TRAVEL_OSM_ID_TAG) : null;
for (String name : names) {
if (name.equals(amenity.getName()) && !amenity.isClosed()) {
return amenity;
}
if (travelOsmId != null && name.equals(travelOsmId)) {
return amenity;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class TravelGpx extends TravelArticle {
public static final String ROUTE_RADIUS = "route_radius";
public static final String USER = "user";
public static final String ACTIVITY_TYPE = "route_activity_type";
public static final String TRAVEL_OSM_ID_TAG = "osm_id";

public String user;
public String activityType;
Expand Down

0 comments on commit c22f9f1

Please sign in to comment.