diff --git a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OABaseTrackMenuHudViewController.mm b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OABaseTrackMenuHudViewController.mm index 764e15fe1b..9dd6add6e0 100644 --- a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OABaseTrackMenuHudViewController.mm +++ b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OABaseTrackMenuHudViewController.mm @@ -18,6 +18,8 @@ #import "OASavingTrackHelper.h" #import "OAGPXTrackAnalysis.h" #import "GeneratedAssetSymbols.h" +#import "OASelectedGPXHelper.h" +#import "OAGPXUIHelper.h" @implementation OAGPXBaseTableData @@ -231,11 +233,31 @@ - (void)updateGpxData:(BOOL)replaceGPX updateDocument:(BOOL)updateDocument else { NSString *gpxFullPath = [[OsmAndApp instance].gpxPath stringByAppendingPathComponent:_gpx.gpxFilePath]; - _doc = [[OAGPXMutableDocument alloc] initWithGpxFile:gpxFullPath]; + const auto& activeGpx = [OASelectedGPXHelper instance].activeGpx; + auto it = activeGpx.find(QString::fromNSString(gpxFullPath)); + if (it != activeGpx.end()) + _doc = [[OAGPXMutableDocument alloc] initWithGpxDocument:std::const_pointer_cast(it.value())]; + else + _doc = [[OAGPXMutableDocument alloc] initWithGpxFile:gpxFullPath]; } } [self updateAnalysis]; + if (_gpx && !_gpx.nearestCity && _analysis && _analysis.locationStart) + { + OAPOI *nearestCity = [OAGPXUIHelper searchNearestCity:_analysis.locationStart.position]; + _gpx.nearestCity = nearestCity ? nearestCity.nameLocalized : @""; + + OAGPXDatabase *db = [OAGPXDatabase sharedDb]; + OAGPX *gpx = [db getGPXItem:_gpx.gpxFilePath]; + if (gpx) + { + gpx.nearestCity = _gpx.nearestCity; + [db replaceGpxItem:gpx]; + [db save]; + } + } + if (replaceGPX) { if (_isCurrentTrack) @@ -246,6 +268,7 @@ - (void)updateGpxData:(BOOL)replaceGPX updateDocument:(BOOL)updateDocument { OAGPXDatabase *db = [OAGPXDatabase sharedDb]; OAGPX *gpx = [db buildGpxItem:_gpx.gpxFilePath title:_doc.metadata.name desc:_doc.metadata.desc bounds:_doc.bounds document:_doc]; + gpx.nearestCity = _gpx.nearestCity; [db replaceGpxItem:gpx]; [db save]; _gpx = gpx; diff --git a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.h b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.h index 6f5420f5d2..aff8dd7fe2 100644 --- a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.h +++ b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.h @@ -55,7 +55,8 @@ shownTrack:(BOOL)shownTrack isNetworkRoute:(BOOL)isNetworkRoute routeIcon:(UIImage *)icon - title:(NSString *)title; + title:(NSString *)title + nearestCity:(NSString *)nearestCity; + (NSMutableArray *)generateGpxBlockStatistics:(OAGPXTrackAnalysis *)analysis withoutGaps:(BOOL)withoutGaps; - (void)generateGpxBlockStatistics:(OAGPXTrackAnalysis *)analysis diff --git a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.mm b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.mm index 3bbadf3cd6..1117f9d0fc 100644 --- a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.mm +++ b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHeaderView.mm @@ -122,6 +122,7 @@ - (void)updateHeader:(BOOL)currentTrack isNetworkRoute:(BOOL)isNetworkRoute routeIcon:(UIImage *)icon title:(NSString *)title + nearestCity:(NSString *)nearestCity { self.backgroundColor = _selectedTab != EOATrackMenuHudActionsTab ? [UIColor colorNamed:ACColorNameGroupBg] : [UIColor colorNamed:ACColorNameViewBg]; @@ -138,14 +139,12 @@ - (void)updateHeader:(BOOL)currentTrack if (_selectedTab == EOATrackMenuHudOverviewTab) { CLLocationCoordinate2D gpxLocation = kCLLocationCoordinate2DInvalid; - OAPOI *nearestCity; if (self.trackMenuDelegate) { if ([self.trackMenuDelegate openedFromMap]) gpxLocation = [self.trackMenuDelegate getPinLocation]; if (!CLLocationCoordinate2DIsValid(gpxLocation)) gpxLocation = [self.trackMenuDelegate getCenterGpxLocation]; - nearestCity = [OAGPXUIHelper checkAndSearchNearestCity:[self.trackMenuDelegate getGeneralAnalysis]]; } CLLocation *lastKnownLocation = _app.locationServices.lastKnownLocation; @@ -162,11 +161,11 @@ - (void)updateHeader:(BOOL)currentTrack self.directionTextView.textColor = [UIColor colorNamed:ACColorNameTextColorActive]; } - if (nearestCity) + if (nearestCity.length > 0) { self.regionIconView.image = [UIImage templateImageNamed:@"ic_small_map_point"]; self.regionIconView.tintColor = [UIColor colorNamed:ACColorNameIconColorSecondary]; - [self.regionTextView setText:nearestCity.nameLocalized]; + [self.regionTextView setText:nearestCity]; self.regionTextView.textColor = [UIColor colorNamed:ACColorNameTextColorSecondary]; } else diff --git a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHudViewController.mm b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHudViewController.mm index 6eef125ae5..75c96ba94d 100644 --- a/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHudViewController.mm +++ b/Sources/Controllers/TargetMenu/GPX/TrackMenu/OATrackMenuHudViewController.mm @@ -511,7 +511,8 @@ - (void)setupHeaderView shownTrack:self.isShown isNetworkRoute:_isNewRoute routeIcon:isRoute ? _reopeningState.trackIcon : [UIImage templateImageNamed:@"ic_custom_trip"] - title:[self.gpx getNiceTitle]]; + title:[self.gpx getNiceTitle] + nearestCity:self.gpx.nearestCity]; [self.scrollableView addSubview:_headerView]; @@ -1496,7 +1497,8 @@ - (void)saveNetworkRoute shownTrack:self.isShown isNetworkRoute:_isNewRoute routeIcon:_reopeningState.trackIcon - title:[self.gpx getNiceTitle]]; + title:[self.gpx getNiceTitle] + nearestCity:gpx.nearestCity]; [self setupUIBuilder]; [_uiBuilder setupTabBar:self.tabBarView parentWidth:self.scrollableView.frame.size.width]; diff --git a/Sources/GPX/OAGPXDatabase.h b/Sources/GPX/OAGPXDatabase.h index 1d9b9d73f3..6559089f32 100644 --- a/Sources/GPX/OAGPXDatabase.h +++ b/Sources/GPX/OAGPXDatabase.h @@ -74,6 +74,7 @@ typedef NS_ENUM(NSInteger, EOAGpxSplitType) { @property (nonatomic) double metricEnd; @property (nonatomic) OAWptPt *locationStart; @property (nonatomic) OAWptPt *locationEnd; +@property (nonatomic) NSString *nearestCity; - (NSString *)getNiceTitle; diff --git a/Sources/GPX/OAGPXDatabase.mm b/Sources/GPX/OAGPXDatabase.mm index cca48ea8c7..0e5428fa8e 100644 --- a/Sources/GPX/OAGPXDatabase.mm +++ b/Sources/GPX/OAGPXDatabase.mm @@ -16,6 +16,8 @@ #import "OAUtilities.h" #import "OASavingTrackHelper.h" #import "OAGPXAppearanceCollection.h" +#import "OAGPXUIHelper.h" +#import "OAPOI.h" #define kDbName @"gpx.db" @@ -177,7 +179,14 @@ - (OAGPX *) buildGpxItem:(NSString *)fileName title:(NSString *)title desc:(NSSt - (OAGPX *) buildGpxItem:(NSString *)fileName path:(NSString *)filepath title:(NSString *)title desc:(NSString *)desc bounds:(OAGpxBounds)bounds document:(OAGPXDocument *)document { OAGPXTrackAnalysis *analysis = [document getAnalysis:0]; - + + NSString *nearestCity; + if (analysis.locationStart) + { + OAPOI *nearestCityPOI = [OAGPXUIHelper searchNearestCity:analysis.locationStart.position]; + nearestCity = nearestCityPOI ? nearestCityPOI.nameLocalized : @""; + } + OAGPX *gpx = [[OAGPX alloc] init]; NSString *pathToRemove = [OsmAndApp.instance.gpxPath stringByAppendingString:@"/"]; gpx.bounds = bounds; @@ -219,7 +228,8 @@ - (OAGPX *) buildGpxItem:(NSString *)fileName path:(NSString *)filepath title:(N gpx.metricEnd = analysis.metricEnd; gpx.locationStart = analysis.locationStart; gpx.locationEnd = analysis.locationEnd; - + gpx.nearestCity = nearestCity; + gpx.splitType = [self.class splitTypeByName:document.getSplitType]; gpx.splitInterval = [document getSplitInterval]; gpx.color = [document getColor:0]; @@ -552,6 +562,8 @@ - (NSDictionary *)generateGpxData:(OAGPX *)gpx [wpt setObject:@(gpx.locationEnd.speed) forKey:@"speed"]; [d setObject:wpt forKey:@"locationEnd"]; } + if (gpx.nearestCity) + [d setObject:gpx.nearestCity forKey:@"nearestCity"]; return d; } @@ -671,6 +683,10 @@ - (OAGPX *)generateGpxItem:(NSDictionary *)gpxData { gpx.hiddenGroups = [NSSet setWithArray:value]; } + else if ([key isEqualToString:@"nearestCity"]) + { + gpx.nearestCity = value; + } } if (!gpx.hiddenGroups) gpx.hiddenGroups = [NSSet set]; diff --git a/Sources/Helpers/OAGPXUIHelper.h b/Sources/Helpers/OAGPXUIHelper.h index c3572c7724..12a34e82d4 100644 --- a/Sources/Helpers/OAGPXUIHelper.h +++ b/Sources/Helpers/OAGPXUIHelper.h @@ -52,7 +52,7 @@ preciseLocation:(BOOL)preciseLocation joinSegments:(BOOL)joinSegments; -+ (OAPOI *)checkAndSearchNearestCity:(OAGPXTrackAnalysis *)analysis; ++ (OAPOI *)searchNearestCity:(CLLocationCoordinate2D)latLon; - (void) openExportForTrack:(OAGPX *)gpx gpxDoc:(id)gpxDoc isCurrentTrack:(BOOL)isCurrentTrack inViewController:(UIViewController *)hostViewController hostViewControllerDelegate:(id)hostViewControllerDelegate; - (void) copyGPXToNewFolder:(NSString *)newFolderName diff --git a/Sources/Helpers/OAGPXUIHelper.mm b/Sources/Helpers/OAGPXUIHelper.mm index fe8698abd7..2676831a06 100644 --- a/Sources/Helpers/OAGPXUIHelper.mm +++ b/Sources/Helpers/OAGPXUIHelper.mm @@ -450,12 +450,6 @@ + (CLLocationCoordinate2D)getIntermediatePointByDistance:(double)passedDistance return CLLocationCoordinate2DMake(prevPoint.position.latitude + dLat, prevPoint.position.longitude + dLon); } -+ (OAPOI *)checkAndSearchNearestCity:(OAGPXTrackAnalysis *)analysis -{ - OAWptPt *startPoint = analysis ? analysis.locationStart : nil; - return startPoint ? [self searchNearestCity:startPoint.position] : nil; -} - + (OAPOI *)searchNearestCity:(CLLocationCoordinate2D)latLon { OsmAnd::PointI pointI = OsmAnd::Utilities::convertLatLonTo31(OsmAnd::LatLon(latLon.latitude, latLon.longitude));