mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge pull request #1036 from aaronschubert0/ASMapNode
[ASMapNode] now supports MKMapSnapshotOptions to specify map parameters
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
{
|
||||
ASDN::RecursiveMutex _propertyLock;
|
||||
MKMapSnapshotter *_snapshotter;
|
||||
MKMapSnapshotOptions *_options;
|
||||
NSArray *_annotations;
|
||||
CLLocationCoordinate2D _centerCoordinateOfMap;
|
||||
}
|
||||
@@ -28,7 +27,7 @@
|
||||
|
||||
@synthesize needsMapReloadOnBoundsChange = _needsMapReloadOnBoundsChange;
|
||||
@synthesize mapDelegate = _mapDelegate;
|
||||
@synthesize region = _region;
|
||||
@synthesize options = _options;
|
||||
@synthesize liveMap = _liveMap;
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
@@ -43,13 +42,6 @@
|
||||
_needsMapReloadOnBoundsChange = YES;
|
||||
_liveMap = NO;
|
||||
_centerCoordinateOfMap = kCLLocationCoordinate2DInvalid;
|
||||
|
||||
//Default world-scale view
|
||||
_region = MKCoordinateRegionForMapRect(MKMapRectWorld);
|
||||
|
||||
_options = [[MKMapSnapshotOptions alloc] init];
|
||||
_options.region = _region;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -119,20 +111,19 @@
|
||||
_needsMapReloadOnBoundsChange = needsMapReloadOnBoundsChange;
|
||||
}
|
||||
|
||||
- (MKCoordinateRegion)region
|
||||
- (MKMapSnapshotOptions *)options
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _region;
|
||||
return _options;
|
||||
}
|
||||
|
||||
- (void)setRegion:(MKCoordinateRegion)region
|
||||
- (void)setOptions:(MKMapSnapshotOptions *)options
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_region = region;
|
||||
_options = options;
|
||||
if (self.isLiveMap) {
|
||||
[_mapView setRegion:_region animated:YES];
|
||||
[self applySnapshotOptions];
|
||||
} else {
|
||||
_options.region = _region;
|
||||
[self resetSnapshotter];
|
||||
[self takeSnapshot];
|
||||
}
|
||||
@@ -183,7 +174,9 @@
|
||||
- (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.");
|
||||
_options.size = self.calculatedSize;
|
||||
if (!_options) {
|
||||
[self createInitialOptions];
|
||||
}
|
||||
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
|
||||
}
|
||||
|
||||
@@ -193,6 +186,23 @@
|
||||
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
|
||||
}
|
||||
|
||||
- (void)createInitialOptions
|
||||
{
|
||||
_options = [[MKMapSnapshotOptions alloc] init];
|
||||
//Default world-scale view
|
||||
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
|
||||
_options.size = self.calculatedSize;
|
||||
}
|
||||
|
||||
- (void)applySnapshotOptions
|
||||
{
|
||||
[_mapView setCamera:_options.camera animated:YES];
|
||||
[_mapView setRegion:_options.region animated:YES];
|
||||
[_mapView setMapType:_options.mapType];
|
||||
_mapView.showsBuildings = _options.showsBuildings;
|
||||
_mapView.showsPointsOfInterest = _options.showsPointsOfInterest;
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
- (void)addLiveMap
|
||||
{
|
||||
@@ -201,7 +211,10 @@
|
||||
__weak ASMapNode *weakSelf = self;
|
||||
_mapView = [[MKMapView alloc] initWithFrame:CGRectZero];
|
||||
_mapView.delegate = weakSelf.mapDelegate;
|
||||
[_mapView setRegion:_options.region];
|
||||
if (!_options) {
|
||||
[weakSelf createInitialOptions];
|
||||
}
|
||||
[weakSelf applySnapshotOptions];
|
||||
[_mapView addAnnotations:_annotations];
|
||||
[weakSelf setNeedsLayout];
|
||||
[weakSelf.view addSubview:_mapView];
|
||||
@@ -232,7 +245,7 @@
|
||||
}
|
||||
|
||||
#pragma mark - Layout
|
||||
// Layout isn't usually needed in the box model, but since we are making use of MKMapView which is hidden in an ASDisplayNode this is preferred.
|
||||
// Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred.
|
||||
- (void)layout
|
||||
{
|
||||
[super layout];
|
||||
|
||||
Reference in New Issue
Block a user