-
Notifications
You must be signed in to change notification settings - Fork 99
Refactor map objects selecting #4611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
da96403
c40fba2
4b56e11
dc544f3
7e96a60
8d51b8e
41f058f
76180e7
e1a5d81
c1e2901
e50c23e
6463f4a
70e63ad
0d23fa7
6e51364
d00d9a6
aa94c94
e271dd8
0afdfc0
2da9584
6682665
d79a304
621d723
a478b2a
12a229c
0614622
6954fb0
3edbbad
aa2fc0a
e1d2efb
4ab8b34
c3fa963
585d8e5
4b819a3
3167fa7
deeed19
4ecbf5f
24a9451
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,20 @@ - (instancetype) init | |
|
||
- (void) commonInit | ||
{ | ||
_clickableTags = [NSSet setWithObjects:@"piste:type", @"piste:difficulty", @"mtb:scale", @"dirtbike:scale", nil]; | ||
_requiredTagsAny = [NSSet setWithObjects:@"name", @"ref", @"piste:name", @"mtb:name", nil]; | ||
_clickableTags = [NSSet setWithArray:@[ | ||
@"piste:type", | ||
@"piste:difficulty", | ||
@"mtb:scale", | ||
@"dirtbike:scale" | ||
]]; | ||
|
||
_requiredTagsAny = [NSSet setWithArray:@[ | ||
@"name", | ||
@"ref", | ||
@"piste:name", | ||
@"mtb:name" | ||
]]; | ||
|
||
_forbiddenTags = @{ | ||
@"area": @"yes", | ||
@"access": @"no", | ||
|
@@ -89,11 +101,12 @@ - (OAClickableWay *) loadClickableWay:(CLLocation *)selectedLatLon obfMapObject: | |
|
||
- (BOOL) isClickableWayTags:(NSDictionary<NSString *, NSString *> *)tags | ||
{ | ||
for (NSString *forbiddenKey in _forbiddenTags.allKeys) | ||
for (NSString *forbiddenKey in _forbiddenTags) | ||
{ | ||
NSString *forbiddenValue = _forbiddenTags[forbiddenKey]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add NSString *tagValue = tags[forbiddenKey]; |
||
if ([forbiddenValue isEqualToString:tags[forbiddenKey]] || | ||
([@"*" isEqualToString:forbiddenValue] && tags[forbiddenKey])) | ||
NSString *tagValue = tags[forbiddenKey]; | ||
if ([forbiddenValue isEqualToString:tagValue] || | ||
([@"*" isEqualToString:forbiddenValue] && tagValue)) | ||
{ | ||
return NO; | ||
} | ||
|
@@ -103,7 +116,7 @@ - (BOOL) isClickableWayTags:(NSDictionary<NSString *, NSString *> *)tags | |
{ | ||
if (tags[required]) | ||
{ | ||
for (NSString *key in tags.allKeys) | ||
for (NSString *key in tags) | ||
{ | ||
if ([_clickableTags containsObject:key]) | ||
return YES; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,22 @@ | |
// Copyright © 2025 OsmAnd. All rights reserved. | ||
// | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class OAMapSelectionResult, OAPOI; | ||
|
||
@interface OAMapSelectionHelper : NSObject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up (macros) |
||
|
||
- (OAMapSelectionResult *) collectObjectsFromMap:(CGPoint)point showUnknownLocation:(BOOL)showUnknownLocation; | ||
- (OAMapSelectionResult *)collectObjectsFromMap:(CGPoint)point showUnknownLocation:(BOOL)showUnknownLocation; | ||
|
||
+ (OAPOI *) findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names obfId:(uint64_t)obfId; | ||
+ (OAPOI *) findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names obfId:(uint64_t)obfId radius:(int)radius; | ||
+ (NSArray<OAPOI *> *) findAmenities:(CLLocation *)latLon; | ||
+ (OAPOI *) findAmenityByOsmId:(CLLocation *)latLon obfId:(uint64_t)obfId; | ||
+ (OAPOI *) findAmenityByOsmId:(NSArray<OAPOI *> *)amenities obfId:(uint64_t)obfId point:(CLLocation *)point; | ||
+ (OAPOI *) findAmenityByName:(NSArray<OAPOI *> *)amenities names:(NSArray<NSString *> *)names; | ||
+ (OAPOI *)findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names obfId:(uint64_t)obfId; | ||
+ (OAPOI *)findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names obfId:(uint64_t)obfId radius:(int)radius; | ||
+ (NSArray<OAPOI *> *)findAmenities:(CLLocation *)latLon; | ||
+ (OAPOI *)findAmenityByOsmId:(CLLocation *)latLon obfId:(uint64_t)obfId; | ||
+ (OAPOI *)findAmenityByOsmId:(NSArray<OAPOI *> *)amenities obfId:(uint64_t)obfId point:(CLLocation *)point; | ||
+ (OAPOI *)findAmenityByName:(NSArray<OAPOI *> *)amenities names:(NSArray<NSString *> *)names; | ||
|
||
@end | ||
|
||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ - (void) collectObjectsFromLayers:(OAMapSelectionResult *)result unknownLocation | |
|
||
for (OAMapLayer *layer in layers) | ||
{ | ||
//Android doesn't have that layer here | ||
// Android doesn't have that layer here | ||
if ([layer isKindOfClass:OAOsmBugsLayer.class]) | ||
continue; | ||
|
||
|
@@ -251,7 +251,7 @@ - (CLLocation *) parsePoiLatLon:(NSString *)value | |
if (!value) | ||
return nil; | ||
|
||
OASKGeoParsedPoint * p = [OASKMapUtils.shared decodeShortLinkStringS:value]; | ||
OASKGeoParsedPoint *p = [OASKMapUtils.shared decodeShortLinkStringS:value]; | ||
return [[CLLocation alloc] initWithLatitude:p.getLatitude longitude:p.getLongitude]; | ||
} | ||
|
||
|
@@ -303,7 +303,7 @@ - (void) addRenderedObject:(OAMapSelectionResult *)result symbolInfo:(OsmAnd::IM | |
{ | ||
[renderedObject setIconRes:rasterMapSymbol->content.toNSString()]; | ||
} | ||
for (NSString *key in tags.allKeys) | ||
for (NSString *key in tags) | ||
{ | ||
renderedObject.tags[key] = tags[key]; | ||
|
||
|
@@ -405,9 +405,9 @@ - (BOOL) isUniqueTravelGpx:(NSMutableArray<OASelectedMapObject *> *)selectedObje | |
[selectedObject.provider isKindOfClass:OAGPXLayer.class]) | ||
{ | ||
NSArray *pair = (NSArray *)selectedObject.object; | ||
if ([pair[0] isKindOfClass:OATravelGpx.class]) | ||
if ([pair firstObject] && [[pair firstObject] isKindOfClass:OATravelGpx.class]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to extract [pair firstObject] into a let variable. Also, checking with if ([yourLet isKindOfClass:OATravelGpx.class]) {} is sufficient. |
||
{ | ||
OATravelGpx *gpx = pair[0]; | ||
OATravelGpx *gpx = [pair firstObject]; | ||
|
||
// TODO: test this isEqual method | ||
if (travelGpx == gpx) | ||
|
@@ -555,7 +555,7 @@ - (void) processTransportStops:(NSMutableArray<OASelectedMapObject *> *)selected | |
return tagsMap; | ||
} | ||
|
||
+ (OAPOI *) findAmenity:(CLLocation *)latLon names:(NSMutableArray<NSString *> *)names obfId:(uint64_t)obfId | ||
+ (OAPOI *) findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names obfId:(uint64_t)obfId | ||
{ | ||
int searchRadius = [ObfConstants isIdFromRelation:obfId >> AMENITY_ID_RIGHT_SHIFT] ? | ||
AMENITY_SEARCH_RADIUS_FOR_RELATION : | ||
|
@@ -570,7 +570,8 @@ + (OAPOI *) findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names | |
OsmAnd::PointI point31 = OsmAnd::Utilities::convertLatLonTo31(OsmAnd::LatLon(latLon.coordinate.latitude, latLon.coordinate.longitude)); | ||
OsmAnd::AreaI rect = (OsmAnd::AreaI)OsmAnd::Utilities::boundingBox31FromAreaInMeters(radius, point31); | ||
|
||
NSArray<OAPOI *> *amenities = [OAPOIHelper findPOI:OASearchPoiTypeFilter.acceptAllPoiTypeFilter additionalFilter:nil bbox31:rect currentLocation:point31 includeTravel:YES matcher:nil publish:nil]; | ||
BOOL (^nilBlock)(OAPOI *poi) = nil; | ||
NSArray<OAPOI *> *amenities = [OAPOIHelper findPOI:OASearchPoiTypeFilter.acceptAllPoiTypeFilter additionalFilter:nil bbox31:rect currentLocation:point31 includeTravel:YES matcher:nil publish:nilBlock]; | ||
OAPOI *amenity = [self findAmenityByOsmId:amenities obfId:osmId point:latLon]; | ||
|
||
if (!amenity && names.count > 0) | ||
|
@@ -584,7 +585,8 @@ + (OAPOI *) findAmenity:(CLLocation *)latLon names:(NSArray<NSString *> *)names | |
{ | ||
OsmAnd::PointI point31 = OsmAnd::Utilities::convertLatLonTo31(OsmAnd::LatLon(latLon.coordinate.latitude, latLon.coordinate.longitude)); | ||
OsmAnd::AreaI rect = (OsmAnd::AreaI)OsmAnd::Utilities::boundingBox31FromAreaInMeters(AMENITY_SEARCH_RADIUS, point31); | ||
return [OAPOIHelper findPOI:OASearchPoiTypeFilter.acceptAllPoiTypeFilter additionalFilter:nil bbox31:rect currentLocation:point31 includeTravel:YES matcher:nil publish:nil]; | ||
BOOL (^nilBlock)(OAPOI *poi) = nil; | ||
return [OAPOIHelper findPOI:[OASearchPoiTypeFilter acceptAllPoiTypeFilter] additionalFilter:nil bbox31:rect currentLocation:point31 includeTravel:YES matcher:nil publish:nilBlock]; | ||
} | ||
|
||
+ (OAPOI *) findAmenityByOsmId:(CLLocation *)latLon obfId:(uint64_t)obfId | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
|
||
#import "OAContextMenuProvider.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
|
||
@class OAPOI, OASelectedMapObject, OAPlaceDetailsObject; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. macros |
||
|
||
@interface OAPlaceDetailsObject : NSObject | ||
|
@@ -16,17 +19,20 @@ | |
@property (nonatomic, readonly) NSMutableSet<NSString *> *wikidataIds; | ||
@property (nonatomic, readonly) NSMutableArray<OASelectedMapObject *> *selectedObjects; | ||
|
||
- (instancetype) initWithObject:(id<OAContextMenuProvider>)object provider:(id<OAContextMenuProvider>)provider; | ||
- (instancetype)initWithObject:(id<OAContextMenuProvider>)object provider:(id<OAContextMenuProvider>)provider; | ||
|
||
- (OAPOI *) getSyntheticAmenity; | ||
- (CLLocation *) getLocation; | ||
- (NSMutableArray<OASelectedMapObject *> *) getSelectedObjects; | ||
- (void) addObject:(id)object provider:(id<OAContextMenuProvider>)provider; | ||
- (BOOL) overlapsWith:(id)object; | ||
- (void) merge:(OAPlaceDetailsObject*)other; | ||
- (void) combineData; | ||
- (void) processAmenity:(OAPOI *)amenity contentLocales:(NSMutableSet<NSString *> *)contentLocales; | ||
- (OAPOI *)getSyntheticAmenity; | ||
- (CLLocation *)getLocation; | ||
- (NSMutableArray<OASelectedMapObject *> *)getSelectedObjects; | ||
- (void)addObject:(id)object provider:(id<OAContextMenuProvider>)provider; | ||
- (BOOL)overlapsWith:(id)object; | ||
- (void)merge:(OAPlaceDetailsObject*)other; | ||
- (void)combineData; | ||
- (void)processAmenity:(OAPOI *)amenity contentLocales:(NSMutableSet<NSString *> *)contentLocales; | ||
|
||
+ (BOOL) shouldSkip:(id) object; | ||
+ (BOOL)shouldSkip:(id) object; | ||
|
||
@end | ||
|
||
|
||
NS_ASSUME_NONNULL_END |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use macros in .h files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.