diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index c7cf92df0f..84a63cb72a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.builders.cards; import android.content.res.ColorStateList; import android.graphics.Bitmap; +import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.view.View; @@ -16,9 +17,13 @@ import androidx.appcompat.widget.AppCompatButton; import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities; import net.osmand.Location; import net.osmand.data.Amenity; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; +import net.osmand.data.RotatedTileBox; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; @@ -26,6 +31,8 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapillary.MapillaryContributeCard; import net.osmand.plus.mapillary.MapillaryImageCard; +import net.osmand.plus.osmedit.OsmBugsLayer; +import net.osmand.plus.views.layers.ContextMenuLayer; import net.osmand.plus.wikimedia.WikiImageHelper; import net.osmand.util.Algorithms; @@ -43,6 +50,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; + public abstract class ImageCard extends AbstractCard { public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; @@ -411,7 +420,7 @@ public abstract class ImageCard extends AbstractCard { } public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon, - @Nullable Map params, GetImageCardsListener listener) { + @Nullable Map params, GetImageCardsListener listener) { this.mapActivity = mapActivity; this.app = mapActivity.getMyApplication(); this.latLon = latLon; @@ -422,64 +431,100 @@ public abstract class ImageCard extends AbstractCard { @Override protected List doInBackground(Void... params) { List result = new ArrayList<>(); - try { + RotatedTileBox rtb = mapActivity.getMapView().getCurrentRotatedTileBox(); + Object o = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject(); + if (this.params != null) { + String wikidataId = this.params.get(Amenity.WIKIDATA); + if (wikidataId != null) { + this.params.remove(Amenity.WIKIDATA); + WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result); + } + String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS); + if (wikimediaContent != null) { + this.params.remove(Amenity.WIKIMEDIA_COMMONS); + WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result); + } + } + if (o instanceof Amenity) { + Amenity am = (Amenity) o; + System.out.println("POINT OSM ID: " + am.getId() + " " + am.getType().ordinal()); final Map pms = new LinkedHashMap<>(); - pms.put("lat", "" + (float) latLon.getLatitude()); - pms.put("lon", "" + (float) latLon.getLongitude()); - Location myLocation = app.getLocationProvider().getLastKnownLocation(); - if (myLocation != null) { - pms.put("mloc", "" + (float) myLocation.getLatitude() + "," + (float) myLocation.getLongitude()); - } - pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); - String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); - if (Algorithms.isEmpty(preferredLang)) { - preferredLang = app.getLanguage(); - } - if (!Algorithms.isEmpty(preferredLang)) { - pms.put("lang", preferredLang); - } - if (this.params != null) { - String wikidataId = this.params.get(Amenity.WIKIDATA); - if (wikidataId != null) { - this.params.remove(Amenity.WIKIDATA); - WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result); - } - String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS); - if (wikimediaContent != null) { - this.params.remove(Amenity.WIKIMEDIA_COMMONS); - WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result); - } - pms.putAll(this.params); - } + pms.put("osmid", "" + am.getId()); String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, "Requesting location images...", false, false); if (!Algorithms.isEmpty(response)) { - JSONObject obj = new JSONObject(response); - JSONArray images = obj.getJSONArray("features"); - if (images.length() > 0) { - for (int i = 0; i < images.length(); i++) { - try { - JSONObject imageObject = (JSONObject) images.get(i); - if (imageObject != JSONObject.NULL) { - ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); - if (imageCard != null) { - result.add(imageCard); + JSONObject obj = null; + try { + obj = new JSONObject(response); + JSONArray images = null; + images = obj.getJSONArray("features"); + if (images.length() > 0) { + for (int i = 0; i < images.length(); i++) { + try { + JSONObject imageObject = (JSONObject) images.get(i); + if (imageObject != JSONObject.NULL) { + ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); + if (imageCard != null) { + result.add(imageCard); + } } + } catch (JSONException e) { + e.printStackTrace(); } - } catch (JSONException e) { - e.printStackTrace(); } } + } catch (JSONException e) { + e.printStackTrace(); } } - } catch (Exception e) { - e.printStackTrace(); - } - if (listener != null) { - listener.onPostProcess(result); } return result; +// try { +// final Map pms = new LinkedHashMap<>(); +// pms.put("lat", "" + (float) latLon.getLatitude()); +// pms.put("lon", "" + (float) latLon.getLongitude()); +// Location myLocation = app.getLocationProvider().getLastKnownLocation(); +// if (myLocation != null) { +// pms.put("mloc", "" + (float) myLocation.getLatitude() + "," + (float) myLocation.getLongitude()); +// } +// pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); +// String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); +// if (Algorithms.isEmpty(preferredLang)) { +// preferredLang = app.getLanguage(); +// } +// if (!Algorithms.isEmpty(preferredLang)) { +// pms.put("lang", preferredLang); +// } +// String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, +// "Requesting location images...", false, false); +// +// if (!Algorithms.isEmpty(response)) { +// JSONObject obj = new JSONObject(response); +// JSONArray images = obj.getJSONArray("features"); +// if (images.length() > 0) { +// for (int i = 0; i < images.length(); i++) { +// try { +// JSONObject imageObject = (JSONObject) images.get(i); +// if (imageObject != JSONObject.NULL) { +// ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); +// if (imageCard != null) { +// result.add(imageCard); +// } +// } +// } catch (JSONException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// if (listener != null) { +// listener.onPostProcess(result); +// } +// return result; } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java index 7a8690fe2d..2902794ee8 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java @@ -907,9 +907,9 @@ public class ContextMenuLayer extends OsmandMapLayer { } @NonNull - private Map selectObjectsForContextMenu(RotatedTileBox tileBox, - PointF point, boolean acquireObjLatLon, - boolean unknownLocation) { + public Map selectObjectsForContextMenu(RotatedTileBox tileBox, + PointF point, boolean acquireObjLatLon, + boolean unknownLocation) { Map pressedLatLonFull = new HashMap<>(); Map pressedLatLonSmall = new HashMap<>(); Map selectedObjects = new HashMap<>(); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index ed0f2cc45d..d01ec310a9 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -66,7 +66,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon /// cache for displayed POI // Work with cache (for map copied from AmenityIndexRepositoryOdb) - private MapLayerData> data; + public MapLayerData> data; private OsmandApplication app;