This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
symbolZOrder example #245
Open
samfader
wants to merge
11
commits into
master
Choose a base branch
from
symbolzorder-example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
symbolZOrder example #245
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f3345c
first draft
6d89cb1
add toggle to switch between z order type
33c2d87
update draft of ObjC example
51765c3
finished examples
eff2d81
Fix PBX file / add missing brace / silence SwiftLint
captainbarbosa d42f683
remove comments
e5d49bf
Merge branch 'symbolzorder-example' of github.com:mapbox/ios-sdk-exam…
af118bf
more fixes
197d90a
New images
captainbarbosa 1ae6472
Updates
captainbarbosa e1483d9
Replace yellow triangle image (PDF -> PNG)
captainbarbosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
Examples/Files/symbol-z-order.xcassets/green-triangle-image.imageset/Contents.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
Binary file added
BIN
+3.13 KB
.../Files/symbol-z-order.xcassets/green-triangle-image.imageset/green-triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
Examples/Files/symbol-z-order.xcassets/purple-triangle-image.imageset/Contents.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
Binary file added
BIN
+2.58 KB
...iles/symbol-z-order.xcassets/purple-triangle-image.imageset/purple-triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
Examples/Files/symbol-z-order.xcassets/yellow-triangle-image.imageset/Contents.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
Binary file added
BIN
+1.77 KB
...ymbol-z-order.xcassets/yellow-triangle-image.imageset/yellow-triangle-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #import <Foundation/Foundation.h> | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface SymbolLayerZOrderExample : UIViewController | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #import "SymbolLayerZOrderExample.h" | ||
| @import Mapbox; | ||
|
|
||
| NSString *const MBXExampleSymbolLayerZOrder = @"SymbolLayerZOrderExample"; | ||
|
|
||
| @interface SymbolLayerZOrderExample () <MGLMapViewDelegate> | ||
|
|
||
| @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]; | ||
samfader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.