diff --git a/Examples.xcodeproj/project.pbxproj b/Examples.xcodeproj/project.pbxproj index d4cdd3b3..488dfe67 100644 --- a/Examples.xcodeproj/project.pbxproj +++ b/Examples.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ 05FA53A91FE2FB46001F3D7D /* CustomCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FA53A81FE2FB46001F3D7D /* CustomCalloutView.m */; }; 05FA53AB1FE2FB9C001F3D7D /* CustomCalloutViewExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FA53AA1FE2FB9B001F3D7D /* CustomCalloutViewExample.m */; }; 05FA53AD1FE2FBB3001F3D7D /* DefaultCalloutExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FA53AC1FE2FBB2001F3D7D /* DefaultCalloutExample.m */; }; + 072BC2A121AF5D0D0056F4AE /* symbol-z-order.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 072BC2A021AF5D0D0056F4AE /* symbol-z-order.xcassets */; }; 079E77C51E1C4E2100F92FA8 /* camera.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 079E77C41E1C4E2100F92FA8 /* camera.xcassets */; }; 07C138C01E6F646F00D6F678 /* MultipleShapesExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 07C138BF1E6F646F00D6F678 /* MultipleShapesExample.m */; }; 07C138C21E6F65D000D6F678 /* MultipleShapesExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07C138C11E6F65D000D6F678 /* MultipleShapesExample.swift */; }; @@ -40,6 +41,8 @@ 07F53B851E00D02100B58DB3 /* AnnotationViewsAndImagesExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 07F53B841E00D02100B58DB3 /* AnnotationViewsAndImagesExample.m */; }; 1F1F84751E538ABB00332CC3 /* BlockingGesturesDelegateExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F1F84741E538ABB00332CC3 /* BlockingGesturesDelegateExample.m */; }; 1F1F84771E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1F84761E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift */; }; + 2F00FCD121750D5A0028FC69 /* SymbolLayerZOrderExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F00FCD021750D5A0028FC69 /* SymbolLayerZOrderExample.m */; }; + 2F00FCD3217511760028FC69 /* SymbolLayerZOrderExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F00FCD2217511760028FC69 /* SymbolLayerZOrderExample.swift */; }; 3E085B801EC526C500163C99 /* BuildingsExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E085B7F1EC526C500163C99 /* BuildingsExample.swift */; }; 3E085B831EC526E500163C99 /* BuildingsExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E085B821EC526E500163C99 /* BuildingsExample.m */; }; 3E1806101EAA800A004DB131 /* UserLocationAnnotationExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E18060F1EAA800A004DB131 /* UserLocationAnnotationExample.m */; }; @@ -216,6 +219,7 @@ 05FA53A81FE2FB46001F3D7D /* CustomCalloutView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomCalloutView.m; sourceTree = ""; }; 05FA53AA1FE2FB9B001F3D7D /* CustomCalloutViewExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomCalloutViewExample.m; sourceTree = ""; }; 05FA53AC1FE2FBB2001F3D7D /* DefaultCalloutExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DefaultCalloutExample.m; sourceTree = ""; }; + 072BC2A021AF5D0D0056F4AE /* symbol-z-order.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "symbol-z-order.xcassets"; sourceTree = ""; }; 079E77C41E1C4E2100F92FA8 /* camera.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = camera.xcassets; sourceTree = ""; }; 07C138BE1E6F646F00D6F678 /* MultipleShapesExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultipleShapesExample.h; sourceTree = ""; }; 07C138BF1E6F646F00D6F678 /* MultipleShapesExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MultipleShapesExample.m; sourceTree = ""; }; @@ -232,6 +236,9 @@ 1F1F84761E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockingGesturesDelegateExample.swift; sourceTree = ""; }; 29A0D7C8DCD539DCA5DA1BAC /* Pods-Examples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Examples.release.xcconfig"; path = "Pods/Target Support Files/Pods-Examples/Pods-Examples.release.xcconfig"; sourceTree = ""; }; 2ECF27F4ACA1A3CA05DE1954 /* Pods-DocsCode.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocsCode.release.xcconfig"; path = "Pods/Target Support Files/Pods-DocsCode/Pods-DocsCode.release.xcconfig"; sourceTree = ""; }; + 2F00FCCF21750D5A0028FC69 /* SymbolLayerZOrderExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SymbolLayerZOrderExample.h; sourceTree = ""; }; + 2F00FCD021750D5A0028FC69 /* SymbolLayerZOrderExample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SymbolLayerZOrderExample.m; sourceTree = ""; }; + 2F00FCD2217511760028FC69 /* SymbolLayerZOrderExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolLayerZOrderExample.swift; sourceTree = ""; }; 3E085B7F1EC526C500163C99 /* BuildingsExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildingsExample.swift; sourceTree = ""; }; 3E085B811EC526E500163C99 /* BuildingsExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BuildingsExample.h; sourceTree = ""; }; 3E085B821EC526E500163C99 /* BuildingsExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BuildingsExample.m; sourceTree = ""; }; @@ -476,6 +483,7 @@ 3EBCD70D1DC28240001E342F /* ImageAnnotationExample.swift */, 3E1806111EAA804B004DB131 /* UserLocationAnnotationExample.swift */, 64BBDB021DF24E0900BB705D /* WebAPIDataExample.swift */, + 2F00FCD2217511760028FC69 /* SymbolLayerZOrderExample.swift */, ); name = "Markers and callouts"; sourceTree = ""; @@ -577,6 +585,7 @@ 96D431FB1C84B4F7007D09D1 /* ImageAnnotationExample.m */, 3E18060F1EAA800A004DB131 /* UserLocationAnnotationExample.m */, 64BBDAFC1DF24DEB00BB705D /* WebAPIDataExample.m */, + 2F00FCD021750D5A0028FC69 /* SymbolLayerZOrderExample.m */, ); name = "Markers and callouts"; sourceTree = ""; @@ -811,6 +820,7 @@ 3EC92DB61E78C431001D0503 /* metro-line.geojson */, 3E25C5DE2056E7E2005B031E /* nps-icons.xcassets */, 96D432051C84B9CF007D09D1 /* pisavector.xcassets */, + 072BC2A021AF5D0D0056F4AE /* symbol-z-order.xcassets */, DDF9432A1E5DEACC00545D0F /* ports.geojson */, 3E4574EC1FA3D8F1000C8CF1 /* radar.gif */, 64BBDAEF1DF22D9600BB705D /* third_party_vector_style.json */, @@ -864,6 +874,7 @@ 968247011C5BDCBB00494AB8 /* StudioClassicStyleExample.h */, 9691AAA11C5AAD8F006A58C6 /* StudioStyleExample.h */, 05536CB3200F9B4900657097 /* SwitchStylesExample.h */, + 2F00FCCF21750D5A0028FC69 /* SymbolLayerZOrderExample.h */, 64CF970E1DF224D400C3C27B /* ThirdPartyVectorStyleExample.h */, 3E18060E1EAA800A004DB131 /* UserLocationAnnotationExample.h */, 969E7FDB1D25C31700663F84 /* UserTrackingModesExample.h */, @@ -1127,6 +1138,7 @@ 3EC92DB71E78C431001D0503 /* metro-line.geojson in Resources */, 9619629F1C581700002D3DAB /* LaunchScreen.storyboard in Resources */, DD5939E61E6778480009BEB2 /* clustering.xcassets in Resources */, + 072BC2A121AF5D0D0056F4AE /* symbol-z-order.xcassets in Resources */, 079E77C51E1C4E2100F92FA8 /* camera.xcassets in Resources */, 9619629C1C581700002D3DAB /* Assets.xcassets in Resources */, 9682471D1C5C123B00494AB8 /* example.geojson in Resources */, @@ -1390,6 +1402,7 @@ 3EBCD7221DC28240001E342F /* LineAnnotationGeoJSONExample.swift in Sources */, 3E085B831EC526E500163C99 /* BuildingsExample.m in Sources */, 3E9EF27C209CFD460053D1D7 /* HeatmapExample.swift in Sources */, + 2F00FCD3217511760028FC69 /* SymbolLayerZOrderExample.swift in Sources */, 64BBDAF61DF232FD00BB705D /* SelectFeatureExample.swift in Sources */, CA3B162E2098CA7E005C087B /* TestingSupport.m in Sources */, 64BBDAF81DF2330B00BB705D /* SelectFeatureExample.m in Sources */, @@ -1436,6 +1449,7 @@ 05FA53A61FE2FA34001F3D7D /* OfflinePackExample.m in Sources */, 3E22EF521F8821F800605203 /* ImageSourceExample.m in Sources */, 05FA53A71FE2FA34001F3D7D /* StaticSnapshotExample.m in Sources */, + 2F00FCD121750D5A0028FC69 /* SymbolLayerZOrderExample.m in Sources */, 3EBCD71C1DC28240001E342F /* CustomCalloutViewExample.swift in Sources */, 05FA53AD1FE2FBB3001F3D7D /* DefaultCalloutExample.m in Sources */, CA39B2C1209B881300D37037 /* AnnotationViewExample+UITesting.m in Sources */, @@ -1724,6 +1738,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 0; DEVELOPMENT_TEAM = GJZR2MEM28; FRAMEWORK_SEARCH_PATHS = ( @@ -1734,6 +1749,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.examples; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Examples/Examples-Bridging-Header.h"; SWIFT_VERSION = 4.0; }; @@ -1747,6 +1763,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 0; DEVELOPMENT_TEAM = GJZR2MEM28; FRAMEWORK_SEARCH_PATHS = ( @@ -1757,6 +1774,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.examples; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Examples/Examples-Bridging-Header.h"; SWIFT_VERSION = 4.0; }; diff --git a/Examples/Examples.h b/Examples/Examples.h index 30d1c433..19c045ae 100644 --- a/Examples/Examples.h +++ b/Examples/Examples.h @@ -57,6 +57,7 @@ extern NSString *const MBXExampleStaticSnapshot; extern NSString *const MBXExampleStudioClassicStyle; extern NSString *const MBXExampleStudioStyle; extern NSString *const MBXExampleSwitchStyles; +extern NSString *const MBXExampleSymbolLayerZOrder; extern NSString *const MBXExampleThirdPartyVectorStyle; extern NSString *const MBXExampleUserLocationAnnotation; extern NSString *const MBXExampleUserTrackingModes; diff --git a/Examples/Examples.m b/Examples/Examples.m index 90873494..cf882cc2 100644 --- a/Examples/Examples.m +++ b/Examples/Examples.m @@ -53,6 +53,7 @@ + (NSArray *)groups { @{@"className": MBXExamplePolygonAnnotation, @"title": @"Add a polygon annotation"}, @{@"className": MBXExampleLineStyleLayer, @"title": @"Add a line style layer from GeoJSON"}, @{@"className": MBXExampleAnimatedLine, @"title": @"Animate a line"}, + @{@"className": MBXExampleSymbolLayerZOrder, @"title": @"Specify z order of features in a symbol layer"} ] }, @{ diff --git a/Examples/Files/clustering.xcassets/marker.imageset/Contents.json b/Examples/Files/clustering.xcassets/marker.imageset/Contents.json index 37439e12..5fc72b0a 100644 --- a/Examples/Files/clustering.xcassets/marker.imageset/Contents.json +++ b/Examples/Files/clustering.xcassets/marker.imageset/Contents.json @@ -4,6 +4,14 @@ "idiom" : "universal", "filename" : "marker.pdf", "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" } ], "info" : { diff --git a/Examples/Files/clustering.xcassets/squircle.imageset/Contents.json b/Examples/Files/clustering.xcassets/squircle.imageset/Contents.json index 2fb896be..7eddcb22 100644 --- a/Examples/Files/clustering.xcassets/squircle.imageset/Contents.json +++ b/Examples/Files/clustering.xcassets/squircle.imageset/Contents.json @@ -4,6 +4,14 @@ "idiom" : "universal", "filename" : "squircle.pdf", "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" } ], "info" : { diff --git a/Examples/Files/clustering.xcassets/star.imageset/Contents.json b/Examples/Files/clustering.xcassets/star.imageset/Contents.json index 19c4c1cf..7b2919e9 100644 --- a/Examples/Files/clustering.xcassets/star.imageset/Contents.json +++ b/Examples/Files/clustering.xcassets/star.imageset/Contents.json @@ -4,6 +4,14 @@ "idiom" : "universal", "filename" : "star.pdf", "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" } ], "info" : { diff --git a/Examples/Files/symbol-z-order.xcassets/Contents.json b/Examples/Files/symbol-z-order.xcassets/Contents.json new file mode 100644 index 00000000..da4a164c --- /dev/null +++ b/Examples/Files/symbol-z-order.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/Contents.json b/Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/Contents.json new file mode 100644 index 00000000..5360e172 --- /dev/null +++ b/Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "green-triangle.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/green-triangle.png b/Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/green-triangle.png new file mode 100644 index 00000000..b3203233 Binary files /dev/null and b/Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/green-triangle.png differ diff --git a/Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/Contents.json b/Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/Contents.json new file mode 100644 index 00000000..ed18f37c --- /dev/null +++ b/Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "purple-triangle.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/purple-triangle.png b/Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/purple-triangle.png new file mode 100644 index 00000000..9b4711f4 Binary files /dev/null and b/Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/purple-triangle.png differ diff --git a/Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/Contents.json b/Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/Contents.json new file mode 100644 index 00000000..ae04fbd1 --- /dev/null +++ b/Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "yellow-triangle-image.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/yellow-triangle-image.png b/Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/yellow-triangle-image.png new file mode 100644 index 00000000..78121da6 Binary files /dev/null and b/Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/yellow-triangle-image.png differ diff --git a/Examples/ObjectiveC/Headers/SymbolLayerZOrderExample.h b/Examples/ObjectiveC/Headers/SymbolLayerZOrderExample.h new file mode 100644 index 00000000..275bf7a7 --- /dev/null +++ b/Examples/ObjectiveC/Headers/SymbolLayerZOrderExample.h @@ -0,0 +1,10 @@ +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SymbolLayerZOrderExample : UIViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Examples/ObjectiveC/SymbolLayerZOrderExample.m b/Examples/ObjectiveC/SymbolLayerZOrderExample.m new file mode 100644 index 00000000..0da8bf2f --- /dev/null +++ b/Examples/ObjectiveC/SymbolLayerZOrderExample.m @@ -0,0 +1,107 @@ +#import "SymbolLayerZOrderExample.h" +@import Mapbox; + +NSString *const MBXExampleSymbolLayerZOrder = @"SymbolLayerZOrderExample"; + +@interface SymbolLayerZOrderExample () + +@property (nonatomic) MGLMapView *mapView; +@property (nonatomic) MGLSymbolStyleLayer *layer; + +@end + +@implementation SymbolLayerZOrderExample + +- (void)viewDidLoad { + [super viewDidLoad]; + + // Create a new map view using the Mapbox Light style. + self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds + styleURL:[MGLStyle lightStyleURL]]; + + self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.mapView.tintColor = [UIColor darkGrayColor]; + + // Set the map’s center coordinate and zoom level. + self.mapView.centerCoordinate = CLLocationCoordinate2DMake(-41.292650,174.778768); + self.mapView.zoomLevel = 11.5; + + self.mapView.delegate = self; + [self.view addSubview: self.mapView]; +} + +// Wait until the style is loaded before modifying the map style. +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { + + // Add icons to the map's style. + // Note that adding icons to the map's style does not mean they have + // been added to the map yet. + [style setImage:([UIImage imageNamed:@"yellow-triangle-image"]) forName:@"yellow-triangle"]; + [style setImage:([UIImage imageNamed:@"green-triangle-image"]) forName:@"green-triangle"]; + [style setImage:([UIImage imageNamed:@"purple-triangle-image"]) forName:@"purple-triangle"]; + + MGLPointFeature *yellow = [MGLPointFeature alloc]; + yellow.coordinate = CLLocationCoordinate2DMake(-41.292650, 174.778768); + yellow.attributes = @{@"id": @"yellow-triangle"}; + + MGLPointFeature *green = [MGLPointFeature alloc]; + green.coordinate = CLLocationCoordinate2DMake(-41.292650, 174.778768); + green.attributes = @{@"id": @"green-triangle"}; + + MGLPointFeature *purple = [MGLPointFeature alloc]; + purple.coordinate = CLLocationCoordinate2DMake(-41.292650, 174.778768); + purple.attributes = @{@"id": @"purple-triangle"}; + + MGLShapeCollectionFeature *shapeCollection = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[yellow, green, purple]]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"symbol-layer-z-order-example" shape:shapeCollection options:nil]; + + [style addSource:source]; + self.layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"points-style" source:source]; + self.layer.sourceLayerIdentifier = @"symbol-layer-z-order-example"; + // Create a stops dictionary with keys that are possible values for 'id', paired with icon images that will represent those features. + NSDictionary *icons = @{ + @"yellow-triangle": @"yellow-triangle", + @"green-triangle": @"green-triangle", + @"purple-triangle": @"purple-triangle"}; + // Use the stops dictionary to assign an icon based on the "POITYPE" for each feature. + self.layer.iconImageName = [NSExpression expressionWithFormat:@"FUNCTION(%@, 'valueForKeyPath:', id)", icons]; + self.layer.iconAllowsOverlap = [NSExpression expressionForConstantValue:@(YES)]; + self.layer.symbolZOrder = [NSExpression expressionForConstantValue:@"source"]; + [style addLayer:self.layer]; + + [self addToggleButton]; +} + +- (void)addToggleButton { + UISegmentedControl *styleToggle =[[UISegmentedControl alloc] initWithItems:@[@"viewport-y", @"source"]]; + styleToggle.translatesAutoresizingMaskIntoConstraints = NO; + styleToggle.backgroundColor = [UIColor colorWithRed:0.83 green:0.84 blue:0.95 alpha:1.0]; + styleToggle.tintColor = [UIColor colorWithRed:0.26 green:0.39 blue:0.98 alpha:1.0]; + styleToggle.layer.cornerRadius = 4; + styleToggle.clipsToBounds = YES; + styleToggle.selectedSegmentIndex = 1; + [self.view insertSubview:styleToggle aboveSubview:self.mapView]; + [styleToggle addTarget:self action:@selector(changeStyle:) forControlEvents:UIControlEventValueChanged]; + + // Configure autolayout constraints for the UISegmentedControl to align + // at the bottom of the map view and above the Mapbox logo and attribution + NSMutableArray *constraints = [NSMutableArray array]; + + [constraints addObject:[NSLayoutConstraint constraintWithItem:styleToggle attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.mapView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:1.0]]; + [constraints addObject:[NSLayoutConstraint constraintWithItem:styleToggle attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mapView.logoView attribute:NSLayoutAttributeTop multiplier:1 constant:-20]]; + + [self.view addConstraints:constraints]; +} + +// Change the map style based on the selected index of the UISegmentedControl +- (void)changeStyle:(UISegmentedControl *)sender { + switch(sender.selectedSegmentIndex){ + case 0: + self.layer.symbolZOrder = [NSExpression expressionForConstantValue:@"viewport-y"]; + break; + case 1: + self.layer.symbolZOrder = [NSExpression expressionForConstantValue:@"source"];; + break; + } +} +@end diff --git a/Examples/Swift/SymbolLayerZOrderExample.swift b/Examples/Swift/SymbolLayerZOrderExample.swift new file mode 100644 index 00000000..bb915393 --- /dev/null +++ b/Examples/Swift/SymbolLayerZOrderExample.swift @@ -0,0 +1,97 @@ +import Foundation +import Mapbox + +@objc(SymbolLayerZOrderExample_Swift) + +class SymbolLayerZOrderExample_Swift: UIViewController, MGLMapViewDelegate { + +var mapView: MGLMapView! +var symbolLayer: MGLSymbolStyleLayer? + +override func viewDidLoad() { + super.viewDidLoad() + // Create a new map view using the Mapbox Light style. + mapView = MGLMapView(frame: view.bounds) + mapView.styleURL = MGLStyle.lightStyleURL + mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + mapView.tintColor = .darkGray + // Set the map’s center coordinate and zoom level. + mapView.setCenter(CLLocationCoordinate2D(latitude: -41.25, longitude: 174.77), animated: false) + mapView.zoomLevel = 11.5 + mapView.delegate = self + view.addSubview(mapView) +} + +// Wait until the style is loaded before modifying the map style. +func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { + // Add icons to the map's style. + // Note that adding icons to the map's style does not mean they have been added to the map yet. + + style.setImage(UIImage(named: "yellow-triangle-image")!, forName: "yellow-triangle") + style.setImage(UIImage(named: "green-triangle-image")!, forName: "green-triangle") + style.setImage(UIImage(named: "purple-triangle-image")!, forName: "purple-triangle") + + let purple = MGLPointFeature() + purple.coordinate = CLLocationCoordinate2DMake(-41.24, 174.77) + purple.attributes = ["id": "purple-triangle"] + + let green = MGLPointFeature() + green.coordinate = CLLocationCoordinate2DMake(-41.25, 174.77) + green.attributes = ["id": "green-triangle"] + + let yellow = MGLPointFeature() + yellow.coordinate = CLLocationCoordinate2DMake(-41.26, 174.77) + yellow.attributes = ["id": "yellow-triangle"] + + let shapeCollection = MGLShapeCollectionFeature(shapes: [yellow, green, purple]) + let source = MGLShapeSource(identifier: "symbol-layer-z-order-example", shape: shapeCollection, options: nil) + style.addSource(source) + let layer = MGLSymbolStyleLayer(identifier: "points-style", source: source) + layer.sourceLayerIdentifier = "symbol-layer-z-order-example" + + // Create a stops dictionary with keys that are possible values for 'id', paired with icon images that will represent those features. + let icons = + ["yellow-triangle": "yellow-triangle", + "green-triangle": "green-triangle", + "purple-triangle": "purple-triangle"] + // Use the stops dictionary to assign an icon based on the "POITYPE" for each feature. + layer.iconImageName = NSExpression(format: "FUNCTION(%@, 'valueForKeyPath:', id)", icons) + + layer.iconAllowsOverlap = NSExpression(forConstantValue: true) + layer.symbolZOrder = NSExpression(forConstantValue: "source") + style.addLayer(layer) + + self.symbolLayer = layer + + addToggleButton() + } + func addToggleButton() { + // Create a UISegmentedControl to toggle between map styles + let styleToggle = UISegmentedControl(items: ["viewport-y", "source"]) + styleToggle.translatesAutoresizingMaskIntoConstraints = false + styleToggle.backgroundColor = UIColor(red: 0.83, green: 0.84, blue: 0.95, alpha: 1.0) + styleToggle.tintColor = UIColor(red: 0.26, green: 0.39, blue: 0.98, alpha: 1.0) + styleToggle.layer.cornerRadius = 4 + styleToggle.clipsToBounds = true + styleToggle.selectedSegmentIndex = 1 + view.insertSubview(styleToggle, aboveSubview: mapView) + styleToggle.addTarget(self, action: #selector(toggleLayer(sender:)), for: .valueChanged) + + // Configure autolayout constraints for the UISegmentedControl to align + // at the bottom of the map view and above the Mapbox logo and attribution + NSLayoutConstraint.activate([NSLayoutConstraint(item: styleToggle, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: mapView, attribute: NSLayoutAttribute.centerX, multiplier: 1.0, constant: 0.0)]) + NSLayoutConstraint.activate([NSLayoutConstraint(item: styleToggle, attribute: .bottom, relatedBy: .equal, toItem: mapView.logoView, attribute: .top, multiplier: 1, constant: -20)]) + } + + // Change the map style based on the selected index of the UISegmentedControl + @objc func toggleLayer(sender: UISegmentedControl) { + switch sender.selectedSegmentIndex { + case 0: + self.symbolLayer?.symbolZOrder = NSExpression(forConstantValue: "viewport-y") + case 1: + self.symbolLayer?.symbolZOrder = NSExpression(forConstantValue: "source") + default: + self.symbolLayer?.symbolZOrder = NSExpression(forConstantValue: "source") + } + } +} diff --git a/Podfile.lock b/Podfile.lock index ac182d18..26ca7205 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -50,4 +50,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: d7f13c38c14f3595d1289272a6b68d0d6486d1f8 -COCOAPODS: 1.6.0.beta.1 +COCOAPODS: 1.5.3