forked from organicmaps/organicmaps
[MAPSME-5030] [ios] Refactored MWMRouter to support intermediateIndex.
This commit is contained in:
parent
a298d37626
commit
f603b37392
8 changed files with 87 additions and 84 deletions
|
@ -169,7 +169,8 @@ BOOL defaultOrientation(CGSize const & size)
|
|||
kStatRoutingMode : kStatRoutingModePlanning
|
||||
}];
|
||||
[MWMRouter
|
||||
buildFromPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart]
|
||||
buildFromPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart
|
||||
intermediateIndex:0]
|
||||
bestRouter:NO];
|
||||
}
|
||||
|
||||
|
|
|
@ -255,9 +255,11 @@ using namespace osm_auth_ios;
|
|||
}];
|
||||
|
||||
auto p1 = [[MWMRoutePoint alloc] initWithURLSchemeRoutePoint:points.front()
|
||||
type:MWMRoutePointTypeStart];
|
||||
type:MWMRoutePointTypeStart
|
||||
intermediateIndex:0];
|
||||
auto p2 = [[MWMRoutePoint alloc] initWithURLSchemeRoutePoint:points.back()
|
||||
type:MWMRoutePointTypeFinish];
|
||||
type:MWMRoutePointTypeFinish
|
||||
intermediateIndex:0];
|
||||
[MWMRouter buildFromPoint:p1 toPoint:p2 bestRouter:NO];
|
||||
}
|
||||
else
|
||||
|
|
|
@ -8,8 +8,11 @@
|
|||
@property(nonatomic, readonly) RouteMarkData routeMarkData;
|
||||
|
||||
- (instancetype)initWithURLSchemeRoutePoint:(url_scheme::RoutePoint const &)point
|
||||
type:(MWMRoutePointType)type;
|
||||
type:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex;
|
||||
- (instancetype)initWithRouteMarkData:(RouteMarkData const &)point;
|
||||
- (instancetype)initWithPoint:(m2::PointD const &)point type:(MWMRoutePointType)type;
|
||||
- (instancetype)initWithPoint:(m2::PointD const &)point
|
||||
type:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex;
|
||||
|
||||
@end
|
||||
|
|
|
@ -6,13 +6,14 @@ typedef NS_ENUM(NSUInteger, MWMRoutePointType) {
|
|||
|
||||
@interface MWMRoutePoint : NSObject
|
||||
|
||||
- (instancetype)initWithLastLocationAndType:(MWMRoutePointType)type;
|
||||
- (instancetype)initWithLastLocationAndType:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex;
|
||||
|
||||
@property(copy, nonatomic, readonly) NSString * title;
|
||||
@property(copy, nonatomic, readonly) NSString * subtitle;
|
||||
@property(nonatomic, readonly) BOOL isMyPosition;
|
||||
@property(nonatomic, readonly) MWMRoutePointType type;
|
||||
@property(nonatomic, readonly) int8_t intermediateIndex;
|
||||
@property(nonatomic) MWMRoutePointType type;
|
||||
@property(nonatomic) int8_t intermediateIndex;
|
||||
|
||||
@property(nonatomic, readonly) double latitude;
|
||||
@property(nonatomic, readonly) double longitude;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
@implementation MWMRoutePoint
|
||||
|
||||
- (instancetype)initWithLastLocationAndType:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex
|
||||
{
|
||||
auto lastLocation = [MWMLocationManager lastLocation];
|
||||
if (!lastLocation)
|
||||
|
@ -28,13 +29,14 @@
|
|||
_subtitle = L(@"");
|
||||
_isMyPosition = YES;
|
||||
_type = type;
|
||||
_intermediateIndex = 0;
|
||||
_intermediateIndex = intermediateIndex;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithURLSchemeRoutePoint:(url_scheme::RoutePoint const &)point
|
||||
type:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
|
@ -44,7 +46,7 @@
|
|||
_subtitle = L(@"");
|
||||
_isMyPosition = NO;
|
||||
_type = type;
|
||||
_intermediateIndex = 0;
|
||||
_intermediateIndex = intermediateIndex;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -69,7 +71,9 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithPoint:(m2::PointD const &)point type:(MWMRoutePointType)type
|
||||
- (instancetype)initWithPoint:(m2::PointD const &)point
|
||||
type:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
|
@ -84,7 +88,7 @@
|
|||
_subtitle = L(@"");
|
||||
_isMyPosition = NO;
|
||||
_type = type;
|
||||
_intermediateIndex = 0;
|
||||
_intermediateIndex = intermediateIndex;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -32,11 +32,9 @@ typedef void (^MWMImageHeightBlock)(UIImage *, NSString *);
|
|||
+ (void)setTurnNotificationsLocale:(NSString *)locale;
|
||||
+ (NSArray<NSString *> *)turnNotifications;
|
||||
|
||||
+ (void)removeStartPointAndRebuild:(int8_t)intermediateIndex;
|
||||
+ (void)removeFinishPointAndRebuild:(int8_t)intermediateIndex;
|
||||
+ (void)addIntermediatePointAndRebuild:(MWMRoutePoint *)point
|
||||
intermediateIndex:(int8_t)intermediateIndex;
|
||||
+ (void)removeIntermediatePointAndRebuild:(int8_t)intermediateIndex;
|
||||
+ (void)addPointAndRebuild:(MWMRoutePoint *)point;
|
||||
+ (void)removePointAndRebuild:(MWMRoutePoint *)point;
|
||||
|
||||
+ (void)buildFromPoint:(MWMRoutePoint *)start bestRouter:(BOOL)bestRouter;
|
||||
+ (void)buildToPoint:(MWMRoutePoint *)finish bestRouter:(BOOL)bestRouter;
|
||||
+ (void)buildFromPoint:(MWMRoutePoint *)startPoint
|
||||
|
|
|
@ -179,20 +179,21 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI
|
|||
if (type == self.type)
|
||||
return;
|
||||
|
||||
// Try to cancel transaction if we switched router type back.
|
||||
[self cancelTaxiTransaction];
|
||||
|
||||
// Taxi routing does not support intermediate points.
|
||||
auto & rm = GetFramework().GetRoutingManager();
|
||||
if (type == MWMRouterTypeTaxi)
|
||||
{
|
||||
auto router = [MWMRouter router];
|
||||
router.taxiRoutePointTransactionId = rm.OpenRoutePointsTransaction();
|
||||
rm.RemoveIntermediateRoutePoints();
|
||||
}
|
||||
|
||||
[self openTaxiTransaction];
|
||||
else
|
||||
[self cancelTaxiTransaction];
|
||||
|
||||
[self doStop:NO];
|
||||
rm.SetRouter(coreRouterType(type));
|
||||
GetFramework().GetRoutingManager().SetRouter(coreRouterType(type));
|
||||
}
|
||||
|
||||
+ (void)openTaxiTransaction
|
||||
{
|
||||
auto & rm = GetFramework().GetRoutingManager();
|
||||
auto router = [MWMRouter router];
|
||||
router.taxiRoutePointTransactionId = rm.OpenRoutePointsTransaction();
|
||||
rm.RemoveIntermediateRoutePoints();
|
||||
}
|
||||
|
||||
+ (void)cancelTaxiTransaction
|
||||
|
@ -243,22 +244,22 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI
|
|||
return [turnNotifications copy];
|
||||
}
|
||||
|
||||
+ (void)removePoint:(RouteMarkType)type intermediateIndex:(int8_t)intermediateIndex
|
||||
{
|
||||
[self applyTaxiTransaction];
|
||||
GetFramework().GetRoutingManager().RemoveRoutePoint(type, intermediateIndex);
|
||||
[[MWMNavigationDashboardManager manager] onRoutePointsUpdated];
|
||||
}
|
||||
|
||||
+ (void)addPoint:(MWMRoutePoint *)point intermediateIndex:(int8_t)intermediateIndex
|
||||
+ (void)removePoint:(MWMRoutePoint *)point
|
||||
{
|
||||
[self applyTaxiTransaction];
|
||||
RouteMarkData pt = point.routeMarkData;
|
||||
pt.m_intermediateIndex = intermediateIndex;
|
||||
GetFramework().GetRoutingManager().AddRoutePoint(std::move(pt));
|
||||
GetFramework().GetRoutingManager().RemoveRoutePoint(pt.m_pointType, pt.m_intermediateIndex);
|
||||
[[MWMNavigationDashboardManager manager] onRoutePointsUpdated];
|
||||
}
|
||||
|
||||
+ (void)removePointAndRebuild:(MWMRoutePoint *)point
|
||||
{
|
||||
if (!point)
|
||||
return;
|
||||
[self removePoint:point];
|
||||
[self rebuildWithBestRouter:NO];
|
||||
}
|
||||
|
||||
+ (void)addPoint:(MWMRoutePoint *)point
|
||||
{
|
||||
if (!point)
|
||||
|
@ -272,30 +273,11 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI
|
|||
[[MWMNavigationDashboardManager manager] onRoutePointsUpdated];
|
||||
}
|
||||
|
||||
+ (void)removeStartPointAndRebuild:(int8_t)intermediateIndex
|
||||
{
|
||||
[self removePoint:RouteMarkType::Start intermediateIndex:intermediateIndex];
|
||||
[self rebuildWithBestRouter:NO];
|
||||
}
|
||||
|
||||
+ (void)removeFinishPointAndRebuild:(int8_t)intermediateIndex
|
||||
{
|
||||
[self removePoint:RouteMarkType::Finish intermediateIndex:intermediateIndex];
|
||||
[self rebuildWithBestRouter:NO];
|
||||
}
|
||||
|
||||
+ (void)addIntermediatePointAndRebuild:(MWMRoutePoint *)point
|
||||
intermediateIndex:(int8_t)intermediateIndex
|
||||
+ (void)addPointAndRebuild:(MWMRoutePoint *)point
|
||||
{
|
||||
if (!point)
|
||||
return;
|
||||
[self addPoint:point intermediateIndex:intermediateIndex];
|
||||
[self rebuildWithBestRouter:NO];
|
||||
}
|
||||
|
||||
+ (void)removeIntermediatePointAndRebuild:(int8_t)intermediateIndex
|
||||
{
|
||||
[self removePoint:RouteMarkType::Intermediate intermediateIndex:intermediateIndex];
|
||||
[self addPoint:point];
|
||||
[self rebuildWithBestRouter:NO];
|
||||
}
|
||||
|
||||
|
@ -313,7 +295,8 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI
|
|||
return;
|
||||
[self addPoint:finishPoint];
|
||||
if (![self startPoint] && [MWMLocationManager lastLocation])
|
||||
[self addPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart]];
|
||||
[self addPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart
|
||||
intermediateIndex:0]];
|
||||
[self rebuildWithBestRouter:bestRouter];
|
||||
}
|
||||
|
||||
|
@ -398,7 +381,8 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI
|
|||
!p2.isMyPosition;
|
||||
[alertController presentPoint2PointAlertWithOkBlock:^{
|
||||
[self buildFromPoint:[[MWMRoutePoint alloc]
|
||||
initWithLastLocationAndType:MWMRoutePointTypeStart]
|
||||
initWithLastLocationAndType:MWMRoutePointTypeStart
|
||||
intermediateIndex:0]
|
||||
bestRouter:NO];
|
||||
}
|
||||
needToRebuild:needToRebuild];
|
||||
|
|
|
@ -62,13 +62,13 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
|
|||
[Statistics logEvent:eventName withParameters:stat atLocation:[MWMLocationManager lastLocation]];
|
||||
}
|
||||
|
||||
void logPointEvent(MWMRoutePoint * pt, NSString * eventType)
|
||||
void logPointEvent(MWMRoutePoint * point, NSString * eventType)
|
||||
{
|
||||
if (pt == nullptr)
|
||||
if (point == nullptr)
|
||||
return;
|
||||
|
||||
NSString * pointTypeStr = @"";
|
||||
switch (pt.type)
|
||||
switch (point.type)
|
||||
{
|
||||
case MWMRoutePointTypeStart: pointTypeStr = kStatRoutingPointTypeStart; break;
|
||||
case MWMRoutePointTypeIntermediate: pointTypeStr = kStatRoutingPointTypeIntermediate; break;
|
||||
|
@ -82,7 +82,7 @@ void logPointEvent(MWMRoutePoint * pt, NSString * eventType)
|
|||
withParameters:@{
|
||||
kStatRoutingPointType : pointTypeStr,
|
||||
kStatRoutingPointValue :
|
||||
(pt.isMyPosition ? kStatRoutingPointValueMyPosition : kStatRoutingPointValuePoint),
|
||||
(point.isMyPosition ? kStatRoutingPointValueMyPosition : kStatRoutingPointValuePoint),
|
||||
kStatRoutingPointMethod :
|
||||
(isPlanning ? kStatRoutingPointMethodPlanning : kStatRoutingPointMethodNoPlanning),
|
||||
kStatRoutingMode : (isOnRoute ? kStatRoutingModeOnRoute : kStatRoutingModePlanning)
|
||||
|
@ -330,9 +330,9 @@ void logPointEvent(MWMRoutePoint * pt, NSString * eventType)
|
|||
[Statistics logEvent:kStatEventName(kStatPlacePage, kStatBuildRoute)
|
||||
withParameters:@{kStatValue : kStatSource}];
|
||||
|
||||
MWMRoutePoint * pt = [self routePointWithType:MWMRoutePointTypeStart];
|
||||
logPointEvent(pt, kStatRoutingAddPoint);
|
||||
[MWMRouter buildFromPoint:pt bestRouter:YES];
|
||||
MWMRoutePoint * point = [self routePointWithType:MWMRoutePointTypeStart intermediateIndex:0];
|
||||
logPointEvent(point, kStatRoutingAddPoint);
|
||||
[MWMRouter buildFromPoint:point bestRouter:YES];
|
||||
[self close];
|
||||
}
|
||||
|
||||
|
@ -341,38 +341,42 @@ void logPointEvent(MWMRoutePoint * pt, NSString * eventType)
|
|||
[Statistics logEvent:kStatEventName(kStatPlacePage, kStatBuildRoute)
|
||||
withParameters:@{kStatValue : kStatDestination}];
|
||||
|
||||
MWMRoutePoint * pt = [self routePointWithType:MWMRoutePointTypeFinish];
|
||||
logPointEvent(pt, kStatRoutingAddPoint);
|
||||
[MWMRouter buildToPoint:pt bestRouter:YES];
|
||||
MWMRoutePoint * point = [self routePointWithType:MWMRoutePointTypeFinish intermediateIndex:0];
|
||||
logPointEvent(point, kStatRoutingAddPoint);
|
||||
[MWMRouter buildToPoint:point bestRouter:YES];
|
||||
[self close];
|
||||
}
|
||||
|
||||
- (void)addStop
|
||||
{
|
||||
MWMRoutePoint * pt = [self routePointWithType:MWMRoutePointTypeIntermediate];
|
||||
logPointEvent(pt, kStatRoutingAddPoint);
|
||||
[MWMRouter addIntermediatePointAndRebuild:pt intermediateIndex:0];
|
||||
MWMRoutePoint * point =
|
||||
[self routePointWithType:MWMRoutePointTypeIntermediate intermediateIndex:0];
|
||||
logPointEvent(point, kStatRoutingAddPoint);
|
||||
[MWMRouter addPointAndRebuild:point];
|
||||
[self shouldClose];
|
||||
}
|
||||
|
||||
- (void)removeStop
|
||||
{
|
||||
auto data = self.data;
|
||||
MWMRoutePoint * point = nil;
|
||||
switch (data.routeMarkType)
|
||||
{
|
||||
case RouteMarkType::Start:
|
||||
logPointEvent([self routePointWithType:MWMRoutePointTypeStart], kStatRoutingRemovePoint);
|
||||
[MWMRouter removeStartPointAndRebuild:data.intermediateIndex];
|
||||
point =
|
||||
[self routePointWithType:MWMRoutePointTypeStart intermediateIndex:data.intermediateIndex];
|
||||
break;
|
||||
case RouteMarkType::Finish:
|
||||
logPointEvent([self routePointWithType:MWMRoutePointTypeFinish], kStatRoutingRemovePoint);
|
||||
[MWMRouter removeFinishPointAndRebuild:data.intermediateIndex];
|
||||
point =
|
||||
[self routePointWithType:MWMRoutePointTypeFinish intermediateIndex:data.intermediateIndex];
|
||||
break;
|
||||
case RouteMarkType::Intermediate:
|
||||
logPointEvent([self routePointWithType:MWMRoutePointTypeIntermediate], kStatRoutingRemovePoint);
|
||||
[MWMRouter removeIntermediatePointAndRebuild:data.intermediateIndex];
|
||||
point = [self routePointWithType:MWMRoutePointTypeIntermediate
|
||||
intermediateIndex:data.intermediateIndex];
|
||||
break;
|
||||
}
|
||||
logPointEvent(point, kStatRoutingRemovePoint);
|
||||
[MWMRouter removePointAndRebuild:point];
|
||||
[self shouldClose];
|
||||
}
|
||||
|
||||
|
@ -391,18 +395,22 @@ void logPointEvent(MWMRoutePoint * pt, NSString * eventType)
|
|||
[Statistics logEvent:kStatPlacePageTaxiClick
|
||||
withParameters:@{kStatProvider : providerString, kStatTags : data.statisticsTags}];
|
||||
[MWMRouter setType:MWMRouterTypeTaxi];
|
||||
[MWMRouter buildToPoint:[self routePointWithType:MWMRoutePointTypeFinish] bestRouter:NO];
|
||||
MWMRoutePoint * point = [self routePointWithType:MWMRoutePointTypeFinish intermediateIndex:0];
|
||||
logPointEvent(point, kStatRoutingAddPoint);
|
||||
[MWMRouter buildToPoint:point bestRouter:NO];
|
||||
[self close];
|
||||
}
|
||||
|
||||
- (MWMRoutePoint *)routePointWithType:(MWMRoutePointType)type
|
||||
intermediateIndex:(int8_t)intermediateIndex
|
||||
{
|
||||
auto data = self.data;
|
||||
if (!data)
|
||||
return nil;
|
||||
|
||||
if (data.isMyPosition)
|
||||
return [[MWMRoutePoint alloc] initWithLastLocationAndType:type];
|
||||
return [[MWMRoutePoint alloc] initWithLastLocationAndType:type
|
||||
intermediateIndex:intermediateIndex];
|
||||
|
||||
NSString * name = nil;
|
||||
if (data.title.length > 0)
|
||||
|
@ -416,7 +424,9 @@ void logPointEvent(MWMRoutePoint * pt, NSString * eventType)
|
|||
else
|
||||
name = L(@"placepage_unknown_place");
|
||||
|
||||
return [[MWMRoutePoint alloc] initWithPoint:data.mercator type:type];
|
||||
return [[MWMRoutePoint alloc] initWithPoint:data.mercator
|
||||
type:type
|
||||
intermediateIndex:intermediateIndex];
|
||||
}
|
||||
|
||||
- (void)share
|
||||
|
|
Loading…
Add table
Reference in a new issue