This component allows you to select circular map region from the MKMapView.
This component allows you to select circular map region from the MKMapView.
To add DBMapSelectorViewController via CocoaPods into your project:
pod 'DBMapSelectorViewController', '~> 1.2.0'
pod install
To add DBMapSelectorViewController manually into your project:
git clone
Source
folder into your project (Make sure to select Copy items when asked if you extracted the code archive outside of your project)To use DBMapSelectorViewController in your project you should perform the following steps:
...
// (1)
#import "DBMapSelectorManager.h"
@interface ViewController () <DBMapSelectorManagerDelegate>
@property (nonatomic, strong) DBMapSelectorManager *mapSelectorManager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// (2)
self.mapSelectorManager = [[DBMapSelectorManager alloc] initWithMapView:self.mapView];
self.mapSelectorManager.delegate = self;
// (3)
self.mapSelectorManager.circleCoordinate = CLLocationCoordinate2DMake(55.75399400, 37.62209300);
self.mapSelectorManager.circleRadius = 3000;
[self.mapSelectorManager applySelectorSettings];
}
...
// (4)
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
return [self.mapSelectorManager mapView:mapView viewForAnnotation:annotation];
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {
[self.mapSelectorManager mapView:mapView annotationView:annotationView didChangeDragState:newState fromOldState:oldState];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {
return [self.mapSelectorManager mapView:mapView rendererForOverlay:overlay];
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
[self.mapSelectorManager mapView:mapView regionDidChangeAnimated:animated];
}
@end
You can change additional MapSelector properties. Full properties list is shown below:
DBMapSelectorEditingType editingType
- Used to specify the selector editing type. Property can equal one of four values:
DBMapSelectorEditingTypeFull
allows to edit coordinate and radius,DBMapSelectorEditingTypeCoordinateOnly
allows to edit cooordinate only,DBMapSelectorEditingTypeRadiusOnly
allows to edit radius only,DBMapSelectorEditingTypeNone
read only mode;CLLocationCoordinate2D circleCoordinate
- Used to specify the selector coordinate;CLLocationDistance circleRadius
- Used to specify the selector radius. Default is equal 1000 meter;CLLocationDistance circleRadiusMin
- Used to specify the minimum selector radius. Default is equal 100 meter;CLLocationDistance circleRadiusMax
- Used to specify the maximum selector radius. Default is equal 10000 meter;BOOL hidden
- Used to hide or show selector. Default is NO;BOOL fillInside
- Used to switching between inside or outside filling;UIColor *fillColor
- Used to specify the selector fill color. Color is used to fill the circular map region;UIColor *strokeColor
- Used to specify the selector stroke color. Color is used to delimit the circular map region;CGFloat mapRegionCoef
- Used to specify the magnification factor maps region. This parameter affects display the maps region after changing the selector settings. It is recommended to set a value greater than 1.f;BOOL shouldShowRadiusText
- Indicates whether the radius text should be displayed or not;BOOL shouldLongPressGesture
- It allows to move the selector to a new location via long press gesture.To be able to react when the main properties (coordinate and radius) of the selector will be changed you must become delegate DBMapSelectorManager. DBMapSelectorManagerDelegate protocol you can see here:
@protocol DBMapSelectorManagerDelegate <NSObject>
@optional
- (void)mapSelectorManager:(DBMapSelectorManager *)mapSelectorManager didChangeCoordinate:(CLLocationCoordinate2D)coordinate;
- (void)mapSelectorManager:(DBMapSelectorManager *)mapSelectorManager didChangeRadius:(CLLocationDistance)radius;
- (void)mapSelectorManagerWillBeginHandlingUserInteraction:(DBMapSelectorManager *)mapSelectorManager;
- (void)mapSelectorManagerDidHandleUserInteraction:(DBMapSelectorManager *)mapSelectorManager;
@end
You can implement these methods in your MyViewController
class in order to respond to these changes. For example, how it can be implemented in your class:
- (void)mapSelectorManager:(DBMapSelectorManager *)mapSelectorManager didChangeCoordinate:(CLLocationCoordinate2D)coordinate {
_coordinateLabel.text = [NSString stringWithFormat:@"Coordinate = {%.5f, %.5f}", coordinate.latitude, coordinate.longitude];
}
- (void)mapSelectorManager:(DBMapSelectorManager *)mapSelectorManager didChangeRadius:(CLLocationDistance)radius {
NSString *radiusStr = (radius >= 1000) ? [NSString stringWithFormat:@"%.1f km", radius * .001f] : [NSString stringWithFormat:@"%.0f m", radius];
_radiusLabel.text = [@"Radius = " stringByAppendingString:radiusStr];
}
BOOL shouldLongPressGesture
. It allows to move the selector to a new location via long press gesture.CGFloat mapRegionCoef
. The magnification factor maps region after changing the selector settings. It is recommended to set a value greater than 1.f.Denis Bogatyrev (maintainer)
DBMapSelectorViewController - Copyright © 2015 Denis Bogatyrev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.