Skip to content

Commit

Permalink
Merge pull request #3594 from osmandapp/suggest_maps_during_navigatio…
Browse files Browse the repository at this point in the history
…n_miss_map

add onlyJointMap
  • Loading branch information
tigrim committed Apr 16, 2024
2 parents ff89e2f + 0a57df8 commit bf3aed3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,10 @@ - (void)configureResourceItems

NSArray<OAResourceItem *> *resources = [NSArray arrayWithArray:[_missingMapsResources arrayByAddingObjectsFromArray:_mapsToUpdateResources]];

NSArray *sortedRegionsMaps = [resources sortedArrayUsingComparator:^NSComparisonResult(OAResourceItem *obj1, OAResourceItem *obj2) {
return [obj1.title compare:obj2.title];
}];

if (sortedRegionsMaps.count > 0)
if (resources.count > 0)
{
_resourcesItems = sortedRegionsMaps;
_selectedResourcesItems = [sortedRegionsMaps mutableCopy];
_resourcesItems = resources;
_selectedResourcesItems = [resources mutableCopy];
[self.tableView reloadData];
}
}
Expand Down
22 changes: 17 additions & 5 deletions Sources/Helpers/MissingMapsCalculator/MissingMapsCalculator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ - (BOOL)checkIfThereAreMissingMaps:(std::shared_ptr<RoutingContext>)ctx

for (auto* file : getOpenMapFiles())
{

NSString *regionName = [NSString stringWithCString:file->inputName.c_str()
encoding:[NSString defaultCStringEncoding]];
NSString *downloadName = regionName.lastPathComponent;
Expand Down Expand Up @@ -270,7 +269,8 @@ - (void)addPoint:(std::shared_ptr<RoutingContext>)ctx
{
NSMutableArray<NSString *> *regions = [NSMutableArray array];

NSArray<OAWorldRegion *> *regionsArray = [_or getWorldRegionsAt:loc.coordinate.latitude longitude:loc.coordinate.longitude];
NSArray<OAWorldRegion *> *regionsArray = [_or getWorldRegionsAtWithoutSort:loc.coordinate.latitude longitude:loc.coordinate.longitude];
BOOL onlyJointMap = YES;

for (OAWorldRegion *region in regionsArray)
{
Expand All @@ -280,13 +280,15 @@ - (void)addPoint:(std::shared_ptr<RoutingContext>)ctx
regionDownloadId = [regionDownloadId substringToIndex:[regionDownloadId length] - 1];
}
[regions addObject:regionDownloadId];
if (!region.regionJoinMap && !region.regionJoinRoads) {
onlyJointMap = NO;
}
}
[regions sortUsingComparator:^NSComparisonResult(NSString * _Nonnull o1, NSString * _Nonnull o2) {
NSInteger lengthComparisonResult = [@(o1.length) compare:@(o2.length)];
return (NSComparisonResult)(-lengthComparisonResult);
}];

if (pointsToCheck.count == 0 || ![regions isEqualToArray:_lastKeyNames])
if ((pointsToCheck.count == 0 || ![regions isEqualToArray:_lastKeyNames]) && !onlyJointMap)
{
MissingMapsCalculatorPoint *pnt = [MissingMapsCalculatorPoint new];
_lastKeyNames = regions;
Expand Down Expand Up @@ -339,7 +341,17 @@ SearchQuery q((uint32_t)(x31 << zoomToLoad), (uint32_t)((x31 + 1) << zoomToLoad)
[worldRegions addObject:worldRegion];
}
}
return [[worldRegions sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]] copy];
return [[self getSortedByDistanceRegions:worldRegions lat:self.startPoint.coordinate.latitude lon:self.startPoint.coordinate.longitude] copy];
}

- (NSArray<OAWorldRegion *> *) getSortedByDistanceRegions:(NSArray<OAWorldRegion *> *)array lat:(double)lat lon:(double)lon
{
return [array sortedArrayUsingComparator:^NSComparisonResult(OAWorldRegion *obj1, OAWorldRegion *obj2)
{
const auto distance1 = OsmAnd::Utilities::distance(lon, lat, obj1.regionCenter.longitude, obj1.regionCenter.latitude);
const auto distance2 = OsmAnd::Utilities::distance(lon, lat, obj2.regionCenter.longitude, obj2.regionCenter.latitude);
return distance1 > distance2 ? NSOrderedDescending : distance1 < distance2 ? NSOrderedAscending : NSOrderedSame;
}];
}

- (BOOL)addMapEditions:(NSDictionary<NSString *, RegisteredMap *> *)knownMaps
Expand Down
3 changes: 3 additions & 0 deletions Sources/OAWorldRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
@property (readonly) NSString* regionRoadSigns;
@property (readonly) NSString* wikiLink;
@property (readonly) NSString* population;
@property (readonly) BOOL regionJoinMap;
@property (readonly) BOOL regionJoinRoads;

@property (readonly) CLLocationCoordinate2D bboxTopLeft;
@property (readonly) CLLocationCoordinate2D bboxBottomRight;
Expand All @@ -54,6 +56,7 @@

- (NSArray<OAWorldRegion *> *) queryAtLat:(double)lat lon:(double)lon;
- (NSArray<OAWorldRegion *> *) getWorldRegionsAt:(double)latitude longitude:(double)longitude;
- (NSArray<OAWorldRegion *> *)getWorldRegionsAtWithoutSort:(double)latitude longitude:(double)longitude;
- (OAWorldRegion *) findAtLat:(double)latitude lon:(double)longitude;
- (NSString *) getCountryNameAtLat:(double)latitude lon:(double)longitude;
- (double) getArea;
Expand Down
17 changes: 16 additions & 1 deletion Sources/OAWorldRegion.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ - (instancetype) initFrom:(const std::shared_ptr<const OsmAnd::WorldRegion> &)re
_regionRoadSigns = _worldRegion->regionRoadSigns.toNSString();
_wikiLink = _worldRegion->wikiLink.toNSString();
_population = _worldRegion->population.toNSString();
_regionJoinMap = _worldRegion->regionJoinMap;
_regionJoinRoads = _worldRegion->regionJoinRoads;

OsmAnd::LatLon latLonTopLeft = OsmAnd::Utilities::convert31ToLatLon(region->mapObject->bbox31.topLeft);
OsmAnd::LatLon latLonBottomRight = OsmAnd::Utilities::convert31ToLatLon(region->mapObject->bbox31.bottomRight);
Expand Down Expand Up @@ -659,7 +661,20 @@ - (BOOL) isBoundary
return [NSArray arrayWithArray:res];
}

- (NSArray<OAWorldRegion *> *) getWorldRegionsAt:(double)latitude longitude:(double)longitude
- (NSArray<OAWorldRegion *> *)getWorldRegionsAtWithoutSort:(double)latitude longitude:(double)longitude
{
NSMutableArray<OAWorldRegion *> *mapRegions = [NSMutableArray arrayWithArray:[self queryAtLat:latitude lon:longitude]];
if (mapRegions.count > 0)
{
[mapRegions.copy enumerateObjectsUsingBlock:^(OAWorldRegion * _Nonnull region, NSUInteger idx, BOOL * _Nonnull stop) {
if (![region contain:latitude lon:longitude])
[mapRegions removeObject:region];
}];
}
return mapRegions;
}

- (NSArray<OAWorldRegion *> *)getWorldRegionsAt:(double)latitude longitude:(double)longitude
{
NSMutableArray<OAWorldRegion *> *mapRegions = [NSMutableArray arrayWithArray:[self queryAtLat:latitude lon:longitude]];
if (mapRegions.count > 0)
Expand Down

0 comments on commit bf3aed3

Please sign in to comment.