mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-13 18:00:17 +00:00
Re-add .region property for API compatibility and convenience, using options object internally.
This commit is contained in:
parent
64ad48a248
commit
28618f7238
@ -19,6 +19,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, strong) MKMapSnapshotOptions *options;
|
@property (nonatomic, strong) MKMapSnapshotOptions *options;
|
||||||
|
|
||||||
|
/** The region is simply the sub-field on the options object. If the objects object is reset,
|
||||||
|
this will in effect be overwritten and become the value of the .region property on that object.
|
||||||
|
Defaults to MKCoordinateRegionForMapRect(MKMapRectWorld).
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) MKCoordinateRegion region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This is the MKMapView that is the live map part of ASMapNode. This will be nil if .liveMap = NO. Note, MKMapView is *not* thread-safe.
|
This is the MKMapView that is the live map part of ASMapNode. This will be nil if .liveMap = NO. Note, MKMapView is *not* thread-safe.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -114,6 +114,11 @@
|
|||||||
- (MKMapSnapshotOptions *)options
|
- (MKMapSnapshotOptions *)options
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_propertyLock);
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
|
if (!_options) {
|
||||||
|
_options = [[MKMapSnapshotOptions alloc] init];
|
||||||
|
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
|
||||||
|
_options.size = self.calculatedSize;
|
||||||
|
}
|
||||||
return _options;
|
return _options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +134,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (MKCoordinateRegion)region
|
||||||
|
{
|
||||||
|
return self.options.region;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setRegion:(MKCoordinateRegion)region
|
||||||
|
{
|
||||||
|
self.options.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Snapshotter
|
#pragma mark - Snapshotter
|
||||||
|
|
||||||
- (void)takeSnapshot
|
- (void)takeSnapshot
|
||||||
@ -174,33 +189,25 @@
|
|||||||
- (void)setUpSnapshotter
|
- (void)setUpSnapshotter
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssert(!CGSizeEqualToSize(CGSizeZero, self.calculatedSize), @"self.calculatedSize can not be zero. Make sure that you are setting a preferredFrameSize or wrapping ASMapNode in a ASRatioLayoutSpec or similar.");
|
ASDisplayNodeAssert(!CGSizeEqualToSize(CGSizeZero, self.calculatedSize), @"self.calculatedSize can not be zero. Make sure that you are setting a preferredFrameSize or wrapping ASMapNode in a ASRatioLayoutSpec or similar.");
|
||||||
if (!_options) {
|
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:self.options];
|
||||||
[self createInitialOptions];
|
|
||||||
}
|
|
||||||
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetSnapshotter
|
- (void)resetSnapshotter
|
||||||
{
|
{
|
||||||
|
// FIXME: The semantics of this method / name would suggest that we cancel + destroy the snapshotter,
|
||||||
|
// but not that we create a new one. We should probably only create the new one in -takeSnapshot or something.
|
||||||
[_snapshotter cancel];
|
[_snapshotter cancel];
|
||||||
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
|
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:self.options];
|
||||||
}
|
|
||||||
|
|
||||||
- (void)createInitialOptions
|
|
||||||
{
|
|
||||||
_options = [[MKMapSnapshotOptions alloc] init];
|
|
||||||
//Default world-scale view
|
|
||||||
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
|
|
||||||
_options.size = self.calculatedSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applySnapshotOptions
|
- (void)applySnapshotOptions
|
||||||
{
|
{
|
||||||
[_mapView setCamera:_options.camera animated:YES];
|
MKMapSnapshotOptions *options = self.options;
|
||||||
[_mapView setRegion:_options.region animated:YES];
|
[_mapView setCamera:options.camera animated:YES];
|
||||||
[_mapView setMapType:_options.mapType];
|
[_mapView setRegion:options.region animated:YES];
|
||||||
_mapView.showsBuildings = _options.showsBuildings;
|
[_mapView setMapType:options.mapType];
|
||||||
_mapView.showsPointsOfInterest = _options.showsPointsOfInterest;
|
_mapView.showsBuildings = options.showsBuildings;
|
||||||
|
_mapView.showsPointsOfInterest = options.showsPointsOfInterest;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Actions
|
#pragma mark - Actions
|
||||||
@ -211,9 +218,6 @@
|
|||||||
__weak ASMapNode *weakSelf = self;
|
__weak ASMapNode *weakSelf = self;
|
||||||
_mapView = [[MKMapView alloc] initWithFrame:CGRectZero];
|
_mapView = [[MKMapView alloc] initWithFrame:CGRectZero];
|
||||||
_mapView.delegate = weakSelf.mapDelegate;
|
_mapView.delegate = weakSelf.mapDelegate;
|
||||||
if (!_options) {
|
|
||||||
[weakSelf createInitialOptions];
|
|
||||||
}
|
|
||||||
[weakSelf applySnapshotOptions];
|
[weakSelf applySnapshotOptions];
|
||||||
[_mapView addAnnotations:_annotations];
|
[_mapView addAnnotations:_annotations];
|
||||||
[weakSelf setNeedsLayout];
|
[weakSelf setNeedsLayout];
|
||||||
@ -227,6 +231,7 @@
|
|||||||
|
|
||||||
- (void)removeLiveMap
|
- (void)removeLiveMap
|
||||||
{
|
{
|
||||||
|
// FIXME: With MKCoordinateRegion, isn't the center coordinate fully specified? Do we need this?
|
||||||
_centerCoordinateOfMap = _mapView.centerCoordinate;
|
_centerCoordinateOfMap = _mapView.centerCoordinate;
|
||||||
[_mapView removeFromSuperview];
|
[_mapView removeFromSuperview];
|
||||||
_mapView = nil;
|
_mapView = nil;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user