From 3b5ce64fed1d0b5b3baeca933cade9d249d19c61 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 15 Jan 2018 16:57:17 +0200 Subject: [PATCH] Fix adding markers on map amenity --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 8 +++++--- .../net/osmand/plus/mapcontextmenu/MapContextMenu.java | 10 +++++++--- .../controllers/AmenityMenuController.java | 3 ++- OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java | 2 +- OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java | 3 ++- OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java | 4 ++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 0d69166011..8628528cef 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -609,10 +609,12 @@ public class MapMarkersHelper { } @Nullable - public MapMarker getMapMarker(@NonNull String mapObjectName) { + public MapMarker getMapMarker(@NonNull String mapObjectName, @NonNull LatLon latLon) { for (MapMarker marker : mapMarkers) { - if (marker.mapObjectName != null && marker.mapObjectName.equals(mapObjectName)) { - return marker; + if (marker.mapObjectName != null && marker.mapObjectName.equals(mapObjectName) && marker.point != null) { + if (MapUtils.getDistance(latLon, marker.point) < 15) { + return marker; + } } } return null; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index a6d14121b6..1d6bac7615 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -38,7 +38,6 @@ import net.osmand.plus.mapcontextmenu.MenuController.MenuType; import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController; -import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.PointEditor; import net.osmand.plus.mapcontextmenu.editors.RtePtEditor; @@ -48,8 +47,8 @@ import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.RenameMarkerBottomSheetDialogFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; -import net.osmand.plus.parkingpoint.ParkingPositionMenuController; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -808,8 +807,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL MapActivity.clearPrevActivityIntent(); MapMarkersDialogFragment.showInstance(mapActivity); } else { + String mapObjectName = null; + if (object instanceof Amenity) { + Amenity amenity = (Amenity) object; + mapObjectName = amenity.getName() + "_" + amenity.getType().getKeyName(); + } mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), - getPointDescriptionForMarker(), object instanceof Amenity ? ((Amenity) object).getName() : null); + getPointDescriptionForMarker(), mapObjectName); } } else { mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 1fdef001f4..62102af5c3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -59,7 +59,8 @@ public class AmenityMenuController extends MenuController { } } - marker = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarker(amenity.getName()); + String mapNameForMarker = amenity.getName() + "_" + amenity.getType().getKeyName(); + marker = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarker(mapNameForMarker, amenity.getLocation()); if (marker != null) { MapMarkerMenuController markerMenuController = new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker); diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 02f579a3c1..ec086ffd31 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -624,7 +624,7 @@ public class ContextMenuLayer extends OsmandMapLayer { if (searchLatLon == null) { searchLatLon = tileBox.getLatLonFromPixel(point.x, point.y); } - Amenity amenity = findAmenity(activity.getMyApplication(), renderedObject.getId() >> 7, names, searchLatLon); + Amenity amenity = findAmenity(activity.getMyApplication(), renderedObject.getId() >> 7, names, searchLatLon, 50); if (amenity != null) { if (renderedObject.getX() != null && renderedObject.getX().size() > 1 && renderedObject.getY() != null && renderedObject.getY().size() > 1) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 34216fc1c2..dc928b52ed 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -556,7 +556,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Nullable public Amenity getMapObjectByMarker(@NonNull MapMarker marker) { if (marker.mapObjectName != null && marker.point != null) { - return findAmenity(map.getMyApplication(), -1, Collections.singletonList(marker.mapObjectName), marker.point); + String mapObjName = marker.mapObjectName.split("_")[0]; + return findAmenity(map.getMyApplication(), -1, Collections.singletonList(mapObjName), marker.point, 15); } return null; } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 46e1d76cd5..818a172173 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -221,8 +221,8 @@ public abstract class OsmandMapLayer { return rf; } - public Amenity findAmenity(OsmandApplication app, long id, List names, LatLon latLon) { - QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 50); + public Amenity findAmenity(OsmandApplication app, long id, List names, LatLon latLon, int radius) { + QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius); List amenities = app.getResourceManager().searchAmenities( new BinaryMapIndexReader.SearchPoiTypeFilter() { @Override