forked from organicmaps/organicmaps
[tracks] Code cleanup.
This commit is contained in:
parent
47d6a7ce4a
commit
ed59cfa77b
8 changed files with 35 additions and 82 deletions
|
@ -19,12 +19,6 @@ namespace
|
|||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_g2p(JNIEnv * env, jobject thiz, jdouble x, jdouble y)
|
||||
{
|
||||
return jni::GetNewParcelablePointD(env, frm()->GtoP(m2::PointD(x, y)));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_getName(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
|
@ -70,13 +64,6 @@ extern "C"
|
|||
return g_framework->ChangeBookmarkCategory(BookmarkAndCategory(oldCat, bmk), newCat);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_p2g(
|
||||
JNIEnv * env, jobject thiz, jdouble px, jdouble py)
|
||||
{
|
||||
return jni::GetNewParcelablePointD(env, frm()->PtoG(m2::PointD(px, py)));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_getXY(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
|
|
|
@ -2,21 +2,20 @@ package com.mapswithme.maps.bookmarks.data;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mapswithme.maps.MapObjectFragment.MapObjectType;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MapObjectFragment.MapObjectType;
|
||||
import com.mapswithme.maps.R;
|
||||
|
||||
public class Bookmark extends MapObject
|
||||
{
|
||||
private Icon mIcon;
|
||||
private Context mContext;
|
||||
private ParcelablePointD mPosition;
|
||||
private int mCategoryId = -1;
|
||||
private int mCategoryId;
|
||||
private int mBookmark;
|
||||
private double mMerX = Double.NaN;
|
||||
private double mMerY = Double.NaN;
|
||||
private double mLon = Double.NaN;
|
||||
private double mLat = Double.NaN;
|
||||
private double mMerX;
|
||||
private double mMerY;
|
||||
private double mLon;
|
||||
private double mLat;
|
||||
|
||||
|
||||
Bookmark(Context context, int c, int b)
|
||||
|
@ -28,25 +27,6 @@ public class Bookmark extends MapObject
|
|||
getXY();
|
||||
}
|
||||
|
||||
private void getXY(ParcelablePointD position)
|
||||
{
|
||||
ParcelablePointD ll = p2g(position.x, position.y);
|
||||
mMerX = ll.x;
|
||||
mMerY = ll.y;
|
||||
}
|
||||
|
||||
public static ParcelablePointD GtoP(ParcelablePointD p)
|
||||
{
|
||||
return g2p(p.x, p.y);
|
||||
}
|
||||
|
||||
public static ParcelablePointD PtoG(ParcelablePointD p)
|
||||
{
|
||||
return p2g(p.x, p.y);
|
||||
}
|
||||
|
||||
private static native ParcelablePointD g2p(double x, double y);
|
||||
private static native ParcelablePointD p2g(double px, double py);
|
||||
private native ParcelablePointD getXY(int c, long b);
|
||||
private native String getName(int c, long b);
|
||||
private native String getIcon(int c, long b);
|
||||
|
@ -65,7 +45,7 @@ public class Bookmark extends MapObject
|
|||
return getScale(mCategoryId, mBookmark);
|
||||
}
|
||||
|
||||
void getXY()
|
||||
private void getXY()
|
||||
{
|
||||
ParcelablePointD ll = getXY(mCategoryId, mBookmark);
|
||||
mMerX = ll.x;
|
||||
|
@ -75,8 +55,6 @@ public class Bookmark extends MapObject
|
|||
final double lat = (180.0/Math.PI)*(2.0 * Math.atan(Math.exp(yRad)) - Math.PI/2.0);
|
||||
mLat = lat;
|
||||
mLon = ll.x;
|
||||
|
||||
mPosition = g2p(mMerX, mMerY);
|
||||
}
|
||||
|
||||
public DistanceAndAzimut getDistanceAndAzimut(double cLat, double cLon, double north)
|
||||
|
@ -84,11 +62,6 @@ public class Bookmark extends MapObject
|
|||
return Framework.getDistanceAndAzimut(mMerX, mMerY, cLat, cLon, north);
|
||||
}
|
||||
|
||||
public ParcelablePointD getPosition()
|
||||
{
|
||||
return g2p(mMerX, mMerY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLat() { return mLat; }
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ void BookmarkCategory::AddTrack(Track & track)
|
|||
m_tracks.push_back(track.CreatePersistent());
|
||||
}
|
||||
|
||||
Track * BookmarkCategory::GetTrack(size_t index) const
|
||||
Track const * BookmarkCategory::GetTrack(size_t index) const
|
||||
{
|
||||
return (index < m_tracks.size() ? m_tracks[index] : 0);
|
||||
}
|
||||
|
@ -75,19 +75,34 @@ void BookmarkCategory::ClearTracks()
|
|||
m_tracks.clear();
|
||||
}
|
||||
|
||||
void BookmarkCategory::DeleteBookmark(size_t index)
|
||||
namespace
|
||||
{
|
||||
if (index < m_bookmarks.size())
|
||||
|
||||
template <class T> void DeleteItem(vector<T> & v, size_t i)
|
||||
{
|
||||
if (i < v.size())
|
||||
{
|
||||
delete m_bookmarks[index];
|
||||
m_bookmarks.erase(m_bookmarks.begin() + index);
|
||||
delete v[i];
|
||||
v.erase(v.begin() + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LWARNING, ("Trying to delete non-existing bookmark in category", GetName(), "at index", index));
|
||||
LOG(LWARNING, ("Trying to delete non-existing item at index", i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BookmarkCategory::DeleteBookmark(size_t index)
|
||||
{
|
||||
DeleteItem(m_bookmarks, index);
|
||||
}
|
||||
|
||||
void BookmarkCategory::DeleteTrack(size_t index)
|
||||
{
|
||||
DeleteItem(m_tracks, index);
|
||||
}
|
||||
|
||||
Bookmark const * BookmarkCategory::GetBookmark(size_t index) const
|
||||
{
|
||||
return (index < m_bookmarks.size() ? m_bookmarks[index] : 0);
|
||||
|
@ -98,16 +113,6 @@ Bookmark * BookmarkCategory::GetBookmark(size_t index)
|
|||
return (index < m_bookmarks.size() ? m_bookmarks[index] : 0);
|
||||
}
|
||||
|
||||
int BookmarkCategory::GetBookmark(m2::PointD const org, double const squareDistance) const
|
||||
{
|
||||
for (size_t i = 0; i < m_bookmarks.size(); ++i)
|
||||
{
|
||||
if (squareDistance >= org.SquareLength(m_bookmarks[i]->GetOrg()))
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
string PointToString(m2::PointD const & org)
|
||||
|
|
|
@ -86,8 +86,9 @@ public:
|
|||
//@{
|
||||
/// @note Move semantics is used here.
|
||||
void AddTrack(Track & track);
|
||||
Track * GetTrack(size_t index) const;
|
||||
Track const * GetTrack(size_t index) const;
|
||||
inline size_t GetTracksCount() const { return m_tracks.size(); }
|
||||
void DeleteTrack(size_t index);
|
||||
//@}
|
||||
|
||||
void SetVisible(bool isVisible) { m_visible = isVisible; }
|
||||
|
@ -101,9 +102,6 @@ public:
|
|||
|
||||
Bookmark const * GetBookmark(size_t index) const;
|
||||
Bookmark * GetBookmark(size_t index);
|
||||
/// @param[in] distance in metres between orgs
|
||||
/// @returns -1 or index of found bookmark
|
||||
int GetBookmark(m2::PointD const org, double const squareDistance) const;
|
||||
|
||||
void DeleteBookmark(size_t index);
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ void BookmarkManager::DrawCategory(BookmarkCategory const * cat, shared_ptr<Pain
|
|||
// Draw tracks.
|
||||
for (size_t i = 0; i < cat->GetTracksCount(); ++i)
|
||||
{
|
||||
Track * track = cat->GetTrack(i);
|
||||
Track const * track = cat->GetTrack(i);
|
||||
if (track->HasDisplayList())
|
||||
track->Draw(pScreen, matrix.GetFinalG2P());
|
||||
}
|
||||
|
@ -318,11 +318,6 @@ Bookmark * BookmarkManager::AdditionalPoiLayerGetBookmark(size_t index)
|
|||
return m_additionalPoiLayer->GetBookmark(index);
|
||||
}
|
||||
|
||||
void BookmarkManager::AdditionalPoiLayerDeleteBookmark(int index)
|
||||
{
|
||||
m_additionalPoiLayer->DeleteBookmark(index);
|
||||
}
|
||||
|
||||
void BookmarkManager::AdditionalPoiLayerClear()
|
||||
{
|
||||
m_additionalPoiLayer->ClearBookmarks();
|
||||
|
|
|
@ -66,7 +66,6 @@ public:
|
|||
void AdditionalPoiLayerAddPoi(Bookmark const & bm);
|
||||
Bookmark const * AdditionalPoiLayerGetBookmark(size_t index) const;
|
||||
Bookmark * AdditionalPoiLayerGetBookmark(size_t index);
|
||||
void AdditionalPoiLayerDeleteBookmark(int index);
|
||||
void AdditionalPoiLayerClear();
|
||||
bool IsAdditionalLayerPoi(const BookmarkAndCategory & bm) const;
|
||||
bool AdditionalLayerIsVisible() const { return m_additionalPoiLayer->IsVisible(); }
|
||||
|
|
|
@ -412,7 +412,7 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint, double vi
|
|||
|
||||
if (m_bmManager.AdditionalLayerIsVisible())
|
||||
{
|
||||
for (int i = 0; i < m_bmManager.AdditionalLayerNumberOfPoi(); ++i)
|
||||
for (size_t i = 0; i < m_bmManager.AdditionalLayerNumberOfPoi(); ++i)
|
||||
{
|
||||
m2::PointD const pt = m_bmManager.AdditionalPoiLayerGetBookmark(i)->GetOrg();
|
||||
if (rect.IsPointInside(pt))
|
||||
|
@ -579,11 +579,6 @@ Bookmark * Framework::AdditionalPoiLayerGetBookmark(size_t index)
|
|||
return m_bmManager.AdditionalPoiLayerGetBookmark(index);
|
||||
}
|
||||
|
||||
void Framework::AdditionalPoiLayerDeleteBookmark(int index)
|
||||
{
|
||||
m_bmManager.AdditionalPoiLayerDeleteBookmark(index);
|
||||
}
|
||||
|
||||
void Framework::AdditionalPoiLayerClear()
|
||||
{
|
||||
m_bmManager.AdditionalPoiLayerClear();
|
||||
|
|
|
@ -211,17 +211,18 @@ public:
|
|||
|
||||
bool AddBookmarksFile(string const & filePath);
|
||||
|
||||
//Additional Layer methods
|
||||
/// @name Additional Layer methods.
|
||||
//@{
|
||||
void AdditionalPoiLayerSetInvisible();
|
||||
void AdditionalPoiLayerSetVisible();
|
||||
void AdditionalPoiLayerAddPoi(Bookmark const & bm);
|
||||
Bookmark const * AdditionalPoiLayerGetBookmark(size_t index) const;
|
||||
Bookmark * AdditionalPoiLayerGetBookmark(size_t index);
|
||||
void AdditionalPoiLayerDeleteBookmark(int index);
|
||||
void AdditionalPoiLayerClear();
|
||||
bool IsAdditionalLayerPoi(const BookmarkAndCategory & bm) const;
|
||||
bool AdditionalLayerIsVisible();
|
||||
size_t AdditionalLayerNumberOfPoi();
|
||||
//@}
|
||||
|
||||
inline m2::PointD PtoG(m2::PointD const & p) const { return m_navigator.PtoG(p); }
|
||||
inline m2::PointD GtoP(m2::PointD const & p) const { return m_navigator.GtoP(p); }
|
||||
|
|
Loading…
Add table
Reference in a new issue