Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit 4581461

Browse files
authored
created a new branch due to merge conflicts. (#423)
1 parent 298e050 commit 4581461

File tree

8 files changed

+189
-13
lines changed

8 files changed

+189
-13
lines changed

Examples.xcodeproj/project.pbxproj

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
580F709E252D11AF000512BE /* ManageOfflineRegionsExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 580F709D252D11AF000512BE /* ManageOfflineRegionsExample.m */; };
8888
583BAE082481AFF50079BB57 /* InsetMapExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 583BAE072481AFF50079BB57 /* InsetMapExample.m */; };
8989
583BAE0B2481B1580079BB57 /* InsetMapExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583BAE0A2481B1580079BB57 /* InsetMapExample.swift */; };
90+
58D43A9B25B9C9D600A29650 /* LineGradientExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D43A9A25B9C9D600A29650 /* LineGradientExample.swift */; };
91+
58D43AA525B9CA1500A29650 /* LineGradientExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 58D43AA425B9CA1500A29650 /* LineGradientExample.m */; };
92+
58D43ACD25B9CE1A00A29650 /* iOSLineGeoJSON.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 58D43AAA25B9CA6200A29650 /* iOSLineGeoJSON.geojson */; };
9093
646B62971DEF6DAF000AA523 /* ShowHideLayerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646B62961DEF6DAF000AA523 /* ShowHideLayerExample.swift */; };
9194
646B629C1DEF6DF1000AA523 /* ShowHideLayerExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 646B629B1DEF6DF1000AA523 /* ShowHideLayerExample.m */; };
9295
646B62A61DEF7121000AA523 /* AnimatedLineExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 646B62A51DEF7121000AA523 /* AnimatedLineExample.m */; };
@@ -288,6 +291,10 @@
288291
583BAE072481AFF50079BB57 /* InsetMapExample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InsetMapExample.m; sourceTree = "<group>"; };
289292
583BAE092481B0220079BB57 /* InsetMapExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InsetMapExample.h; sourceTree = "<group>"; };
290293
583BAE0A2481B1580079BB57 /* InsetMapExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsetMapExample.swift; sourceTree = "<group>"; };
294+
58D43A9925B9C93800A29650 /* LineGradientExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LineGradientExample.h; sourceTree = "<group>"; };
295+
58D43A9A25B9C9D600A29650 /* LineGradientExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineGradientExample.swift; sourceTree = "<group>"; };
296+
58D43AA425B9CA1500A29650 /* LineGradientExample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LineGradientExample.m; sourceTree = "<group>"; };
297+
58D43AAA25B9CA6200A29650 /* iOSLineGeoJSON.geojson */ = {isa = PBXFileReference; lastKnownFileType = text; path = iOSLineGeoJSON.geojson; sourceTree = "<group>"; };
291298
646B62961DEF6DAF000AA523 /* ShowHideLayerExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowHideLayerExample.swift; sourceTree = "<group>"; };
292299
646B629B1DEF6DF1000AA523 /* ShowHideLayerExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowHideLayerExample.m; sourceTree = "<group>"; };
293300
646B629E1DEF6DFD000AA523 /* ShowHideLayerExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShowHideLayerExample.h; sourceTree = "<group>"; };
@@ -480,6 +487,7 @@
480487
646B62AF1DEF7161000AA523 /* AnimatedLineExample.swift */,
481488
646B62AD1DEF7155000AA523 /* LineStyleLayerExample.swift */,
482489
055ABCC21EFB14AE0063BACA /* PolygonPatternExample.swift */,
490+
58D43A9A25B9C9D600A29650 /* LineGradientExample.swift */,
483491
);
484492
name = "Lines and polygons";
485493
sourceTree = "<group>";
@@ -579,6 +587,7 @@
579587
646B62A51DEF7121000AA523 /* AnimatedLineExample.m */,
580588
05FA539F1FE2FA1E001F3D7D /* LineStyleLayerExample.m */,
581589
05FA539D1FE2FA1D001F3D7D /* PolygonPatternExample.m */,
590+
58D43AA425B9CA1500A29650 /* LineGradientExample.m */,
582591
);
583592
name = "Lines and polygons";
584593
sourceTree = "<group>";
@@ -812,6 +821,7 @@
812821
1F07016422557B0B0045E061 /* icons.xcassets */,
813822
1F07015622530BDF0045E061 /* text-format.json */,
814823
075AFB7723393DBA0091FF0A /* example.geojson */,
824+
58D43AAA25B9CA6200A29650 /* iOSLineGeoJSON.geojson */,
815825
);
816826
path = Files;
817827
sourceTree = "<group>";
@@ -864,6 +874,7 @@
864874
583BAE092481B0220079BB57 /* InsetMapExample.h */,
865875
C67C17E12507FC0C004112DE /* LocationPrivacyExample.h */,
866876
580F7089252D10F0000512BE /* ManageOfflineRegionsExample.h */,
877+
58D43A9925B9C93800A29650 /* LineGradientExample.h */,
867878
);
868879
path = Headers;
869880
sourceTree = "<group>";
@@ -1113,6 +1124,7 @@
11131124
DD5939E61E6778480009BEB2 /* clustering.xcassets in Resources */,
11141125
9619629C1C581700002D3DAB /* Assets.xcassets in Resources */,
11151126
1F07016522557B0B0045E061 /* icons.xcassets in Resources */,
1127+
58D43ACD25B9CE1A00A29650 /* iOSLineGeoJSON.geojson in Resources */,
11161128
075AFB7823393DBA0091FF0A /* example.geojson in Resources */,
11171129
64BBDAF01DF22D9600BB705D /* third_party_vector_style.json in Resources */,
11181130
961962CF1C581FBC002D3DAB /* Main.storyboard in Resources */,
@@ -1218,17 +1230,11 @@
12181230
inputPaths = (
12191231
"${PODS_ROOT}/Target Support Files/Pods-Examples/Pods-Examples-frameworks.sh",
12201232
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
1221-
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
1222-
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/8F3E82C3-52DF-39E5-809D-3389B6CBCAD4.bcsymbolmap",
1223-
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/0DC8DAD8-C6D7-343B-ACBF-79B48068D7CC.bcsymbolmap",
12241233
"${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework",
12251234
);
12261235
name = "[CP] Embed Pods Frameworks";
12271236
outputPaths = (
12281237
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
1229-
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
1230-
"${BUILT_PRODUCTS_DIR}/8F3E82C3-52DF-39E5-809D-3389B6CBCAD4.bcsymbolmap",
1231-
"${BUILT_PRODUCTS_DIR}/0DC8DAD8-C6D7-343B-ACBF-79B48068D7CC.bcsymbolmap",
12321238
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
12331239
);
12341240
runOnlyForDeploymentPostprocessing = 0;
@@ -1259,17 +1265,11 @@
12591265
inputPaths = (
12601266
"${PODS_ROOT}/Target Support Files/Pods-DocsCode/Pods-DocsCode-frameworks.sh",
12611267
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
1262-
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
1263-
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/8F3E82C3-52DF-39E5-809D-3389B6CBCAD4.bcsymbolmap",
1264-
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/0DC8DAD8-C6D7-343B-ACBF-79B48068D7CC.bcsymbolmap",
12651268
"${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework",
12661269
);
12671270
name = "[CP] Embed Pods Frameworks";
12681271
outputPaths = (
12691272
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
1270-
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
1271-
"${BUILT_PRODUCTS_DIR}/8F3E82C3-52DF-39E5-809D-3389B6CBCAD4.bcsymbolmap",
1272-
"${BUILT_PRODUCTS_DIR}/0DC8DAD8-C6D7-343B-ACBF-79B48068D7CC.bcsymbolmap",
12731273
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
12741274
);
12751275
runOnlyForDeploymentPostprocessing = 0;
@@ -1429,10 +1429,12 @@
14291429
DDF943291E5DE63300545D0F /* ClusteringExample.m in Sources */,
14301430
3E44BA58203B54260072DE4B /* MultipleImagesExample.m in Sources */,
14311431
3EBCD7171DC28240001E342F /* DefaultCalloutExample.swift in Sources */,
1432+
58D43A9B25B9C9D600A29650 /* LineGradientExample.swift in Sources */,
14321433
64BBDAFD1DF24DEB00BB705D /* WebAPIDataExample.m in Sources */,
14331434
055ABCC31EFB14AE0063BACA /* PolygonPatternExample.swift in Sources */,
14341435
583BAE0B2481B1580079BB57 /* InsetMapExample.swift in Sources */,
14351436
646B62AE1DEF7155000AA523 /* LineStyleLayerExample.swift in Sources */,
1437+
58D43AA525B9CA1500A29650 /* LineGradientExample.m in Sources */,
14361438
3EBCD71F1DC28240001E342F /* DefaultStylesExample.swift in Sources */,
14371439
DD5939E41E6639BA0009BEB2 /* ClusteringExample.swift in Sources */,
14381440
3E22EF4F1F87F10C00605203 /* ImageSourceExample.swift in Sources */,

Examples/Examples.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern NSString *const MBXExampleDefaultStyles;
3333
extern NSString *const MBXExampleDraggableAnnotationView;
3434
extern NSString *const MBXExampleFeatureSelection;
3535
extern NSString *const MBXExampleFormattingExpression;
36+
extern NSString *const MBXExampleLineGradient;
3637
extern NSString *const MBXExampleHeatmap;
3738
extern NSString *const MBXExampleImageSource;
3839
extern NSString *const MBXExampleInsetMap;

Examples/Examples.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ + (NSArray *)groups {
4949
@{@"className": MBXExamplePolygonPattern, @"title": @"Add a pattern to a polygon"},
5050
@{@"className": MBXExampleLineStyleLayer, @"title": @"Add a line style layer from GeoJSON"},
5151
@{@"className": MBXExampleAnimatedLine, @"title": @"Animate a line"},
52+
@{@"className": MBXExampleLineGradient, @"title": @"Create a line with a color-changing gradient"},
5253
]
5354
},
5455
@{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [{
4+
"type": "Feature",
5+
"properties": {"lineMetrics": true},
6+
"geometry": {
7+
"coordinates": [
8+
[-77.044211, 38.852924],
9+
[-77.045659, 38.860158],
10+
[-77.044232, 38.862326],
11+
[-77.040879, 38.865454],
12+
[-77.039936, 38.867698],
13+
[-77.040338, 38.86943],
14+
[-77.04264, 38.872528],
15+
[-77.03696, 38.878424],
16+
[-77.032309, 38.87937],
17+
[-77.030056, 38.880945],
18+
[-77.027645, 38.881779],
19+
[-77.026946, 38.882645],
20+
[-77.026942, 38.885502],
21+
[-77.028054, 38.887449],
22+
[-77.02806, 38.892088],
23+
[-77.03364, 38.892108],
24+
[-77.033643, 38.899926]
25+
],
26+
"type": "LineString"
27+
}
28+
}]
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface LineGradientExample : UIViewController
4+
5+
@end
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#import "LineGradientExample.h"
2+
@import Mapbox;
3+
@interface LineGradientExample () <MGLMapViewDelegate>
4+
@property (nonatomic) MGLMapView *mapView;
5+
@end
6+
7+
NSString *const MBXExampleLineGradient = @"LineGradientExample";
8+
9+
@implementation LineGradientExample
10+
11+
- (void)viewDidLoad {
12+
[super viewDidLoad];
13+
14+
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle lightStyleURL]];
15+
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
16+
17+
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(38.875, -77.035)
18+
zoomLevel:12
19+
animated:NO];
20+
21+
22+
[self.view addSubview:self.mapView];
23+
24+
self.mapView.delegate = self;
25+
}
26+
27+
// Wait until the map is loaded before adding line layer to the map.
28+
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
29+
[self loadGeoJSON];
30+
}
31+
32+
- (void)loadGeoJSON {
33+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
34+
NSString *path = [[NSBundle mainBundle] pathForResource:@"iOSLineGeoJSON" ofType:@"geojson"];
35+
NSData *jsonData = [NSData dataWithContentsOfFile:path];
36+
dispatch_async(dispatch_get_main_queue(), ^{
37+
[self drawPolyline:jsonData];
38+
});
39+
});
40+
}
41+
42+
- (void)drawPolyline:(NSData *)geoJson {
43+
// Add our GeoJSON data to the map as an MGLShapeSource.
44+
// We can then reference this data from an MGLStyleLayer.
45+
MGLShape *shape = [MGLShape shapeWithData:geoJson encoding:NSUTF8StringEncoding error:nil];
46+
MGLSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"polyline" shape:shape options: @{MGLShapeSourceOptionLineDistanceMetrics:@YES}];
47+
[self.mapView.style addSource:source];
48+
49+
// Create new layer for the line.
50+
MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"polyline" source:source];
51+
52+
// Set the line join and cap to a rounded end.
53+
layer.lineJoin = [NSExpression expressionForConstantValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]];
54+
layer.lineCap = [NSExpression expressionForConstantValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]];
55+
56+
NSDictionary *stops = @{
57+
@0: UIColor.blueColor,
58+
@0.1: UIColor.purpleColor,
59+
@0.3: UIColor.cyanColor,
60+
@0.5: UIColor.greenColor,
61+
@0.7: UIColor.yellowColor,
62+
@1: UIColor.redColor
63+
};
64+
65+
66+
// Set the line color to a gradient
67+
layer.lineGradient = [NSExpression expressionWithFormat: @"mgl_interpolate:withCurveType:parameters:stops:($lineProgress, 'linear', nil, %@)", stops];
68+
69+
// Use `NSExpression` to allow the appearance of your gradient to change and become more detailed with the map’s zoom level
70+
layer.lineWidth = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)",
71+
@{@14: @10, @18: @20}];
72+
[self.mapView.style addLayer:layer];
73+
74+
}
75+
@end
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import UIKit
2+
import Mapbox
3+
@objc(LineGradientExample_Swift)
4+
5+
class LineGradientExample_Swift: UIViewController, MGLMapViewDelegate {
6+
7+
var mapView: MGLMapView!
8+
9+
override func viewDidLoad() {
10+
super.viewDidLoad()
11+
// Do any additional setup after loading the view.
12+
mapView = MGLMapView(frame: view.bounds)
13+
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
14+
mapView.styleURL = MGLStyle.lightStyleURL
15+
mapView.delegate = self
16+
view.addSubview(mapView)
17+
mapView.setCenter(CLLocationCoordinate2D(latitude: 38.875, longitude: -77.035), zoomLevel: 12, animated: false)
18+
}
19+
20+
func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
21+
drawPolyline()
22+
}
23+
24+
func drawPolyline() {
25+
// Since we know this file exists within this project, we'll force unwrap its value.
26+
// If this data was coming from an external server, we would want to perform
27+
// proper error handling for a web request/response.
28+
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "iOSLineGeoJSON", ofType: "geojson")!)
29+
guard let jsonData = try? Data(contentsOf: url) else {
30+
preconditionFailure("Failed to parse GeoJSON file")
31+
}
32+
// Add our GeoJSON data to the map as an MGLShapeSource.
33+
// We can then reference this data from an MGLStyleLayer.
34+
// MGLMapView.style is optional, so you must guard against it not being set.
35+
guard let style = self.mapView.style else { return }
36+
guard let shapeFromGeoJSON = try? MGLShape(data: jsonData, encoding: String.Encoding.utf8.rawValue) else {
37+
fatalError("Could not generate MGLShape")
38+
}
39+
let source = MGLShapeSource(identifier: "polyline", shape: shapeFromGeoJSON, options: [MGLShapeSourceOption.lineDistanceMetrics: true])
40+
style.addSource(source)
41+
// Create a new style layer for the line which will determine the line's styling properties.
42+
let layer = MGLLineStyleLayer(identifier: "polyline", source: source)
43+
// Set the line join and cap to a rounded end.
44+
layer.lineJoin = NSExpression(forConstantValue: "round")
45+
layer.lineCap = NSExpression(forConstantValue: "round")
46+
47+
let stops = [0: UIColor.blue,
48+
0.1: UIColor.purple,
49+
0.3: UIColor.cyan,
50+
0.5: UIColor.green,
51+
0.7: UIColor.yellow,
52+
1: UIColor.red]
53+
54+
// Set the line color to a gradient
55+
layer.lineGradient = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($lineProgress, 'linear', nil, %@)", stops)
56+
57+
// Use `NSExpression` to allow the appearance of your gradient to change and become more detailed with the map’s zoom level
58+
layer.lineWidth = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)",
59+
[14: 10, 18: 20])
60+
61+
style.addLayer(layer)
62+
}
63+
}

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ SPEC CHECKSUMS:
2121

2222
PODFILE CHECKSUM: 3fb0eea64d7fe606fd4edb9f5b121e174bebc01a
2323

24-
COCOAPODS: 1.9.3
24+
COCOAPODS: 1.10.0

0 commit comments

Comments
 (0)