Skip to content

Commit

Permalink
Merge branch 'r4.8-pre' of github.com:osmandapp/OsmAnd-ios into r4.8-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
vshcherb committed Aug 2, 2024
2 parents f4e1ae3 + 01ef2db commit 63b593d
Show file tree
Hide file tree
Showing 35 changed files with 1,024 additions and 203 deletions.
4 changes: 4 additions & 0 deletions OsmAnd.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@
46964F762C345448007F3938 /* ColorPaletteHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46964F752C345448007F3938 /* ColorPaletteHelper.swift */; };
46993C0A2986BCB70047F2F5 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 46993C092986BCB60047F2F5 /* [email protected] */; };
46A27270281DD05E00FF591D /* osm-carto.render.xml in Resources */ = {isa = PBXBuildFile; fileRef = 46A2726F281DD05D00FF591D /* osm-carto.render.xml */; };
46A35EF52C53F9510089B21C /* DirectoryObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A35EF42C53F9510089B21C /* DirectoryObserver.swift */; };
46A8FD33297D985700AF9C0C /* OAUninstallSpeedCamerasViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A8FD32297D985700AF9C0C /* OAUninstallSpeedCamerasViewController.mm */; };
46AB58A729C4C979003B2FB9 /* OAWikipediaImagesSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 46AB58A629C4C979003B2FB9 /* OAWikipediaImagesSettingsViewController.m */; };
46AD052A2C29E2060032C3B7 /* color-palette in Resources */ = {isa = PBXBuildFile; fileRef = 46AD05292C29E2060032C3B7 /* color-palette */; };
Expand Down Expand Up @@ -4199,6 +4200,7 @@
46964F752C345448007F3938 /* ColorPaletteHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPaletteHelper.swift; sourceTree = "<group>"; };
46993C092986BCB60047F2F5 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Icons/[email protected]"; sourceTree = "<group>"; };
46A2726F281DD05D00FF591D /* osm-carto.render.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = "osm-carto.render.xml"; path = "../resources/rendering_styles/osm-carto.render.xml"; sourceTree = "<group>"; };
46A35EF42C53F9510089B21C /* DirectoryObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryObserver.swift; sourceTree = "<group>"; };
46A8FD31297D982200AF9C0C /* OAUninstallSpeedCamerasViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OAUninstallSpeedCamerasViewController.h; sourceTree = "<group>"; };
46A8FD32297D985700AF9C0C /* OAUninstallSpeedCamerasViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = OAUninstallSpeedCamerasViewController.mm; sourceTree = "<group>"; };
46AB58A529C4C967003B2FB9 /* OAWikipediaImagesSettingsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OAWikipediaImagesSettingsViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -13371,6 +13373,7 @@
0590D19B2BF88AF400C62AF5 /* ConcurrentDictionary.swift */,
32A0CDF52C29B07B00FDD8E0 /* Model3dHelper */,
4665DB6D2C20BBFD00F897EC /* ColorsPaletteUtils.swift */,
46A35EF42C53F9510089B21C /* DirectoryObserver.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -17136,6 +17139,7 @@
DA5A836B26C563A800F274C7 /* OADestinationItemsListViewController.mm in Sources */,
DA5A81B026C563A700F274C7 /* OADownloadsManager.m in Sources */,
DA5A84D326C563A900F274C7 /* OAMapSettingsOverlayUnderlayScreen.mm in Sources */,
46A35EF52C53F9510089B21C /* DirectoryObserver.swift in Sources */,
DA5A813126C563A700F274C7 /* OAWebClient.mm in Sources */,
DA5A833926C563A800F274C7 /* OAFoldersCell.m in Sources */,
3234101A28889D1B00E90FBA /* OARowInfo.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,67 @@ - (void)commonInit
if (!_basePaletteColorItem)
_basePaletteColorItem = [_gradientColorsCollection getGradientPaletteBy:[[TerrainMode getDefaultMode:_terrainMode.type] getKeyName]];
_currentPaletteColorItem = _basePaletteColorItem;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onColorPalettesFilesUpdated:)
name:ColorPaletteHelper.colorPalettesUpdatedNotification
object:nil];
}

_minZoom = _baseMinZoom;
_maxZoom = _baseMaxZoom;
_currentAlpha = _baseAlpha;
}

- (void)onColorPalettesFilesUpdated:(NSNotification *)notification
{
if (![notification.object isKindOfClass:NSDictionary.class] || _terrainType != EOATerrainSettingsTypePalette)
return;

NSDictionary<NSString *, NSString *> *colorPaletteFiles = (NSDictionary *) notification.object;
if (!colorPaletteFiles)
return;
NSString *currentPaletteFile = [_terrainMode getMainFile];
BOOL reloadData = NO;
BOOL deleted = NO;
for (NSString *colorPaletteFile in colorPaletteFiles.allKeys)
{
if ([_gradientColorsCollection hasTerrainGradientPaletteBy:colorPaletteFile]
|| [colorPaletteFiles[colorPaletteFile] isEqualToString:DirectoryObserver.createdKey])
{
reloadData = YES;
if ([currentPaletteFile isEqualToString:colorPaletteFile]
&& [colorPaletteFiles[colorPaletteFile] isEqualToString:DirectoryObserver.deletedKey])
{
deleted = YES;
break;
}
}
}
if (reloadData)
{
_gradientColorsCollection = [[GradientColorsCollection alloc] initWithTerrainType:_terrainMode.type];
_sortedPaletteColorItems = [NSMutableArray arrayWithArray:[_gradientColorsCollection getPaletteColors]];
if (deleted)
_basePaletteColorItem = [_gradientColorsCollection getDefaultGradientPalette];
else
_basePaletteColorItem = [_gradientColorsCollection getGradientPaletteBy:[_terrainMode getKeyName]];
_currentPaletteColorItem = _basePaletteColorItem;

dispatch_async(dispatch_get_main_queue(), ^{
[self generateData];
[UIView transitionWithView:self.tableView
duration:0.35f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void)
{
[self.tableView reloadData];
}
completion:nil];
});
}
}

- (void)configureGPXVerticalExaggerationScale:(CGFloat)scale
{
if (_terrainType == EOAGPXSettingsTypeVerticalExaggeration)
Expand Down Expand Up @@ -224,7 +278,7 @@ - (NSString *)getHeaderText
result = OALocalizedString(@"visibility");
break;
case EOATerrainSettingsTypePalette:
result = _terrainMode.translateName;
result = [_terrainMode getDescription];
break;
case EOATerrainSettingsTypeZoomLevels:
result = OALocalizedString(@"shared_string_zoom_levels");
Expand Down Expand Up @@ -792,6 +846,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
OASimpleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[OASimpleTableViewCell getCellIdentifier]];
[cell leftIconVisibility:NO];
[cell descriptionVisibility:NO];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.titleLabel.text = [_currentPaletteColorItem toHumanString];
cell.titleLabel.textColor = UIColorFromRGB(color_extra_text_gray);
cell.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
Expand All @@ -811,7 +866,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
[cell setCollectionHandler:paletteHandler];

[cell rightActionButtonVisibility:NO];
[cell.collectionView reloadData];
[cell.collectionView performBatchUpdates:^{
for (NSInteger i = 0; i < cell.collectionView.numberOfSections; i ++)
{
[cell.collectionView reloadSections:[NSIndexSet indexSetWithIndex:i]];
}
} completion:nil];
[cell layoutIfNeeded];
return cell;
}
Expand Down
104 changes: 67 additions & 37 deletions Sources/Controllers/Map/Layers/OAGPXLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @implementation OAGPXLayer
QHash< QString, QList<OsmAnd::FColorARGB> > _cachedColors;
QHash< QString, QList<OsmAnd::FColorARGB> > _cachedWallColors;
NSMutableDictionary<NSString *, NSNumber *> *_cachedTrackWidth;
NSMutableDictionary<NSString *, NSString *> *_updatedColorPaletteFiles;

NSOperationQueue *_splitLabelsQueue;
NSObject* _splitLock;
Expand Down Expand Up @@ -98,8 +99,14 @@ - (void) initLayer

_cachedTracks = [NSMutableDictionary dictionary];
_cachedTrackWidth = [NSMutableDictionary dictionary];
_updatedColorPaletteFiles = [NSMutableDictionary dictionary];

_plugin = (OASRTMPlugin *) [OAPluginsHelper getPlugin:OASRTMPlugin.class];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onColorPalettesFilesUpdated:)
name:ColorPaletteHelper.colorPalettesUpdatedNotification
object:nil];
}

- (void) resetLayer
Expand Down Expand Up @@ -137,6 +144,33 @@ - (BOOL) updateLayer
return YES;
}

- (void)onColorPalettesFilesUpdated:(NSNotification *)notification
{
if (![notification.object isKindOfClass:NSDictionary.class])
return;

NSDictionary<NSString *, NSString *> *colorPaletteFiles = (NSDictionary *) notification.object;
if (!colorPaletteFiles)
return;
BOOL refresh = NO;
for (NSString *colorPaletteFile in colorPaletteFiles)
{
if ([colorPaletteFile hasPrefix:ColorPaletteHelper.routePrefix])
{
_updatedColorPaletteFiles[colorPaletteFile] = colorPaletteFiles[colorPaletteFile];
refresh = YES;
}
}
if (refresh)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.mapViewController runWithRenderSync:^{
[self refreshGpxTracks:_gpxDocs reset:YES];
}];
});
}
}

- (void) refreshGpxTracks:(QHash< QString, std::shared_ptr<const OsmAnd::GpxDocument> >)gpxDocs reset:(BOOL)reset
{
if (reset)
Expand Down Expand Up @@ -222,7 +256,7 @@ - (void)addTrackToCached:(QString)key value:(std::shared_ptr<const OsmAnd::GpxDo
cachedTrack[@"doc"] = doc;
cachedTrack[@"colorization_scheme"] = @(COLORIZATION_NONE);
cachedTrack[@"prev_coloring_type"] = gpx.coloringType;
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : @"default";
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : PaletteGradientColor.defaultName;
cachedTrack[@"prev_wall_coloring_type"] = @(gpx.visualization3dWallColorType);
_cachedTracks[filePath] = cachedTrack;
_cachedColors[key] = QList<OsmAnd::FColorARGB>();
Expand All @@ -244,28 +278,20 @@ - (void)configureCachedWallColorsFor:(OAColoringType *)type
}
else
{
NSError *error = nil;
ColorPalette *palette =
[[ColorPaletteHelper shared] getGradientColorPaletteSync:(ColorizationType) [type toColorizationType]
gradientPaletteName:gradientPalette
error:&error];
if (error)
{
NSLog(@"Error reading color palette file: %@", error.description);
gradientPaletteName:gradientPalette];
if (!palette)
return;
}
else
{
OARouteColorize *routeColorize =
[[OARouteColorize alloc] initWithGpxFile:doc
analysis:analysis ?: [doc getAnalysis:0]
type:[type toColorizationType]
palette:palette
maxProfileSpeed:0];
_cachedWallColors[key].clear();
if (routeColorize)
_cachedWallColors[key].append([routeColorize getResultQList]);
}
OARouteColorize *routeColorize =
[[OARouteColorize alloc] initWithGpxFile:doc
analysis:analysis ?: [doc getAnalysis:0]
type:[type toColorizationType]
palette:palette
maxProfileSpeed:0];
_cachedWallColors[key].clear();
if (routeColorize)
_cachedWallColors[key].append([routeColorize getResultQList]);
}
}

Expand Down Expand Up @@ -312,15 +338,27 @@ - (void) refreshGpxTracks
type = OAColoringType.DEFAULT;

OAGPXTrackAnalysis *analysis;
NSString *colorPaletteFile = @"";
if ([type isGradient])
{
colorPaletteFile =
[ColorPaletteHelper getRoutePaletteFileName:(ColorizationType) [type toColorizationType]
gradientPaletteName:cachedTrack[@"prev_color_palette"]];
}
if ([type isGradient]
&& (![cachedTrack[@"prev_coloring_type"] isEqualToString:gpx.coloringType]
|| ![cachedTrack[@"prev_color_palette"] isEqualToString:gpx.gradientPaletteName]
|| [cachedTrack[@"colorization_scheme"] intValue] != COLORIZATION_GRADIENT
|| [_updatedColorPaletteFiles.allKeys containsObject:colorPaletteFile]
|| _cachedColors[key].isEmpty()))
{
NSString *updatedColorPaletteValue = _updatedColorPaletteFiles[colorPaletteFile];
BOOL isColorPaletteDeleted = [updatedColorPaletteValue isEqualToString:DirectoryObserver.deletedKey];
[_updatedColorPaletteFiles removeObjectForKey:colorPaletteFile];

cachedTrack[@"colorization_scheme"] = @(COLORIZATION_GRADIENT);
cachedTrack[@"prev_coloring_type"] = gpx.coloringType;
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : @"default";
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length == 0 || isColorPaletteDeleted ? PaletteGradientColor.defaultName : gpx.gradientPaletteName;
BOOL shouldCalculateColorCache = YES;
// check if we already have a cached array of wall color points that can be reused for route line color, provided that the coloring type matches
switch (gpx.visualization3dWallColorType)
Expand All @@ -341,28 +379,20 @@ - (void) refreshGpxTracks
if (shouldCalculateColorCache)
{
analysis = [doc getAnalysis:0];
NSError *error = nil;
ColorPalette *palette =
[[ColorPaletteHelper shared] getGradientColorPaletteSync:(ColorizationType) [type toColorizationType]
gradientPaletteName:cachedTrack[@"prev_color_palette"]
error:&error];
if (error)
{
NSLog(@"Error reading color palette file: %@", error.description);
gradientPaletteName:cachedTrack[@"prev_color_palette"]];
if (!palette)
return;
}
else
{
OARouteColorize *routeColorize =
OARouteColorize *routeColorize =
[[OARouteColorize alloc] initWithGpxFile:doc
analysis:analysis
type:[type toColorizationType]
palette:palette
maxProfileSpeed:0];
_cachedColors[key].clear();
if (routeColorize)
_cachedColors[key].append([routeColorize getResultQList]);
}
_cachedColors[key].clear();
if (routeColorize)
_cachedColors[key].append([routeColorize getResultQList]);
}
else
{
Expand All @@ -388,7 +418,7 @@ - (void) refreshGpxTracks
}
cachedTrack[@"colorization_scheme"] = @(COLORIZATION_SOLID);
cachedTrack[@"prev_coloring_type"] = gpx.coloringType;
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : @"default";
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : PaletteGradientColor.defaultName;
_cachedColors[key].clear();
[self calculateSegmentsColor:_cachedColors[key]
attrName:gpx.coloringType
Expand All @@ -402,7 +432,7 @@ - (void) refreshGpxTracks
{
cachedTrack[@"colorization_scheme"] = @(COLORIZATION_NONE);
cachedTrack[@"prev_coloring_type"] = gpx.coloringType;
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : @"default";
cachedTrack[@"prev_color_palette"] = gpx.gradientPaletteName.length > 0 ? gpx.gradientPaletteName : PaletteGradientColor.defaultName;
_cachedColors[key].clear();
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Controllers/Map/Layers/OAMapLayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
- (void) updateLayers;

- (void) updateWeatherDate:(NSDate *)date;
- (void) updateWeatherLayers;

- (void) showLayer:(NSString *)layerId;
- (void) hideLayer:(NSString *)layerId;
Expand Down
7 changes: 7 additions & 0 deletions Sources/Controllers/Map/Layers/OAMapLayers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ - (void) updateWeatherDate:(NSDate *)date
[_weatherContourLayer updateDate:date];
}

- (void) updateWeatherLayers
{
[_weatherLayerLow updateWeatherLayer];
[_weatherLayerHigh updateWeatherLayer];
[_weatherContourLayer updateLayer];
}

- (void) addLayer:(OAMapLayer *)layer
{
[layer initLayer];
Expand Down
11 changes: 2 additions & 9 deletions Sources/Controllers/Map/Layers/OAPreviewRouteLineLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void) initLayer
{
[super initLayer];

_routeGradientPalette = @"default";
_routeGradientPalette = PaletteGradientColor.defaultName;
_routingHelper = OARoutingHelper.sharedInstance;

_collection = std::make_shared<OsmAnd::VectorLinesCollection>();
Expand Down Expand Up @@ -597,15 +597,8 @@ - (void)fillSlopeGradientArrays:(QVector<OsmAnd::PointI> &)points distances:(NSM
if (gradientScaleType)
{
ColorizationType colorizationType = (ColorizationType) [gradientScaleType toColorizationType];
NSError *error = nil;
previewPalette = [[ColorPaletteHelper shared] requireGradientColorPaletteSync:colorizationType
gradientPaletteName:_routeGradientPalette
error:&error];
if (error)
{
NSLog(@"Error reading color palette file: %@", error.description);
return;
}
gradientPaletteName:_routeGradientPalette];
}
NSMutableArray<NSNumber *> *palette = [NSMutableArray array];
for (ColorValue *colorValue in [previewPalette colorValues])
Expand Down
Loading

0 comments on commit 63b593d

Please sign in to comment.