Created
November 4, 2015 03:04
-
-
Save overcyn/5108c31efc93f89f455f to your computer and use it in GitHub Desktop.
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
| @interface MSHidesConferenceRoomsViewController : UIViewController <MRMapViewDelegate> | |
| @property (nonatomic, strong) MRMapView *mapView; | |
| @property (nonatomic, assign) BOOL conferenceHidden; | |
| @property (nonatomic, strong) NSArray *placemarks; | |
| @end | |
| @implementation MSHidesConferenceRoomsViewController | |
| - (id)initWithNibName:(NSString *)name bundle:(NSBundle *)bundle { | |
| if ((self = [super initWithNibName:name bundle:bundle])) { | |
| self.edgesForExtendedLayout = UIRectEdgeNone; | |
| UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"Hide ConferenceRooms" style:UIBarButtonItemStylePlain target:self action:@selector(toggle)]; | |
| self.navigationItem.rightBarButtonItems = @[button1]; | |
| } | |
| return self; | |
| } | |
| #pragma mark - UIViewController | |
| - (void)loadView { | |
| self.mapView = [[MRMapView alloc] init]; | |
| self.mapView.delegate = self; | |
| self.mapView.mapKey = [MREditorKey keyForMap:@"13001" app:@"5376006"]; | |
| self.view = self.mapView; | |
| } | |
| #pragma mark - Action | |
| - (void)toggle { | |
| self.conferenceHidden = !self.conferenceHidden; | |
| [self reloadAnnotations]; | |
| } | |
| #pragma mark - MRMapViewDelegate | |
| - (void)mapViewWillStartLoadingMap:(MRMapView *)mapView { | |
| self.mapView.showsPlacemarks = YES; | |
| self.placemarks = nil; | |
| [self reloadAnnotations]; | |
| } | |
| - (void)mapView:(MRMapView *)mapView didLoadPlacemarks:(NSArray *)placemarks { | |
| self.mapView.showsPlacemarks = NO; | |
| self.placemarks = placemarks; | |
| [self reloadAnnotations]; | |
| } | |
| #pragma mark - Internal | |
| - (void)reloadAnnotations { | |
| NSArray *existing = self.mapView.annotations; | |
| NSMutableArray *annotations = [NSMutableArray array]; | |
| NSMutableArray *toAdd = [NSMutableArray array]; | |
| NSMutableArray *toRemove = [NSMutableArray array]; | |
| for (MRPlacemark *i in self.placemarks) { | |
| if (![i.type isEqualToString:@"conference_room"] || !self.conferenceHidden) { | |
| [annotations addObject:i]; | |
| } | |
| } | |
| for (id<MRAnnotation> i in annotations) { | |
| if (![existing containsObject:i]) { | |
| [toAdd addObject:i]; | |
| } | |
| } | |
| for (id<MRAnnotation> i in existing) { | |
| if (![annotations containsObject:i]) { | |
| [toRemove addObject:i]; | |
| } | |
| } | |
| [self.mapView addAnnotations:toAdd]; | |
| [self.mapView removeAnnotations:toRemove]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment