From 4304679d8c6d83acaa6bb870e9f782df55e7d26d Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 17 Apr 2012 18:39:57 +0300 Subject: [PATCH] [bookmarks] Add bookmark re-position routine. --- iphone/Maps/Classes/BalloonView.h | 7 ++++- iphone/Maps/Classes/BalloonView.mm | 27 ++++++++++++++-- iphone/Maps/Classes/MapViewController.mm | 39 ++++++++++++++++++------ map/address_finder.cpp | 4 +-- map/framework.cpp | 16 +++------- map/framework.hpp | 17 ++++++----- qt/draw_widget.cpp | 2 +- 7 files changed, 76 insertions(+), 36 deletions(-) diff --git a/iphone/Maps/Classes/BalloonView.h b/iphone/Maps/Classes/BalloonView.h index 2407cb77a9..77bc95a067 100644 --- a/iphone/Maps/Classes/BalloonView.h +++ b/iphone/Maps/Classes/BalloonView.h @@ -1,5 +1,8 @@ #import +#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 diff --git a/iphone/Maps/Classes/BalloonView.mm b/iphone/Maps/Classes/BalloonView.mm index fa1dcdfa42..19a835ffca 100644 --- a/iphone/Maps/Classes/BalloonView.mm +++ b/iphone/Maps/Classes/BalloonView.mm @@ -1,9 +1,14 @@ #import "BalloonView.h" #import +//#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]; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 0fa75b3c6f..5ffc30fcbc 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -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 diff --git a/map/address_finder.cpp b/map/address_finder.cpp index e4581dcc81..94f409cf52 100644 --- a/map/address_finder.cpp +++ b/map/address_finder.cpp @@ -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()) { diff --git a/map/framework.cpp b/map/framework.cpp index 25b5e22544..80386bcb8f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -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 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); diff --git a/map/framework.hpp b/map/framework.hpp index 5490ec0884..b97c311b5b 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -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 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 & types) const; + /// Get classificator types for nearest features. + /// @param[in] pixPt Current touch point in device pixel coordinates. + void GetFeatureTypes(m2::PointD pixPt, vector & 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 const & e); /// Function for calling from platform dependent-paint function. diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index fc8665d400..7285aa9ac0 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -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);