mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[ASMapNode] Add custom pin annotation for static maps (#1890)
* Adds possibility to have custom annotation pins on static map. This resolves #1889. * Removes wrong example for map annotations and adds some annotations to correct map example. #1889 * Static map node now uses specific property block to get annotation views. * Changes self to strongSelf inside of the snapshotters completion block. * MapNode: Adds statement in documentation. * MapNode: Block for annotation view/image now returns UIImage and center offset is returned in inout param. * MapNode and map example: Fixes from review. * MapNode example: Gets image directly from custom annotation, without creating annotation view.
This commit is contained in:
committed by
Adlai Holler
parent
c0be871812
commit
873bae2eed
6
examples/ASMapNode/Sample/Assets.xcassets/Contents.json
Normal file
6
examples/ASMapNode/Sample/Assets.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
23
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/Contents.json
vendored
Normal file
23
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "hill.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "hill@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "hill@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/hill.png
vendored
Normal file
BIN
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/hill.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/hill@2x.png
vendored
Normal file
BIN
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/hill@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
BIN
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/hill@3x.png
vendored
Normal file
BIN
examples/ASMapNode/Sample/Assets.xcassets/Hill.imageset/hill@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
23
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/Contents.json
vendored
Normal file
23
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "water.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "water@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "water@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/water.png
vendored
Normal file
BIN
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/water.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
BIN
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/water@2x.png
vendored
Normal file
BIN
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/water@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
BIN
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/water@3x.png
vendored
Normal file
BIN
examples/ASMapNode/Sample/Assets.xcassets/Water.imageset/water@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
28
examples/ASMapNode/Sample/CustomMapAnnotation.h
Normal file
28
examples/ASMapNode/Sample/CustomMapAnnotation.h
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// CustomMapAnnotation.h
|
||||
// ASDKMapTest
|
||||
//
|
||||
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// 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
|
||||
// FACEBOOK 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.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <MapKit/MapKit.h>
|
||||
|
||||
@interface CustomMapAnnotation : NSObject<MKAnnotation>
|
||||
|
||||
@property (assign, nonatomic) CLLocationCoordinate2D coordinate;
|
||||
@property (copy, nonatomic, nullable) UIImage *image;
|
||||
@property (copy, nonatomic, nullable) NSString *title;
|
||||
@property (copy, nonatomic, nullable) NSString *subtitle;
|
||||
|
||||
@end
|
||||
22
examples/ASMapNode/Sample/CustomMapAnnotation.m
Normal file
22
examples/ASMapNode/Sample/CustomMapAnnotation.m
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// CustomMapAnnotation.m
|
||||
// ASDKMapTest
|
||||
//
|
||||
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// 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
|
||||
// FACEBOOK 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.
|
||||
//
|
||||
|
||||
#import "CustomMapAnnotation.h"
|
||||
|
||||
@implementation CustomMapAnnotation
|
||||
|
||||
@end
|
||||
@@ -16,6 +16,7 @@
|
||||
//
|
||||
|
||||
#import "MapHandlerNode.h"
|
||||
#import "CustomMapAnnotation.h"
|
||||
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||
|
||||
@@ -90,6 +91,22 @@
|
||||
[_liveMapToggleButton setTitle:[self liveMapStr] withFont:nil withColor:[UIColor blueColor] forState:ASControlStateNormal];
|
||||
[_liveMapToggleButton setTitle:[self liveMapStr] withFont:[UIFont systemFontOfSize:14] withColor:[UIColor blueColor] forState:ASControlStateHighlighted];
|
||||
[_liveMapToggleButton addTarget:self action:@selector(toggleLiveMap) forControlEvents:ASControlNodeEventTouchUpInside];
|
||||
|
||||
// avoiding retain cycles
|
||||
__weak MapHandlerNode *weakSelf = self;
|
||||
|
||||
self.mapNode.imageForStaticMapAnnotationBlock = ^UIImage *(id<MKAnnotation> annotation, CGPoint *centerOffset){
|
||||
MapHandlerNode *grabbedSelf = weakSelf;
|
||||
if (grabbedSelf) {
|
||||
if ([annotation isKindOfClass:[CustomMapAnnotation class]]) {
|
||||
CustomMapAnnotation *customAnnotation = (CustomMapAnnotation *)annotation;
|
||||
return customAnnotation.image;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
};
|
||||
|
||||
[self addAnnotations];
|
||||
}
|
||||
|
||||
#pragma mark - Layout
|
||||
@@ -183,6 +200,30 @@
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
||||
- (void)addAnnotations {
|
||||
|
||||
MKPointAnnotation *brno = [MKPointAnnotation new];
|
||||
brno.coordinate = CLLocationCoordinate2DMake(49.2002211, 16.6078411);
|
||||
brno.title = @"Brno city";
|
||||
|
||||
CustomMapAnnotation *atlantic = [CustomMapAnnotation new];
|
||||
atlantic.coordinate = CLLocationCoordinate2DMake(38.6442228, -29.9956942);
|
||||
atlantic.title = @"Atlantic ocean";
|
||||
atlantic.image = [UIImage imageNamed:@"Water"];
|
||||
|
||||
CustomMapAnnotation *kilimanjaro = [CustomMapAnnotation new];
|
||||
kilimanjaro.coordinate = CLLocationCoordinate2DMake(-3.075833, 37.353333);
|
||||
kilimanjaro.title = @"Kilimanjaro";
|
||||
kilimanjaro.image = [UIImage imageNamed:@"Hill"];
|
||||
|
||||
CustomMapAnnotation *mtblanc = [CustomMapAnnotation new];
|
||||
mtblanc.coordinate = CLLocationCoordinate2DMake(45.8325, 6.864444);
|
||||
mtblanc.title = @"Mont Blanc";
|
||||
mtblanc.image = [UIImage imageNamed:@"Hill"];
|
||||
|
||||
self.mapNode.annotations = @[brno, atlantic, kilimanjaro, mtblanc];
|
||||
}
|
||||
|
||||
-(NSString *)liveMapStr
|
||||
{
|
||||
return _mapNode.liveMap ? @"Live Map is ON" : @"Live Map is OFF";
|
||||
@@ -235,6 +276,21 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (MKAnnotationView *)annotationViewForAnnotation:(id<MKAnnotation>)annotation
|
||||
{
|
||||
MKAnnotationView *av;
|
||||
if ([annotation isKindOfClass:[CustomMapAnnotation class]]) {
|
||||
av = [[MKAnnotationView alloc] init];
|
||||
av.centerOffset = CGPointMake(21, 21);
|
||||
av.image = [(CustomMapAnnotation *)annotation image];
|
||||
} else {
|
||||
av = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:@""];
|
||||
}
|
||||
|
||||
av.opaque = NO;
|
||||
return av;
|
||||
}
|
||||
|
||||
#pragma mark - MKMapViewDelegate
|
||||
|
||||
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
|
||||
@@ -244,4 +300,9 @@
|
||||
_deltaLonEditableNode.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%f", mapView.region.span.longitudeDelta]];
|
||||
}
|
||||
|
||||
- (MKAnnotationView *)mapView:(MKMapView *)__unused mapView viewForAnnotation:(id<MKAnnotation>)annotation
|
||||
{
|
||||
return [self annotationViewForAnnotation:annotation];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user