Fix adding markers on map amenity

This commit is contained in:
Alexander Sytnyk 2018-01-15 16:57:17 +02:00
parent 6cf701cd1f
commit 3b5ce64fed
6 changed files with 19 additions and 11 deletions

View file

@ -609,10 +609,12 @@ public class MapMarkersHelper {
} }
@Nullable @Nullable
public MapMarker getMapMarker(@NonNull String mapObjectName) { public MapMarker getMapMarker(@NonNull String mapObjectName, @NonNull LatLon latLon) {
for (MapMarker marker : mapMarkers) { for (MapMarker marker : mapMarkers) {
if (marker.mapObjectName != null && marker.mapObjectName.equals(mapObjectName)) { if (marker.mapObjectName != null && marker.mapObjectName.equals(mapObjectName) && marker.point != null) {
return marker; if (MapUtils.getDistance(latLon, marker.point) < 15) {
return marker;
}
} }
} }
return null; return null;

View file

@ -38,7 +38,6 @@ import net.osmand.plus.mapcontextmenu.MenuController.MenuType;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController; 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.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.PointEditor; import net.osmand.plus.mapcontextmenu.editors.PointEditor;
import net.osmand.plus.mapcontextmenu.editors.RtePtEditor; 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.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.RenameMarkerBottomSheetDialogFragment; import net.osmand.plus.mapmarkers.RenameMarkerBottomSheetDialogFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionMenuController;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
@ -808,8 +807,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
MapMarkersDialogFragment.showInstance(mapActivity); MapMarkersDialogFragment.showInstance(mapActivity);
} else { } 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(), mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForMarker(), object instanceof Amenity ? ((Amenity) object).getName() : null); getPointDescriptionForMarker(), mapObjectName);
} }
} else { } else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(), mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),

View file

@ -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) { if (marker != null) {
MapMarkerMenuController markerMenuController = MapMarkerMenuController markerMenuController =
new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker); new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker);

View file

@ -624,7 +624,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (searchLatLon == null) { if (searchLatLon == null) {
searchLatLon = tileBox.getLatLonFromPixel(point.x, point.y); 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 (amenity != null) {
if (renderedObject.getX() != null && renderedObject.getX().size() > 1 if (renderedObject.getX() != null && renderedObject.getX().size() > 1
&& renderedObject.getY() != null && renderedObject.getY().size() > 1) { && renderedObject.getY() != null && renderedObject.getY().size() > 1) {

View file

@ -556,7 +556,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
@Nullable @Nullable
public Amenity getMapObjectByMarker(@NonNull MapMarker marker) { public Amenity getMapObjectByMarker(@NonNull MapMarker marker) {
if (marker.mapObjectName != null && marker.point != null) { 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; return null;
} }

View file

@ -221,8 +221,8 @@ public abstract class OsmandMapLayer {
return rf; return rf;
} }
public Amenity findAmenity(OsmandApplication app, long id, List<String> names, LatLon latLon) { public Amenity findAmenity(OsmandApplication app, long id, List<String> names, LatLon latLon, int radius) {
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 50); QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius);
List<Amenity> amenities = app.getResourceManager().searchAmenities( List<Amenity> amenities = app.getResourceManager().searchAmenities(
new BinaryMapIndexReader.SearchPoiTypeFilter() { new BinaryMapIndexReader.SearchPoiTypeFilter() {
@Override @Override