forked from organicmaps/organicmaps
[ios] Added framework * to Search View Controller for direct access to Search functions
This commit is contained in:
parent
a41edbd6b9
commit
6631e22123
3 changed files with 25 additions and 30 deletions
|
@ -94,10 +94,7 @@ storage::Storage m_storage;
|
|||
|
||||
- (IBAction)OnSearchClicked:(id)sender
|
||||
{
|
||||
SearchVC * searchVC = [[[SearchVC alloc] initWithNibName:@"Search" bundle:nil] autorelease];
|
||||
[searchVC setSearchFunc:bind(&framework_t::Search, m_framework, _1, _2)
|
||||
andShowRectFunc:bind(&framework_t::ShowRect, m_framework, _1)
|
||||
andGetViewportCenterFunc:bind(&framework_t::GetViewportCenter, m_framework)];
|
||||
SearchVC * searchVC = [[[SearchVC alloc] initWithFramework:m_framework] autorelease];
|
||||
[self presentModalViewController:searchVC animated:YES];
|
||||
}
|
||||
|
||||
|
@ -281,7 +278,7 @@ NSInteger compareAddress(id l, id r, void * context)
|
|||
EAGLView * v = (EAGLView*)self.view;
|
||||
boost::shared_ptr<WindowHandle> wh = [v windowHandle];
|
||||
boost::shared_ptr<iphone::RenderBuffer> rb = [v renderBuffer];
|
||||
shared_ptr<DrawerYG> drawer = [(EAGLView*)self.view drawer];
|
||||
shared_ptr<DrawerYG> drawer = [v drawer];
|
||||
shared_ptr<PaintEvent> pe(new PaintEvent(drawer.get()));
|
||||
|
||||
if (wh->needRedraw())
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
#include "../../map/framework.hpp"
|
||||
#include "../../map/feature_vec_model.hpp"
|
||||
|
||||
#include "../../std/vector.hpp"
|
||||
#include "../../std/function.hpp"
|
||||
|
@ -9,13 +10,12 @@
|
|||
|
||||
namespace search { class Result; }
|
||||
|
||||
typedef function<void (string const &, SearchCallbackT)> SearchF;
|
||||
typedef function<void (m2::RectD)> ShowRectF;
|
||||
typedef function<m2::PointD (void)> GetViewportCenterF;
|
||||
typedef Framework<model::FeaturesFetcher> framework_t;
|
||||
|
||||
@interface SearchVC : UIViewController
|
||||
<UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate>
|
||||
{
|
||||
framework_t * m_framework;
|
||||
vector<search::Result> m_results;
|
||||
CLLocationManager * m_locationManager;
|
||||
UISearchBar * m_searchBar;
|
||||
|
@ -25,7 +25,6 @@ typedef function<m2::PointD (void)> GetViewportCenterF;
|
|||
@property (nonatomic, retain) IBOutlet UISearchBar * m_searchBar;
|
||||
@property (nonatomic, retain) IBOutlet UITableView * m_table;
|
||||
|
||||
- (void)setSearchFunc:(SearchF)s andShowRectFunc:(ShowRectF)r
|
||||
andGetViewportCenterFunc:(GetViewportCenterF)c;
|
||||
- (id)initWithFramework:(framework_t *)framework;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
#include "../../search/result.hpp"
|
||||
|
||||
SearchVC * g_searchVC = nil;
|
||||
SearchF g_searchF;
|
||||
ShowRectF g_showRectF;
|
||||
GetViewportCenterF g_getViewportCenterF;
|
||||
volatile int g_queryId = 0;
|
||||
|
||||
@interface Wrapper : NSObject
|
||||
|
@ -64,20 +61,22 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
|
|||
@synthesize m_searchBar;
|
||||
@synthesize m_table;
|
||||
|
||||
- (void)setSearchFunc:(SearchF)s andShowRectFunc:(ShowRectF)r
|
||||
andGetViewportCenterFunc:(GetViewportCenterF)c
|
||||
- (id)initWithFramework:(framework_t *)framework
|
||||
{
|
||||
g_searchF = s;
|
||||
g_showRectF = r;
|
||||
g_getViewportCenterF = c;
|
||||
m_locationManager = [[CLLocationManager alloc] init];
|
||||
m_locationManager.delegate = self;
|
||||
// filter out unnecessary events
|
||||
m_locationManager.headingFilter = 3;
|
||||
m_locationManager.distanceFilter = 1.0;
|
||||
[m_locationManager startUpdatingLocation];
|
||||
if ([CLLocationManager headingAvailable])
|
||||
[m_locationManager startUpdatingHeading];
|
||||
if ((self = [super initWithNibName:@"Search" bundle:nil]))
|
||||
{
|
||||
m_framework = framework;
|
||||
m_locationManager = [[CLLocationManager alloc] init];
|
||||
m_locationManager.delegate = self;
|
||||
// filter out unnecessary events
|
||||
m_locationManager.headingFilter = 3;
|
||||
m_locationManager.distanceFilter = 1.0;
|
||||
[m_locationManager startUpdatingLocation];
|
||||
if ([CLLocationManager headingAvailable])
|
||||
[m_locationManager startUpdatingHeading];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)clearResults
|
||||
|
@ -154,7 +153,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
|
|||
|
||||
if ([searchText length] > 0)
|
||||
{
|
||||
g_searchF([[searchText precomposedStringWithCompatibilityMapping] UTF8String],
|
||||
m_framework->Search([[searchText precomposedStringWithCompatibilityMapping] UTF8String],
|
||||
bind(&OnSearchResultCallback, _1, g_queryId));
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +201,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
|
|||
}
|
||||
}
|
||||
|
||||
m2::PointD const center = g_getViewportCenterF();
|
||||
m2::PointD const center = m_framework->GetViewportCenter();
|
||||
return ang::AngleTo(center, pt);
|
||||
}
|
||||
|
||||
|
@ -215,7 +214,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
|
|||
return ms::DistanceOnEarth(loc.coordinate.latitude, loc.coordinate.longitude, ptLat, ptLon);
|
||||
else
|
||||
{
|
||||
m2::PointD const center = g_getViewportCenterF();
|
||||
m2::PointD const center = m_framework->GetViewportCenter();
|
||||
return ms::DistanceOnEarth(MercatorBounds::YToLat(center.y), MercatorBounds::XToLon(center.x),
|
||||
ptLat, ptLon);
|
||||
}
|
||||
|
@ -286,7 +285,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
|
|||
{
|
||||
// Zoom to the feature
|
||||
case search::Result::RESULT_FEATURE:
|
||||
g_showRectF(res.GetFeatureRect());
|
||||
m_framework->ShowRect(res.GetFeatureRect());
|
||||
[self searchBarCancelButtonClicked:m_searchBar];
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue