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

adding a new example FilterMapSymbolsExample #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
3EC92DB71E78C431001D0503 /* metro-line.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 3EC92DB61E78C431001D0503 /* metro-line.geojson */; };
3ED403411E006B5200230C95 /* CameraFlyToExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ED403401E006B5200230C95 /* CameraFlyToExample.swift */; };
3ED403481E006BE800230C95 /* CameraFlyToExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3ED403471E006BE800230C95 /* CameraFlyToExample.m */; };
58AC6B9C23478646002665E1 /* mapbox_access_token in Resources */ = {isa = PBXBuildFile; fileRef = 58AC6B9B23478646002665E1 /* mapbox_access_token */; };
58AC6B9E23478BA6002665E1 /* FilterMapSymbolsExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 58AC6B9D23478BA6002665E1 /* FilterMapSymbolsExample.m */; };
58AC6BA023478D81002665E1 /* FilterMapSymbolsExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58AC6B9F23478D81002665E1 /* FilterMapSymbolsExample.swift */; };
58AC6BE82347D47B002665E1 /* iOS.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 58AC6BE72347D47B002665E1 /* iOS.geojson */; };
60E0DCA0CEED683C3A4F18F2 /* Pods_Examples.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9EC12D8F1A97963D68BFA871 /* Pods_Examples.framework */; };
646B62971DEF6DAF000AA523 /* ShowHideLayerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646B62961DEF6DAF000AA523 /* ShowHideLayerExample.swift */; };
646B629C1DEF6DF1000AA523 /* ShowHideLayerExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 646B629B1DEF6DF1000AA523 /* ShowHideLayerExample.m */; };
Expand Down Expand Up @@ -270,6 +274,11 @@
3ED403471E006BE800230C95 /* CameraFlyToExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CameraFlyToExample.m; sourceTree = "<group>"; };
532FB53EE0142E4DAC3FB49B /* Pods-Shared-Examples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Shared-Examples.release.xcconfig"; path = "Pods/Target Support Files/Pods-Shared-Examples/Pods-Shared-Examples.release.xcconfig"; sourceTree = "<group>"; };
589ABF8859560819F8B431C7 /* Pods-ExamplesTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExamplesTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExamplesTests/Pods-ExamplesTests.debug.xcconfig"; sourceTree = "<group>"; };
58AC6B9B23478646002665E1 /* mapbox_access_token */ = {isa = PBXFileReference; lastKnownFileType = text; path = mapbox_access_token; sourceTree = "<group>"; };
58AC6B9D23478BA6002665E1 /* FilterMapSymbolsExample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FilterMapSymbolsExample.m; sourceTree = "<group>"; };
58AC6B9F23478D81002665E1 /* FilterMapSymbolsExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterMapSymbolsExample.swift; sourceTree = "<group>"; };
58AC6BE62347D38A002665E1 /* FilterMapSymbols.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FilterMapSymbols.h; sourceTree = "<group>"; };
58AC6BE72347D47B002665E1 /* iOS.geojson */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iOS.geojson; sourceTree = "<group>"; };
646B62961DEF6DAF000AA523 /* ShowHideLayerExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowHideLayerExample.swift; sourceTree = "<group>"; };
646B629B1DEF6DF1000AA523 /* ShowHideLayerExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowHideLayerExample.m; sourceTree = "<group>"; };
646B629E1DEF6DFD000AA523 /* ShowHideLayerExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShowHideLayerExample.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -315,7 +324,6 @@
962B450D1D1C8520007B7454 /* AnnotationViewExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnnotationViewExample.h; sourceTree = "<group>"; };
962B450E1D1C8520007B7454 /* AnnotationViewExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnnotationViewExample.m; sourceTree = "<group>"; };
9637341B2139B30A00BE4B39 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = SOURCE_ROOT; };
964CB5171E445AE1004549EA /* mapbox_access_token */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mapbox_access_token; sourceTree = SOURCE_ROOT; };
968247011C5BDCBB00494AB8 /* StudioClassicStyleExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StudioClassicStyleExample.h; sourceTree = "<group>"; };
968247111C5C0F0F00494AB8 /* DefaultCalloutExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DefaultCalloutExample.h; sourceTree = "<group>"; };
968247251C5C1DC700494AB8 /* CameraAnimationExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CameraAnimationExample.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -492,6 +500,7 @@
3EBCD7121DC28240001E342F /* PointConversionExample.swift */,
646B62961DEF6DAF000AA523 /* ShowHideLayerExample.swift */,
3EBCD7151DC28240001E342F /* UserTrackingModesExample.swift */,
58AC6B9F23478D81002665E1 /* FilterMapSymbolsExample.swift */,
);
name = "User interaction";
sourceTree = "<group>";
Expand Down Expand Up @@ -586,6 +595,7 @@
96BAED2D1FE304DD00A58BEB /* PointConversionExample.m */,
646B629B1DEF6DF1000AA523 /* ShowHideLayerExample.m */,
969E7FDC1D25C31700663F84 /* UserTrackingModesExample.m */,
58AC6B9D23478BA6002665E1 /* FilterMapSymbolsExample.m */,
);
name = "User interaction";
sourceTree = "<group>";
Expand Down Expand Up @@ -676,6 +686,7 @@
961962831C581700002D3DAB = {
isa = PBXGroup;
children = (
58AC6B9B23478646002665E1 /* mapbox_access_token */,
9619628E1C581700002D3DAB /* Examples */,
961962A81C581700002D3DAB /* ExamplesTests */,
961962B31C581700002D3DAB /* ExamplesUITests */,
Expand Down Expand Up @@ -727,7 +738,6 @@
9637341B2139B30A00BE4B39 /* .swiftlint.yml */,
9691AAAA1C5AB546006A58C6 /* Examples-Bridging-Header.h */,
961962901C581700002D3DAB /* main.m */,
964CB5171E445AE1004549EA /* mapbox_access_token */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand All @@ -753,6 +763,7 @@
9682471B1C5C123B00494AB8 /* Files */ = {
isa = PBXGroup;
children = (
58AC6BE72347D47B002665E1 /* iOS.geojson */,
DD5939E51E6778480009BEB2 /* clustering.xcassets */,
3EC92DB61E78C431001D0503 /* metro-line.geojson */,
3E25C5DE2056E7E2005B031E /* nps-icons.xcassets */,
Expand Down Expand Up @@ -810,6 +821,7 @@
3E18060E1EAA800A004DB131 /* UserLocationAnnotationExample.h */,
969E7FDB1D25C31700663F84 /* UserTrackingModesExample.h */,
64BBDAFB1DF24DD700BB705D /* WebAPIDataExample.h */,
58AC6BE62347D38A002665E1 /* FilterMapSymbols.h */,
);
path = Headers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1080,13 +1092,15 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
58AC6BE82347D47B002665E1 /* iOS.geojson in Resources */,
3E25C5DF2056E7E2005B031E /* nps-icons.xcassets in Resources */,
3E4574ED1FA3D8F1000C8CF1 /* radar.gif in Resources */,
1F0701632255789D0045E061 /* missing_icon.json in Resources */,
DDF9432B1E5DEACC00545D0F /* ports.geojson in Resources */,
3EC92DB71E78C431001D0503 /* metro-line.geojson in Resources */,
9619629F1C581700002D3DAB /* LaunchScreen.storyboard in Resources */,
DD5939E61E6778480009BEB2 /* clustering.xcassets in Resources */,
58AC6B9C23478646002665E1 /* mapbox_access_token in Resources */,
9619629C1C581700002D3DAB /* Assets.xcassets in Resources */,
1F07016522557B0B0045E061 /* icons.xcassets in Resources */,
075AFB7823393DBA0091FF0A /* example.geojson in Resources */,
Expand Down Expand Up @@ -1357,6 +1371,7 @@
3E52ACD31EE8D8AF0056242C /* LiveDataExample.m in Sources */,
3EA5AA041FAD2EC7007073C0 /* StaticSnapshotExample.swift in Sources */,
05FA53A91FE2FB46001F3D7D /* CustomCalloutView.m in Sources */,
58AC6BA023478D81002665E1 /* FilterMapSymbolsExample.swift in Sources */,
05FA53A31FE2FA1E001F3D7D /* LineStyleLayerExample.m in Sources */,
3E44BA55203B54120072DE4B /* MultipleImagesExample.swift in Sources */,
3E1806101EAA800A004DB131 /* UserLocationAnnotationExample.m in Sources */,
Expand Down Expand Up @@ -1384,6 +1399,7 @@
DDF943291E5DE63300545D0F /* ClusteringExample.m in Sources */,
3E44BA58203B54260072DE4B /* MultipleImagesExample.m in Sources */,
3EBCD7171DC28240001E342F /* DefaultCalloutExample.swift in Sources */,
58AC6B9E23478BA6002665E1 /* FilterMapSymbolsExample.m in Sources */,
64BBDAFD1DF24DEB00BB705D /* WebAPIDataExample.m in Sources */,
055ABCC31EFB14AE0063BACA /* PolygonPatternExample.swift in Sources */,
646B62AE1DEF7155000AA523 /* LineStyleLayerExample.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Examples/Examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern NSString *const MBXExampleDefaultCallout;
extern NSString *const MBXExampleDefaultStyles;
extern NSString *const MBXExampleDraggableAnnotationView;
extern NSString *const MBXExampleFeatureSelection;
extern NSString *const MBXExampleFilterMapSymbols;
extern NSString *const MBXExampleFormattingExpression;
extern NSString *const MBXExampleHeatmap;
extern NSString *const MBXExampleImageSource;
Expand Down
1 change: 1 addition & 0 deletions Examples/Examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ + (NSArray *)groups {
@{@"className": MBXExampleShowHideLayer, @"title": @"Show and hide a layer"},
@{@"className": MBXExampleFeatureSelection, @"title": @"Select a feature within a layer"},
@{@"className": MBXExampleUserTrackingModes, @"title": @"Switch between user tracking modes"},
@{@"className": MBXExampleFilterMapSymbols, @"title": @"Filter locations marked by symbols on a map"},
]
},
@{
Expand Down
67 changes: 67 additions & 0 deletions Examples/Files/iOS.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"icon": "theatre"
},
"geometry": {
"type": "Point",
"coordinates": [-77.038659, 38.931567]
}
}, {
"type": "Feature",
"properties": {
"icon": "theatre"
},
"geometry": {
"type": "Point",
"coordinates": [-77.003168, 38.894651]
}
}, {
"type": "Feature",
"properties": {
"icon": "bar"
},
"geometry": {
"type": "Point",
"coordinates": [-77.090372, 38.881189]
}
}, {
"type": "Feature",
"properties": {
"icon": "bicycle"
},
"geometry": {
"type": "Point",
"coordinates": [-77.052477, 38.943951]
}
}, {
"type": "Feature",
"properties": {
"icon": "music"
},
"geometry": {
"type": "Point",
"coordinates": [-77.031706, 38.914581]
}
}, {
"type": "Feature",
"properties": {
"icon": "music"
},
"geometry": {
"type": "Point",
"coordinates": [-77.020945, 38.878241]
}
}, {
"type": "Feature",
"properties": {
"icon": "music"
},
"geometry": {
"type": "Point",
"coordinates": [-77.007481, 38.876516]
}
}]
}
112 changes: 112 additions & 0 deletions Examples/ObjectiveC/FilterMapSymbolsExample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

#import "FilterMapSymbols.h"

NSString *const MBXExampleFilterMapSymbols = @"FilterMapSymbolsExample";

@import Mapbox;
@interface FilterMapSymbolsExample () <MGLMapViewDelegate>

@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) MGLSymbolStyleLayer *symbolLayer;
@property (nonatomic) MGLStyle *style;


@end


@implementation FilterMapSymbolsExample

- (void)viewDidLoad {
[super viewDidLoad];

self.mapView = [[MGLMapView alloc] initWithFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

// Set the map's initial style, center coordinate, and zoom level
self.mapView.styleURL = [NSURL URLWithString:@"mapbox://styles/zizim/ck12h05if04ha1co4qr1ra9l2"];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(38.897435, -77.039679)
zoomLevel:11
animated:NO];
_mapView.delegate = self;
[self.view addSubview:self.mapView];

[self toggleSet];

}

-(void)toggleSet {
// Create a UISegmentedControl to toggle between map styles
UISegmentedControl *styleToggle =[[UISegmentedControl alloc] initWithItems:@[@"theatre", @"bar", @"music", @"biking"]];
styleToggle.translatesAutoresizingMaskIntoConstraints = NO;
styleToggle.tintColor = [UIColor colorWithRed:0.976 green:0.843 blue:0.831 alpha:1];
styleToggle.backgroundColor = [UIColor colorWithRed:0.09 green:0.568 blue:0.514 alpha:0.56];
styleToggle.layer.cornerRadius = 4;
styleToggle.clipsToBounds = YES;
[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];
}


- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iOS" ofType:@"geojson"]];


MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"icons" URL:url options:@{}];
[style addSource:source];

self.symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"icons" source:source];

// Create a stops dictionary with keys that are possible values for 'POITYPE', paired with icon images that will represent those features.
NSDictionary *stops = @{
@"theatre": [NSExpression expressionForConstantValue:@"theatre-15"],
@"bar": [NSExpression expressionForConstantValue:@"alcohol-shop-15"],
@"music": [NSExpression expressionForConstantValue:@"music-15"],
@"bicycle":[NSExpression expressionForConstantValue:@"bicycle-15"]
};

// Use the stops dictionary to assign an icon based on the "icon" for each feature.
self.symbolLayer.iconImageName = [NSExpression expressionWithFormat:@"FUNCTION(%@, 'valueForKeyPath:', icon)", stops];

NSLog(@"%@", stops);


[style addLayer:_symbolLayer];
}

// Change the map style based on the selected index of the UISegmentedControl
- (void)changeStyle:(UISegmentedControl *)sender {
switch(sender.selectedSegmentIndex){
case 0:
NSLog(@"%@", @"ummm");

self.symbolLayer.iconImageName = [NSExpression expressionForConstantValue:@"theatre-15"];
self.symbolLayer.predicate = [NSPredicate predicateWithFormat:@"icon = 'theatre'"];

break;
case 1:
_symbolLayer.iconImageName =[NSExpression expressionForConstantValue:@"alcohol-shop-15"];
_symbolLayer.predicate = [NSPredicate predicateWithFormat:@"icon = 'bar'"];
break;
case 2:
_symbolLayer.iconImageName = [NSExpression expressionForConstantValue:@"music-15"];
_symbolLayer.predicate =[NSPredicate predicateWithFormat:@"icon = 'music'"];
break;
case 3:
_symbolLayer.iconImageName = [NSExpression expressionForConstantValue:@"bicycle-15"];
_symbolLayer.predicate =[NSPredicate predicateWithFormat:@"icon = 'bicycle'"];
break;
}
}


@end
14 changes: 14 additions & 0 deletions Examples/ObjectiveC/Headers/FilterMapSymbols.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FilterMapSymbols.h
// Examples
//
// Created by ZiZi Miles on 10/4/19.
// Copyright © 2019 Mapbox. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FilterMapSymbolsExample : UIViewController


@end
Loading