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.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";
@ -422,22 +431,8 @@ public abstract class ImageCard extends AbstractCard {
@Override
protected List<ImageCard> doInBackground(Void... params) {
List<ImageCard> result = new ArrayList<>();
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);
}
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) {
@ -449,14 +444,21 @@ public abstract class ImageCard extends AbstractCard {
this.params.remove(Amenity.WIKIMEDIA_COMMONS);
WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result);
}
pms.putAll(this.params);
}
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<>();
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");
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 {
@ -472,14 +474,57 @@ public abstract class ImageCard extends AbstractCard {
}
}
}
}
} catch (Exception e) {
} catch (JSONException e) {
e.printStackTrace();
}
if (listener != null) {
listener.onPostProcess(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

View file

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

View file

@ -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<List<Amenity>> data;
public MapLayerData<List<Amenity>> data;
private OsmandApplication app;