forked from organicmaps/organicmaps
Pass metadata for POI from core to java.
This commit is contained in:
parent
569e8cbfe5
commit
51eaec33fd
10 changed files with 142 additions and 12 deletions
|
@ -821,7 +821,8 @@ extern "C"
|
|||
}
|
||||
|
||||
// POI
|
||||
void CallOnPoiActivatedListener(shared_ptr<jobject> obj, m2::PointD const & globalPoint, search::AddressInfo const & addrInfo)
|
||||
void CallOnPoiActivatedListener(shared_ptr<jobject> obj, m2::PointD const & globalPoint,
|
||||
search::AddressInfo const & addrInfo, feature::FeatureMetadata const & metadata)
|
||||
{
|
||||
JNIEnv * jniEnv = jni::GetEnv();
|
||||
|
||||
|
@ -831,10 +832,22 @@ extern "C"
|
|||
const double lon = MercatorBounds::XToLon(globalPoint.x);
|
||||
const double lat = MercatorBounds::YToLat(globalPoint.y);
|
||||
|
||||
const char * signature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DD)V";
|
||||
const vector<feature::FeatureMetadata::EMetadataType> metaTypes = metadata.GetPresentTypes();
|
||||
const jintArray j_metaTypes = jniEnv->NewIntArray(metadata.Size());
|
||||
jint * arr = jniEnv->GetIntArrayElements(j_metaTypes, 0);
|
||||
const jobjectArray j_metaValues = jniEnv->NewObjectArray(metadata.Size(), jni::GetStringClass(jniEnv), 0);
|
||||
for (int i = 0; i < metaTypes.size(); i++)
|
||||
{
|
||||
arr[i] = metaTypes[i];
|
||||
feature::FeatureMetadata::EMetadataType metaType = static_cast<feature::FeatureMetadata::EMetadataType>(metaTypes[i]);
|
||||
jniEnv->SetObjectArrayElement(j_metaValues, i, jni::ToJavaString(jniEnv, metadata.Get(metaType)));
|
||||
}
|
||||
jniEnv->ReleaseIntArrayElements(j_metaTypes, arr, 0);
|
||||
|
||||
const char * signature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DD[I[Ljava/lang/String;)V";
|
||||
const jmethodID methodId = jni::GetJavaMethodID(jniEnv, *obj.get(),
|
||||
"onPoiActivated", signature);
|
||||
jniEnv->CallVoidMethod(*obj.get(), methodId, j_name, j_type, j_address, lat, lon);
|
||||
jniEnv->CallVoidMethod(*obj.get(), methodId, j_name, j_type, j_address, lat, lon, j_metaTypes, j_metaValues);
|
||||
}
|
||||
|
||||
// Bookmark
|
||||
|
@ -879,7 +892,7 @@ extern "C"
|
|||
case UserMark::POI:
|
||||
{
|
||||
PoiMarkPoint const * poiMark = CastMark<PoiMarkPoint>(mark);
|
||||
CallOnPoiActivatedListener(obj, mark->GetOrg(), poiMark->GetInfo());
|
||||
CallOnPoiActivatedListener(obj, mark->GetOrg(), poiMark->GetInfo(), poiMark->GetMetadata());
|
||||
}
|
||||
break;
|
||||
case UserMark::SEARCH:
|
||||
|
|
|
@ -16,7 +16,7 @@ public class Framework
|
|||
{
|
||||
public void onApiPointActivated(double lat, double lon, String name, String id);
|
||||
|
||||
public void onPoiActivated(String name, String type, String address, double lat, double lon);
|
||||
public void onPoiActivated(String name, String type, String address, double lat, double lon, int[] metaTypes, String[] metaValues);
|
||||
|
||||
public void onBookmarkActivated(int category, int bookmarkIndex);
|
||||
|
||||
|
|
|
@ -90,7 +90,6 @@ import java.io.Serializable;
|
|||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import android.os.Debug;
|
||||
|
||||
public class MWMActivity extends NvEventQueueActivity
|
||||
implements LocationHelper.LocationListener, OnBalloonListener,
|
||||
|
@ -1337,9 +1336,12 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPoiActivated(final String name, final String type, final String address, final double lat, final double lon)
|
||||
public void onPoiActivated(final String name, final String type, final String address, final double lat, final double lon,
|
||||
final int[] metaTypes, final String[] metaValues)
|
||||
{
|
||||
final MapObject poi = new MapObject.Poi(name, lat, lon, type);
|
||||
for (int i = 0; i < metaTypes.length; i++)
|
||||
poi.addMetadata(metaTypes[i], metaValues[i]);
|
||||
|
||||
runOnUiThread(new Runnable()
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ public abstract class MapObject
|
|||
protected double mLat;
|
||||
protected double mLon;
|
||||
protected String mTypeName;
|
||||
protected Metadata mMetadata;
|
||||
|
||||
public MapObject(String name, double lat, double lon, String typeName)
|
||||
{
|
||||
|
@ -21,6 +22,7 @@ public abstract class MapObject
|
|||
mLat = lat;
|
||||
mLon = lon;
|
||||
mTypeName = typeName;
|
||||
mMetadata = new Metadata();
|
||||
}
|
||||
|
||||
private static boolean isEmpty(String s)
|
||||
|
@ -108,6 +110,16 @@ public abstract class MapObject
|
|||
|
||||
public String getPoiTypeName() { return mTypeName; }
|
||||
|
||||
public void addMetadata(int type, String value)
|
||||
{
|
||||
mMetadata.addMetadata(type, value);
|
||||
}
|
||||
|
||||
public String getMetadata(Metadata.MetadataType type)
|
||||
{
|
||||
return mMetadata.getMetadata(type);
|
||||
}
|
||||
|
||||
public abstract MapObjectType getType();
|
||||
|
||||
public static enum MapObjectType implements Serializable
|
||||
|
@ -177,8 +189,6 @@ public abstract class MapObject
|
|||
|
||||
public static class MyPosition extends MapObject
|
||||
{
|
||||
|
||||
|
||||
public MyPosition(String name, double lat, double lon)
|
||||
{
|
||||
super(name, lat, lon, "");
|
||||
|
|
82
android/src/com/mapswithme/maps/bookmarks/data/Metadata.java
Normal file
82
android/src/com/mapswithme/maps/bookmarks/data/Metadata.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Metadata
|
||||
{
|
||||
// values MUST correspond to definitions from feature_meta.hpp
|
||||
public enum MetadataType
|
||||
{
|
||||
FMD_CUISINE(1),
|
||||
FMD_OPEN_HOURS(2),
|
||||
FMD_PHONE_NUMBER(3),
|
||||
FMD_FAX_NUMBER(4),
|
||||
FMD_STARS(5),
|
||||
FMD_OPERATOR(6),
|
||||
FMD_URL(7),
|
||||
FMD_INTERNET(8),
|
||||
FMD_ELE(9),
|
||||
FMD_TURN_LANES(10),
|
||||
FMD_TURN_LANES_FORWARD(11),
|
||||
FMD_TURN_LANES_BACKWARD(12),
|
||||
FMD_EMAIL(13);
|
||||
|
||||
private int mMetaType;
|
||||
|
||||
MetadataType(int metadataType)
|
||||
{
|
||||
mMetaType = metadataType;
|
||||
}
|
||||
|
||||
public static MetadataType fromInt(int metaType)
|
||||
{
|
||||
for (MetadataType type : values())
|
||||
if (type.mMetaType == metaType)
|
||||
return type;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<MetadataType, String> mMetadataMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Adds metadata with type code and value. Returns false if metaType is wrong or unknown
|
||||
*
|
||||
* @param metaType
|
||||
* @param metaValue
|
||||
* @return true, if metadata was added, false otherwise
|
||||
*/
|
||||
public boolean addMetadata(int metaType, String metaValue)
|
||||
{
|
||||
final MetadataType type = MetadataType.fromInt(metaType);
|
||||
if (type == null)
|
||||
return false;
|
||||
|
||||
mMetadataMap.put(type, metaValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds metadata with type and value.
|
||||
*
|
||||
* @param type
|
||||
* @param value
|
||||
* @return true, if metadata was added, false otherwise
|
||||
*/
|
||||
public boolean addMetadata(MetadataType type, String value)
|
||||
{
|
||||
mMetadataMap.put(type, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @return null if metadata doesn't exist
|
||||
*/
|
||||
public String getMetadata(MetadataType type)
|
||||
{
|
||||
return mMetadataMap.get(type);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include "../std/string.hpp"
|
||||
#include "../std/limits.hpp"
|
||||
#include "../std/algorithm.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
|
||||
namespace feature
|
||||
{
|
||||
|
@ -51,6 +52,15 @@ namespace feature
|
|||
return (it == m_metadata.end()) ? string() : it->second;
|
||||
}
|
||||
|
||||
vector<EMetadataType> GetPresentTypes() const
|
||||
{
|
||||
vector<EMetadataType> types;
|
||||
for (auto item: m_metadata)
|
||||
types.push_back(static_cast<EMetadataType>(item.first));
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
void Drop(EMetadataType type)
|
||||
{
|
||||
m_metadata.erase(type);
|
||||
|
|
|
@ -193,4 +193,5 @@ bool Index::FeaturesLoaderGuard::IsWorld() const
|
|||
void Index::FeaturesLoaderGuard::GetFeature(uint32_t offset, FeatureType & ft)
|
||||
{
|
||||
m_vector.Get(offset, ft);
|
||||
ft.SetID(FeatureID(m_lock.GetID(), offset));
|
||||
}
|
||||
|
|
|
@ -1677,7 +1677,7 @@ OEPointerT GetClosestToPivot(list<OEPointerT> const & l, m2::PointD const & pxPo
|
|||
#endif // USE_DRAPE
|
||||
|
||||
bool Framework::GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot,
|
||||
search::AddressInfo & info) const
|
||||
search::AddressInfo & info, feature::FeatureMetadata & metadata) const
|
||||
{
|
||||
#ifndef USE_DRAPE
|
||||
graphics::OverlayElement::UserInfo ui;
|
||||
|
@ -1714,6 +1714,9 @@ bool Framework::GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot,
|
|||
FeatureType ft;
|
||||
guard.GetFeature(ui.m_offset, ft);
|
||||
|
||||
ft.ParseMetadata();
|
||||
metadata = ft.GetMetadata();
|
||||
|
||||
// @TODO experiment with other pivots
|
||||
ASSERT_NOT_EQUAL(ft.GetFeatureType(), feature::GEOM_LINE, ());
|
||||
m2::PointD const center = feature::GetCenter(ft);
|
||||
|
@ -1817,7 +1820,8 @@ UserMark const * Framework::GetUserMark(m2::PointD const & pxPoint, bool isLongP
|
|||
bool needMark = false;
|
||||
m2::PointD pxPivot;
|
||||
search::AddressInfo info;
|
||||
if (GetVisiblePOI(pxPoint, pxPivot, info))
|
||||
feature::FeatureMetadata metadata;
|
||||
if (GetVisiblePOI(pxPoint, pxPivot, info, metadata))
|
||||
needMark = true;
|
||||
else if (isLongPress)
|
||||
{
|
||||
|
@ -1831,6 +1835,7 @@ UserMark const * Framework::GetUserMark(m2::PointD const & pxPoint, bool isLongP
|
|||
PoiMarkPoint * poiMark = UserMarkContainer::UserMarkForPoi();
|
||||
poiMark->SetPtOrg(m_navigator.PtoG(pxPivot));
|
||||
poiMark->SetInfo(info);
|
||||
poiMark->SetMetadata(metadata);
|
||||
mark = poiMark;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -357,7 +357,7 @@ private:
|
|||
void GetLocality(m2::PointD const & pt, search::AddressInfo & info) const;
|
||||
|
||||
public:
|
||||
bool GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot, search::AddressInfo & info) const;
|
||||
bool GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot, search::AddressInfo & info, feature::FeatureMetadata & metadata) const;
|
||||
|
||||
#ifndef USE_DRAPE
|
||||
virtual void BeginPaint(shared_ptr<PaintEvent> const & e);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "../geometry/point2d.hpp"
|
||||
|
||||
#include "../indexer/feature.hpp"
|
||||
|
||||
#include "../search/result.hpp"
|
||||
|
||||
#include "../std/string.hpp"
|
||||
|
@ -123,6 +125,10 @@ public:
|
|||
|
||||
search::AddressInfo const & GetInfo() const { return m_info; }
|
||||
void SetInfo(search::AddressInfo const & info) { m_info = info; }
|
||||
|
||||
feature::FeatureMetadata const & GetMetadata() const { return m_metadata; }
|
||||
void SetMetadata(feature::FeatureMetadata const & metadata) { m_metadata = metadata; }
|
||||
|
||||
virtual UserMarkCopy * Copy() const
|
||||
{
|
||||
return new UserMarkCopy(new SearchMarkPoint(m_info, m_ptOrg, m_container));
|
||||
|
@ -130,6 +136,7 @@ public:
|
|||
|
||||
protected:
|
||||
search::AddressInfo m_info;
|
||||
feature::FeatureMetadata m_metadata;
|
||||
};
|
||||
|
||||
class PoiMarkPoint : public SearchMarkPoint
|
||||
|
|
Loading…
Add table
Reference in a new issue