Skip to content

Commit 39dc587

Browse files
author
Denis Bogatyrev
committed
Merge branch 'release/1.2.1'
2 parents 71727f2 + ddd0d56 commit 39dc587

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

DBMapSelectorViewController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'DBMapSelectorViewController'
3-
s.version = '1.2.0'
3+
s.version = '1.2.1'
44
s.authors = { 'Denis Bogatyrev' => 'denis.bogatyrev@gmail.com' }
55
s.summary = 'This component allows you to select circular map region from the MKMapView'
66
s.homepage = 'https://github.com/d0ping/DBMapSelectorViewController'

Example/DBMapSelectorViewControllerExample/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.2.0</string>
18+
<string>1.2.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ You can change additional MapSelector properties. Full properties list is shown
9191
- `BOOL fillInside` - Used to switching between inside or outside filling;
9292
- `UIColor *fillColor` - Used to specify the selector fill color. Color is used to fill the circular map region;
9393
- `UIColor *strokeColor` - Used to specify the selector stroke color. Color is used to delimit the circular map region;
94-
- `BOOL shouldShowRadiusText` - Indicates whether the radius text should be displayed or not.
94+
- `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;
95+
- `BOOL shouldShowRadiusText` - Indicates whether the radius text should be displayed or not;
96+
- `BOOL shouldLongPressGesture` - It allows to move the selector to a new location via long press gesture.
9597
9698
### DBMapSelectorManagerDelegate
9799
@@ -123,6 +125,11 @@ You can implement these methods in your `MyViewController` class in order to res
123125
```
124126
## Version history
125127

128+
### 1.2.1
129+
- Added new property `BOOL shouldLongPressGesture`. It allows to move the selector to a new location via long press gesture.
130+
- Added new property `CGFloat mapRegionCoef`. The magnification factor maps region after changing the selector settings. It is recommended to set a value greater than 1.f.
131+
- Improved drawing selector after first display map controller. Fixed problem when sometimes it cuts the circle after first load.
132+
126133
### 1.2.0
127134
- The DBMapSelectorViewController was replaced by a DBMapSelectorManager. This change allows the functionality provided by this component to be more easily integrated into existing projects where, for instance, the target view controller already inherits from another custom view controller. (Thank [Marcelo Schroeder](https://github.com/marcelo-schroeder) for giving solution).
128135
- Improved user experience when moving the map selector.

Source/DBMapSelectorManager.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@ typedef NS_ENUM(NSInteger, DBMapSelectorEditingType) {
7474
*/
7575
@property (nonatomic, strong) UIColor *strokeColor;
7676

77-
/*! @brief Indicates whether the radius text should be displayed or not. */
77+
/*!
78+
@brief The magnification factor maps region after changing the selector settings
79+
@discussion It is recommended to set a value greater than 1.f
80+
*/
81+
@property (nonatomic, assign) CGFloat mapRegionCoef; // default is equal 2.f
82+
83+
/*! @brief Indicates whether the radius text should be displayed or not */
7884
@property (nonatomic) BOOL shouldShowRadiusText;
7985

86+
/*! @brief It allows to move the selector to a new location via long press gesture */
87+
@property (nonatomic) BOOL shouldLongPressGesture; // default is NO
88+
8089
- (instancetype)initWithMapView:(MKMapView *)mapView;
8190
- (void)applySelectorSettings;
8291

Source/DBMapSelectorManager.m

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020

2121

2222
@interface DBMapSelectorManager () {
23+
BOOL _isFirstTimeApplySelectorSettings;
2324
DBMapSelectorOverlay *_selectorOverlay;
2425
DBMapSelectorOverlayRenderer *_selectorOverlayRenderer;
25-
26+
2627
BOOL _mapViewGestureEnabled;
2728
MKMapPoint _prevMapPoint;
2829
CLLocationDistance _prevRadius;
2930
CGRect _radiusTouchRect;
3031
UIView *_radiusTouchView;
32+
33+
UILongPressGestureRecognizer *_longPressGestureRecognizer;
3134
}
3235

3336
@end
@@ -37,6 +40,7 @@ @implementation DBMapSelectorManager
3740
- (instancetype)initWithMapView:(MKMapView *)mapView {
3841
self = [super init];
3942
if (self) {
43+
_isFirstTimeApplySelectorSettings = YES;
4044
_mapView = mapView;
4145
[self prepareForFirstUse];
4246
}
@@ -55,8 +59,11 @@ - (void)prepareForFirstUse {
5559
// [self.mapView addSubview:_radiusTouchView];
5660
#endif
5761

62+
_longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizer:)];
63+
5864
_mapViewGestureEnabled = YES;
5965
[self.mapView addGestureRecognizer:[self selectorGestureRecognizer]];
66+
6067
}
6168

6269
#pragma mark Defaults
@@ -71,12 +78,18 @@ - (void)selectorSetDefaults {
7178
self.shouldShowRadiusText = YES;
7279
self.fillColor = [UIColor orangeColor];
7380
self.strokeColor = [UIColor darkGrayColor];
81+
self.mapRegionCoef = 2.f;
7482
}
7583

7684
- (void)applySelectorSettings {
7785
[self updateMapRegionForMapSelector];
7886
[self displaySelectorAnnotationIfNeeded];
7987
[self recalculateRadiusTouchRect];
88+
if (_isFirstTimeApplySelectorSettings) {
89+
_isFirstTimeApplySelectorSettings = NO;
90+
[self.mapView removeOverlay:_selectorOverlay];
91+
[self.mapView addOverlay:_selectorOverlay];
92+
}
8093
}
8194

8295
#pragma mark - GestureRecognizer
@@ -147,6 +160,28 @@ - (DBMapSelectorGestureRecognizer *)selectorGestureRecognizer {
147160
return selectorGestureRecognizer;
148161
}
149162

163+
- (void)longPressGestureRecognizer:(UILongPressGestureRecognizer *)gestureRecognizer {
164+
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] &&
165+
( self.editingType == DBMapSelectorEditingTypeFull || self.editingType == DBMapSelectorEditingTypeCoordinateOnly )) {
166+
switch (gestureRecognizer.state) {
167+
case UIGestureRecognizerStateBegan: {
168+
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
169+
CLLocationCoordinate2D coord = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
170+
self.circleCoordinate = coord;
171+
[self displaySelectorAnnotationIfNeeded];
172+
break;
173+
}
174+
case UIGestureRecognizerStateEnded:
175+
if (NO == MKMapRectContainsRect(self.mapView.visibleMapRect, _selectorOverlay.boundingMapRect)) {
176+
[self updateMapRegionForMapSelector];
177+
}
178+
break;
179+
default:
180+
break;
181+
}
182+
}
183+
}
184+
150185
#pragma mark - Accessors
151186

152187
- (void)setCircleRadius:(CLLocationDistance)circleRadius {
@@ -243,6 +278,17 @@ - (void)setShouldShowRadiusText:(BOOL)shouldShowRadiusText {
243278
_selectorOverlay.shouldShowRadiusText = shouldShowRadiusText;
244279
}
245280

281+
- (void)setShouldLongPressGesture:(BOOL)shouldLongPressGesture {
282+
if (_shouldLongPressGesture != shouldLongPressGesture) {
283+
_shouldLongPressGesture = shouldLongPressGesture;
284+
if (_shouldLongPressGesture) {
285+
[self.mapView addGestureRecognizer:_longPressGestureRecognizer];
286+
} else {
287+
[self.mapView removeGestureRecognizer:_longPressGestureRecognizer];
288+
}
289+
}
290+
}
291+
246292
#pragma mark - Additional
247293

248294
- (void)recalculateRadiusTouchRect {
@@ -261,7 +307,7 @@ - (void)updateMapRegionForMapSelector {
261307
MKCoordinateRegion selectorRegion = MKCoordinateRegionForMapRect(_selectorOverlay.boundingMapRect);
262308
MKCoordinateRegion region;
263309
region.center = selectorRegion.center;
264-
region.span = MKCoordinateSpanMake(selectorRegion.span.latitudeDelta *2.f, selectorRegion.span.longitudeDelta *2.f);
310+
region.span = MKCoordinateSpanMake(selectorRegion.span.latitudeDelta * _mapRegionCoef, selectorRegion.span.longitudeDelta * _mapRegionCoef);
265311
[self.mapView setRegion:region animated:YES];
266312
}
267313

0 commit comments

Comments
 (0)