[bookmarks] Add bookmark re-position routine.

This commit is contained in:
vng 2012-04-17 18:39:57 +03:00 committed by Alex Zolotarev
parent c42f96c666
commit 4304679d8c
7 changed files with 76 additions and 36 deletions

View file

@ -1,5 +1,8 @@
#import <UIKit/UIKit.h>
#include "../../geometry/point2d.hpp"
@interface BalloonView : NSObject
{
UIImageView * m_pinView;
@ -8,10 +11,12 @@
SEL m_selector;
}
@property(nonatomic,assign,readonly) BOOL isDisplayed;
@property(nonatomic, assign, readonly) BOOL isDisplayed;
@property(nonatomic, assign) m2::PointD glbPos;
- (id) initWithTarget:(id)target andSelector:(SEL)selector;
- (void) showInView:(UIView *)view atPoint:(CGPoint)pt;
- (void) updatePosition:(UIView *)view atPoint:(CGPoint)pt;
- (void) hide;
@end

View file

@ -1,9 +1,14 @@
#import "BalloonView.h"
#import <QuartzCore/CALayer.h>
//#include "../../base/logging.hpp"
@implementation BalloonView
@synthesize isDisplayed;
@synthesize glbPos;
- (id) initWithTarget:(id)target andSelector:(SEL)selector;
{
@ -31,7 +36,8 @@
m_buttonsView.frame = CGRectMake(pt.x - w/2, pt.y, w, 0);
m_buttonsView.userInteractionEnabled = YES;
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:m_target action:m_selector];
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc]
initWithTarget:m_target action:m_selector];
recognizer.numberOfTapsRequired = 1;
recognizer.numberOfTouchesRequired = 1;
recognizer.delaysTouchesBegan = YES;
@ -39,6 +45,7 @@
[recognizer release];
[view addSubview:m_buttonsView];
// Animate buttons view to appear up from the pin
[UIView transitionWithView:m_buttonsView duration:0.1 options:UIViewAnimationOptionCurveEaseIn
animations:^{
@ -58,10 +65,10 @@
m_pinView = [[UIImageView alloc ]initWithImage:[UIImage imageNamed:@"marker"]];
CGFloat const w = m_pinView.bounds.size.width;
CGFloat const h = m_pinView.bounds.size.height;
// Set initial frame at the top outside of the view
m_pinView.frame = CGRectMake(pt.x - w/2, 0 - h, w, h);
//pinView.userInteractionEnabled = YES;
[view addSubview:m_pinView];
// Animate pin to the touched point
[UIView transitionWithView:m_pinView duration:0.1 options:UIViewAnimationOptionCurveEaseIn
animations:^{ m_pinView.frame = CGRectMake(pt.x - w/2, pt.y - h, w, h); }
@ -70,6 +77,20 @@
}];
}
- (void) updatePosition:(UIView *)view atPoint:(CGPoint)pt
{
if (isDisplayed)
{
CGFloat const w1 = m_pinView.bounds.size.width;
CGFloat const h1 = m_pinView.bounds.size.height;
m_pinView.frame = CGRectMake(pt.x - w1/2, pt.y - h1, w1, h1);
CGFloat const w2 = m_buttonsView.bounds.size.width;
CGFloat const h2 = m_buttonsView.bounds.size.height;
m_buttonsView.frame = CGRectMake(pt.x - w2/2, pt.y - h1 - h2, w2, h2);
}
}
- (void) hide
{
[m_buttonsView removeFromSuperview];

View file

@ -107,8 +107,13 @@ Framework * m_framework = NULL;
- (void)onBookmarkClicked
{
m_framework->AddBookmark(m_Pt1);
Framework::AddressInfo info;
m_framework->GetAddressInfo(m_bookmark.glbPos, info);
m_framework->AddBookmark(m_bookmark.glbPos, info.m_name);
[m_bookmark hide];
m_framework->Invalidate();
}
@ -116,8 +121,13 @@ Framework * m_framework = NULL;
{
if (m_bookmark.isDisplayed)
[m_bookmark hide];
else
[m_bookmark showInView:self.view atPoint:[point CGPointValue]];
//else
//{
CGPoint const pt = [point CGPointValue];
m_bookmark.glbPos = m_framework->PtoG(m2::PointD(pt.x, pt.y));
[m_bookmark showInView:self.view atPoint:pt];
//}
}
- (void) dealloc
@ -192,6 +202,12 @@ NSInteger compareAddress(id l, id r, void * context)
}
}
- (void)updateDataAfterScreenChanged
{
m2::PointD const p = m_framework->GtoP(m_bookmark.glbPos);
[m_bookmark updatePosition:self.view atPoint:CGPointMake(p.x, p.y)];
}
- (void)stopCurrentAction
{
switch (m_CurrentAction)
@ -205,7 +221,10 @@ NSInteger compareAddress(id l, id r, void * context)
m_framework->StopScale(ScaleEvent(m_Pt1.x, m_Pt1.y, m_Pt2.x, m_Pt2.y));
break;
}
m_CurrentAction = NOTHING;
[self updateDataAfterScreenChanged];
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
@ -228,6 +247,8 @@ NSInteger compareAddress(id l, id r, void * context)
}
m_isSticking = true;
[self updateDataAfterScreenChanged];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
@ -244,12 +265,10 @@ NSInteger compareAddress(id l, id r, void * context)
if ((TempPt1.Length(m_Pt1) > m_StickyThreshold) || (TempPt2.Length(m_Pt2) > m_StickyThreshold))
{
m_isSticking = false;
// Hide bookmark icon, if finger has moved
[m_bookmark hide];
}
else
{
/// Still stickying. Restoring old points and return.
// Still stickying. Restoring old points and return.
m_Pt1 = TempPt1;
m_Pt2 = TempPt2;
return;
@ -274,6 +293,8 @@ NSInteger compareAddress(id l, id r, void * context)
case NOTHING:
return;
}
[self updateDataAfterScreenChanged];
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
@ -287,21 +308,19 @@ NSInteger compareAddress(id l, id r, void * context)
if (tapCount == 2 && touchesCount == 1 && m_isSticking)
{
// Hide bookmarks icon if it was displayed
[m_bookmark hide];
m_framework->ScaleToPoint(ScaleToPointEvent(m_Pt1.x, m_Pt1.y, 2.0));
}
if (touchesCount == 2 && tapCount == 1 && m_isSticking)
{
// Hide bookmarks icon if it was displayed
[m_bookmark hide];
m_framework->Scale(0.5);
}
// Launch single tap timer
if (touchesCount == 1 && tapCount == 1 && m_isSticking)
[self performSelector:@selector(onSingleTap:) withObject:[NSValue valueWithCGPoint:[theTouch locationInView:self.view]] afterDelay:0.3];
[self updateDataAfterScreenChanged];
}
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event

View file

@ -331,10 +331,8 @@ namespace
};
}
void Framework::GetAddressInfo(m2::PointD pt, AddressInfo & info) const
void Framework::GetAddressInfo(m2::PointD const & pt, AddressInfo & info) const
{
pt = m_navigator.Screen().PtoG(m_navigator.ShiftPoint(pt));
info.m_country = GetCountryName(pt);
if (info.m_country.empty())
{

View file

@ -190,13 +190,6 @@ void Framework::RemoveLocalMaps()
m_model.RemoveAllCountries();
}
void Framework::AddBookmark(m2::PointD const & pixelCoords)
{
// @TODO automatically get bookmark name from the data
string const name = "Best offline maps!";
m_bookmarks.push_back(Bookmark(m_navigator.Screen().PtoG(m_navigator.ShiftPoint(pixelCoords)), name));
}
void Framework::AddBookmark(m2::PointD const & pt, string const & name)
{
m_bookmarks.push_back(Bookmark(pt, name));
@ -586,11 +579,12 @@ void Framework::DrawAdditionalInfo(shared_ptr<PaintEvent> const & e)
m_informationDisplay.enableEmptyModelMessage(m_renderPolicy->IsEmptyModel());
m_informationDisplay.setDebugInfo(0/*m_renderQueue.renderState().m_duration*/,
GetDrawScale());
m_informationDisplay.setCenter(m2::PointD(MercatorBounds::XToLon(center.x), MercatorBounds::YToLat(center.y)));
m_informationDisplay.setDebugInfo(0/*m_renderQueue.renderState().m_duration*/, GetDrawScale());
m_informationDisplay.enableRuler(true/*!IsEmptyModel()*/);
m_informationDisplay.setCenter(m2::PointD(MercatorBounds::XToLon(center.x),
MercatorBounds::YToLat(center.y)));
m_informationDisplay.enableRuler(true);
m_informationDisplay.doDraw(pDrawer);

View file

@ -124,13 +124,15 @@ public:
void AddLocalMaps();
void RemoveLocalMaps();
void AddBookmark(m2::PointD const & pixelCoords);
void AddBookmark(m2::PointD const & pt, string const & name);
inline size_t BookmarksCount() const { return m_bookmarks.size(); }
void GetBookmark(size_t index, Bookmark & bm) const;
void RemoveBookmark(size_t index);
void ClearBookmarks();
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); }
void LoadFromKML(ReaderPtr<Reader> const & reader);
void SaveToKML(std::ostream & s);
@ -203,17 +205,18 @@ public:
Invalidate(true);
}
/// @name
/// @param[in] pt Current touch point in device pixel coordinates.
//@{
void GetFeatureTypes(m2::PointD pt, vector<string> & types) const;
/// Get classificator types for nearest features.
/// @param[in] pixPt Current touch point in device pixel coordinates.
void GetFeatureTypes(m2::PointD pixPt, vector<string> & types) const;
struct AddressInfo
{
string m_country, m_city, m_street, m_house, m_name;
};
void GetAddressInfo(m2::PointD pt, AddressInfo & info) const;
//@}
/// Get address information for point on map.
/// @param[in] pt Point in mercator coordinates.
void GetAddressInfo(m2::PointD const & pt, AddressInfo & info) const;
virtual void BeginPaint(shared_ptr<PaintEvent> const & e);
/// Function for calling from platform dependent-paint function.

View file

@ -341,7 +341,7 @@ namespace qt
(void)menu.addSeparator();
Framework::AddressInfo info;
m_framework->GetAddressInfo(m2::PointD(pt.x(), pt.y()), info);
m_framework->GetAddressInfo(m_framework->PtoG(m2::PointD(pt.x(), pt.y())), info);
add_string(menu, info.m_country);
add_string(menu, info.m_city);