mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
ASMapNode now supports MKMapSnapshotOptions as opposed to just a region property.
This commit is contained in:
parent
e35697d162
commit
45fa36eba5
@ -12,9 +12,9 @@
|
|||||||
@interface ASMapNode : ASImageNode
|
@interface ASMapNode : ASImageNode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The current region of ASMapNode. This can be set at any time and ASMapNode will animate the change. This property may be set from a background thread before the node is loaded, and will automatically be applied to define the region of the static snapshot (if .liveMap = NO) or the internal MKMapView (otherwise).
|
The current options of ASMapNode. This can be set at any time and ASMapNode will animate the change. This property may be set from a background thread before the node is loaded, and will automatically be applied to define the behavior of the static snapshot (if .liveMap = NO) or the internal MKMapView (otherwise).
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) MKCoordinateRegion region;
|
@property (nonatomic, readwrite) MKMapSnapshotOptions *options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
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.
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
{
|
{
|
||||||
ASDN::RecursiveMutex _propertyLock;
|
ASDN::RecursiveMutex _propertyLock;
|
||||||
MKMapSnapshotter *_snapshotter;
|
MKMapSnapshotter *_snapshotter;
|
||||||
MKMapSnapshotOptions *_options;
|
|
||||||
NSArray *_annotations;
|
NSArray *_annotations;
|
||||||
CLLocationCoordinate2D _centerCoordinateOfMap;
|
CLLocationCoordinate2D _centerCoordinateOfMap;
|
||||||
}
|
}
|
||||||
@ -25,7 +24,7 @@
|
|||||||
|
|
||||||
@synthesize needsMapReloadOnBoundsChange = _needsMapReloadOnBoundsChange;
|
@synthesize needsMapReloadOnBoundsChange = _needsMapReloadOnBoundsChange;
|
||||||
@synthesize mapDelegate = _mapDelegate;
|
@synthesize mapDelegate = _mapDelegate;
|
||||||
@synthesize region = _region;
|
@synthesize options = _options;
|
||||||
@synthesize liveMap = _liveMap;
|
@synthesize liveMap = _liveMap;
|
||||||
|
|
||||||
#pragma mark - Lifecycle
|
#pragma mark - Lifecycle
|
||||||
@ -41,11 +40,9 @@
|
|||||||
_liveMap = NO;
|
_liveMap = NO;
|
||||||
_centerCoordinateOfMap = kCLLocationCoordinate2DInvalid;
|
_centerCoordinateOfMap = kCLLocationCoordinate2DInvalid;
|
||||||
|
|
||||||
//Default world-scale view
|
|
||||||
_region = MKCoordinateRegionForMapRect(MKMapRectWorld);
|
|
||||||
|
|
||||||
_options = [[MKMapSnapshotOptions alloc] init];
|
_options = [[MKMapSnapshotOptions alloc] init];
|
||||||
_options.region = _region;
|
//Default world-scale view
|
||||||
|
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -116,20 +113,19 @@
|
|||||||
_needsMapReloadOnBoundsChange = needsMapReloadOnBoundsChange;
|
_needsMapReloadOnBoundsChange = needsMapReloadOnBoundsChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MKCoordinateRegion)region
|
- (MKMapSnapshotOptions *)options
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_propertyLock);
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
return _region;
|
return _options;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRegion:(MKCoordinateRegion)region
|
- (void)setOptions:(MKMapSnapshotOptions *)options
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_propertyLock);
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
_region = region;
|
_options = options;
|
||||||
if (self.isLiveMap) {
|
if (self.isLiveMap) {
|
||||||
[_mapView setRegion:_region animated:YES];
|
[self applySnapshotOptions];
|
||||||
} else {
|
} else {
|
||||||
_options.region = _region;
|
|
||||||
[self resetSnapshotter];
|
[self resetSnapshotter];
|
||||||
[self takeSnapshot];
|
[self takeSnapshot];
|
||||||
}
|
}
|
||||||
@ -190,6 +186,15 @@
|
|||||||
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
|
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (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
|
#pragma mark - Actions
|
||||||
- (void)addLiveMap
|
- (void)addLiveMap
|
||||||
{
|
{
|
||||||
@ -198,7 +203,7 @@
|
|||||||
__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;
|
||||||
[_mapView setRegion:_options.region];
|
[weakSelf applySnapshotOptions];
|
||||||
[_mapView addAnnotations:_annotations];
|
[_mapView addAnnotations:_annotations];
|
||||||
[weakSelf setNeedsLayout];
|
[weakSelf setNeedsLayout];
|
||||||
[weakSelf.view addSubview:_mapView];
|
[weakSelf.view addSubview:_mapView];
|
||||||
@ -229,7 +234,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Layout
|
#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
|
- (void)layout
|
||||||
{
|
{
|
||||||
[super layout];
|
[super layout];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user