Skip to content

Commit

Permalink
Merge pull request #293 from anil-shukla-axway/MOD-2418_Updated
Browse files Browse the repository at this point in the history
MOD-2418/2450 TI.Map iOS: Support rotation on annotations
  • Loading branch information
ssjsamir authored Sep 4, 2020
2 parents b1e3c53 + 3dcbbc1 commit bb9bdf2
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 15 deletions.
20 changes: 20 additions & 0 deletions apidoc/Annotation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,23 @@ properties:
since: "6.2.0"
type: Titanium.UI.iOS.PreviewContext
osver: {ios: {min: "9.0"}}

methods:

- name: animate
summary: Animate annotation to new location.
parameters:
- name: newLocation
summary: latitude and longitude where annotation will animate.
type: Array<Number>
platforms: [iphone, ipad]
since: "9.2.0"

- name: rotate
summary: Rotate annotation on its location.
parameters:
- name: angle
summary: angle on which annotation will rotate.
type: Number
platforms: [iphone, ipad]
since: "9.2.0"
5 changes: 2 additions & 3 deletions ios/Classes/TiMapAnnotationProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
// Title and subtitle for use by selection UI.
- (NSString *)title;
- (NSString *)subtitle;

- (id)pincolor;
- (id)nativePinColor;
- (BOOL)animatesDrop;
- (void)setHidden:(id)value;

- (UIView *)leftViewAccessory;
- (UIView *)rightViewAccessory;

- (int)tag;
- (void)animate:(id)arg;
- (void)rotate:(id)arg;

@end
19 changes: 19 additions & 0 deletions ios/Classes/TiMapAnnotationProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -548,5 +548,24 @@ - (int)tag
{
return tag;
}
- (void)rotate:(id)arg
{
CGFloat getAngle = [[arg objectAtIndex:0] floatValue];
[UIView animateWithDuration:1
animations:^{
MKAnnotationView *annotationView = [[(TiMapView *)[delegate view] map] viewForAnnotation:self];
annotationView.transform = CGAffineTransformMakeRotation(getAngle);
}];
}

- (void)animate:(id)arg
{
ENSURE_SINGLE_ARG(arg, NSArray);
TiMapAnnotationProxy *newAnnotation = self;
CLLocationCoordinate2D newLocation;
newLocation.latitude = [[arg objectAtIndex:0] floatValue];
newLocation.longitude = [[arg objectAtIndex:1] floatValue];
[(TiMapView *)[delegate view] animateAnnotation:newAnnotation withLocation:newLocation];
}

@end
1 change: 1 addition & 0 deletions ios/Classes/TiMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#if IS_IOS_11
- (void)setClusterAnnotation:(TiMapAnnotationProxy *)annotation forMembers:(NSArray<TiMapAnnotationProxy *> *)members;
#endif
- (void)animateAnnotation:(TiMapAnnotationProxy *)newAnnotation withLocation:(CLLocationCoordinate2D)newLocation;

#pragma mark Utils
- (void)addOverlay:(MKPolyline *)polyline level:(MKOverlayLevel)level;
Expand Down
19 changes: 14 additions & 5 deletions ios/Classes/TiMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
#import "TiMapRouteProxy.h"
#import "TiMapUtils.h"
#import "TiUtils.h"
#import <MapKit/MapKit.h>

@implementation TiMapView

CLLocationCoordinate2D userNewLocation;

#pragma mark Internal

- (void)dealloc
Expand Down Expand Up @@ -237,7 +240,6 @@ - (void)addAnnotations:(id)args
{
ENSURE_TYPE(args, NSArray);
ENSURE_UI_THREAD(addAnnotations, args);

[[self map] addAnnotations:[self annotationsFromArgs:args]];
}

Expand Down Expand Up @@ -1067,7 +1069,6 @@ - (TiMapAnnotationProxy *)proxyForAnnotation:(MKAnnotationView *)pinview
for (id annotation in [map annotations]) {
if ([annotation isKindOfClass:[TiMapAnnotationProxy class]]) {
if ([(TiMapAnnotationProxy *)annotation tag] == pinview.tag) {
[annotation setView:pinview];
return annotation;
}
}
Expand Down Expand Up @@ -1202,7 +1203,6 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotationProxy:(TiMap
annView.canShowCallout = [TiUtils boolValue:[ann valueForUndefinedKey:@"canShowCallout"] def:YES];
annView.enabled = YES;
annView.centerOffset = ann.offset;

#if IS_IOS_11
if ([TiMapView isiOS11OrGreater]) {
annView.clusteringIdentifier = [ann valueForUndefinedKey:@"clusterIdentifier"];
Expand Down Expand Up @@ -1257,13 +1257,22 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotationProxy:(TiMap
ann.controllerPreviewing = [controller registerForPreviewingWithDelegate:previewingDelegate sourceView:annView];
#endif
}

return annView;
}
- (void)animateAnnotation:(TiMapAnnotationProxy *)newAnnotation withLocation:(CLLocationCoordinate2D)newLocation
{
userNewLocation.latitude = newLocation.latitude;
userNewLocation.longitude = newLocation.longitude;

[UIView animateWithDuration:2
animations:^{
newAnnotation.coordinate = userNewLocation;
MKAnnotationView *annotationView = (MKAnnotationView *)[self.map viewForAnnotation:newAnnotation];
}];
}
// mapView:viewForAnnotation: provides the view for each annotation.
// This method may be called for all or some of the added annotations.
// For MapKit provided annotations (eg. MKUserLocation) return nil to use the MapKit provided annotation view.
// For MapKit provided annotations (eg. MKUserLocation) return nil to use the MapKit provided annotatiown view.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[TiMapAnnotationProxy class]]) {
Expand Down
22 changes: 18 additions & 4 deletions ios/example/tests/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ exports.run = function(UI, Map) {
}; //Mountain View
}
},
{
hasChild: true,
title: 'animate annotation',
run: function() {
var newLocation = [-33.09,151.03];
anno2.animate(newLocation);
}
},
{
hasChild: true,
title: 'rotate annotation',
run: function() {
var angle = 90;
anno4.rotate(angle);
}
},
{
hasChild: true,
title: 'add anno3',
Expand Down Expand Up @@ -86,7 +102,6 @@ exports.run = function(UI, Map) {
tableView.addEventListener('click', function(e) {
rows[e.index].run && rows[e.index].run();
});

var anno = Map.createAnnotation({
latitude: -33.87365,
image: 'map_pin.png',
Expand Down Expand Up @@ -117,7 +132,6 @@ exports.run = function(UI, Map) {
subtitle: 'This is anno4',
draggable: true
});

Ti.API.info('Latitude:' + anno.latitude);
Ti.API.info('Title:' + anno.title);

Expand All @@ -127,8 +141,8 @@ exports.run = function(UI, Map) {
animate: true,
annotations: [anno, anno2, anno4],
region: {
latitude: -33.87365,
longitude: 151.20689,
latitude: -33.86365,
longitude: 151.21689,
latitudeDelta: 0.1,
longitudeDelta: 0.1
}, //Sydney
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.3.1
version: 3.4.0
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: External version of Map module
Expand Down
1 change: 0 additions & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//
//
TITANIUM_SDK_VERSION = 9.0.0.GA

//
// THESE SHOULD BE OK GENERALLY AS-IS
//
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@titanium-sdk/ti.map",
"version": "5.0.2",
"version": "5.0.3",
"description": "Provides Map UI elements for Titanium applications",
"scripts": {
"commit": "git-cz",
Expand Down

0 comments on commit bb9bdf2

Please sign in to comment.