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
[WIP] Add Line Gradient Example #232
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "type": "FeatureCollection", | ||
| "features": [{ | ||
| "type": "Feature", | ||
| "properties": {"lineMetrics": true}, | ||
| "geometry": { | ||
| "coordinates": [ | ||
| [-77.044211, 38.852924 ], | ||
| [-77.045659, 38.860158 ], | ||
| [-77.044232, 38.862326 ], | ||
| [-77.040879, 38.865454 ], | ||
| [-77.039936, 38.867698 ], | ||
| [-77.040338, 38.86943 ], | ||
| [-77.04264, 38.872528 ], | ||
| [-77.03696, 38.878424 ], | ||
| [-77.032309, 38.87937 ], | ||
| [-77.030056, 38.880945 ], | ||
| [-77.027645, 38.881779 ], | ||
| [-77.026946, 38.882645 ], | ||
| [-77.026942, 38.885502 ], | ||
| [-77.028054, 38.887449 ], | ||
| [-77.02806, 38.892088 ], | ||
| [-77.03364, 38.892108 ], | ||
| [-77.033643, 38.899926 ] | ||
| ], | ||
| "type": "LineString" | ||
| } | ||
| }] | ||
| } |
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,9 @@ | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface LineGradientExample : 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,58 @@ | ||
| #import "LineGradientExample.h" | ||
| @import Mapbox; | ||
|
|
||
| NSString *const MBXExampleLineGradient = @"LineGradientExample"; | ||
|
|
||
| @interface LineGradientExample ()<MGLMapViewDelegate> | ||
|
|
||
| @end | ||
|
|
||
| @implementation LineGradientExample | ||
|
|
||
| - (void)viewDidLoad { | ||
| [super viewDidLoad]; | ||
| MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle lightStyleURL]]; | ||
|
|
||
| mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | ||
|
|
||
| mapView.delegate = self; | ||
|
|
||
| // Set the map’s center coordinate and zoom level. | ||
| [mapView setCenterCoordinate:CLLocationCoordinate2DMake(38.875, -77.035) | ||
| zoomLevel:12 | ||
| animated:NO]; | ||
|
|
||
| [self.view addSubview:mapView]; | ||
| } | ||
|
|
||
| - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { | ||
|
|
||
| NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"line-gradient" ofType:@"geojson"]]; | ||
| MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"line-source" URL:url options:nil]; | ||
|
|
||
|
|
||
| [style addSource:source]; | ||
|
|
||
| MGLLineStyleLayer *polylineStyle = [[MGLLineStyleLayer alloc] initWithIdentifier:@"lineStyle" source:source]; | ||
| polylineStyle.lineWidth = [NSExpression expressionForConstantValue:@14]; | ||
| polylineStyle.lineCap = [NSExpression expressionForConstantValue:@"round"]; | ||
|
|
||
| NSDictionary *stops = @{ | ||
| @0: UIColor.blueColor, | ||
| @0.1: UIColor.purpleColor, | ||
| @0.3: UIColor.cyanColor, | ||
| @0.5: UIColor.greenColor, | ||
| @0.7: UIColor.yellowColor, | ||
| @1: UIColor.redColor | ||
| }; | ||
|
|
||
| NSExpression *gradientExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($lineProgress, 'linear', nil, %@)", stops]; | ||
|
Contributor
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. Noting that we might be seeing this crash in its current state because of mapbox/mapbox-gl-native#12917.
Contributor
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. We can try using
Contributor
Author
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. I'm getting the following error when trying to implement that workaround @captainbarbosa: Am I doing something wrong here: |
||
|
|
||
| polylineStyle.lineColor = gradientExpression; | ||
|
|
||
| [style addLayer:polylineStyle]; | ||
|
|
||
| } | ||
|
|
||
| @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,14 @@ | ||
| import UIKit | ||
| import Mapbox | ||
|
|
||
| @objc(LineGradientExample_Swift) | ||
|
|
||
| class LineGradientExample: UIViewController { | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
|
|
||
| // Do any additional setup after loading the view. | ||
| } | ||
|
|
||
| } |
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.
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.
Note that the clarification that will happen in mapbox/mapbox-gl-native#13000 should allow you to switch back to using an
MGLPolylinelike you did in 100c88d.