amenity id

This commit is contained in:
simon 2020-10-07 12:10:59 +03:00
parent 1801e0add9
commit 02dbacf4fe
3 changed files with 95 additions and 50 deletions

View file

@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.builders.cards;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.view.View; import android.view.View;
@ -16,9 +17,13 @@ import androidx.appcompat.widget.AppCompatButton;
import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; 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.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapillary.MapillaryContributeCard; import net.osmand.plus.mapillary.MapillaryContributeCard;
import net.osmand.plus.mapillary.MapillaryImageCard; 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.plus.wikimedia.WikiImageHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -43,6 +50,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE;
public abstract class ImageCard extends AbstractCard { public abstract class ImageCard extends AbstractCard {
public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; 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, public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon,
@Nullable Map<String, String> params, GetImageCardsListener listener) { @Nullable Map<String, String> params, GetImageCardsListener listener) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication(); this.app = mapActivity.getMyApplication();
this.latLon = latLon; this.latLon = latLon;
@ -422,64 +431,100 @@ public abstract class ImageCard extends AbstractCard {
@Override @Override
protected List<ImageCard> doInBackground(Void... params) { protected List<ImageCard> doInBackground(Void... params) {
List<ImageCard> result = new ArrayList<>(); List<ImageCard> 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<String, String> pms = new LinkedHashMap<>(); final Map<String, String> pms = new LinkedHashMap<>();
pms.put("lat", "" + (float) latLon.getLatitude()); pms.put("osmid", "" + am.getId());
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);
}
String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms,
"Requesting location images...", false, false); "Requesting location images...", false, false);
if (!Algorithms.isEmpty(response)) { if (!Algorithms.isEmpty(response)) {
JSONObject obj = new JSONObject(response); JSONObject obj = null;
JSONArray images = obj.getJSONArray("features"); try {
if (images.length() > 0) { obj = new JSONObject(response);
for (int i = 0; i < images.length(); i++) { JSONArray images = null;
try { images = obj.getJSONArray("features");
JSONObject imageObject = (JSONObject) images.get(i); if (images.length() > 0) {
if (imageObject != JSONObject.NULL) { for (int i = 0; i < images.length(); i++) {
ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); try {
if (imageCard != null) { JSONObject imageObject = (JSONObject) images.get(i);
result.add(imageCard); 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; return result;
// try {
// final Map<String, String> 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 @Override

View file

@ -907,9 +907,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
@NonNull @NonNull
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox, public Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox,
PointF point, boolean acquireObjLatLon, PointF point, boolean acquireObjLatLon,
boolean unknownLocation) { boolean unknownLocation) {
Map<LatLon, BackgroundType> pressedLatLonFull = new HashMap<>(); Map<LatLon, BackgroundType> pressedLatLonFull = new HashMap<>();
Map<LatLon, BackgroundType> pressedLatLonSmall = new HashMap<>(); Map<LatLon, BackgroundType> pressedLatLonSmall = new HashMap<>();
Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>(); Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();

View file

@ -66,7 +66,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
/// cache for displayed POI /// cache for displayed POI
// Work with cache (for map copied from AmenityIndexRepositoryOdb) // Work with cache (for map copied from AmenityIndexRepositoryOdb)
private MapLayerData<List<Amenity>> data; public MapLayerData<List<Amenity>> data;
private OsmandApplication app; private OsmandApplication app;