diff --git a/iphone/Classes/TiGooglemapsCircleProxy.h b/iphone/Classes/TiGooglemapsCircleProxy.h index 915fbfc..41287b2 100644 --- a/iphone/Classes/TiGooglemapsCircleProxy.h +++ b/iphone/Classes/TiGooglemapsCircleProxy.h @@ -12,6 +12,4 @@ @property(nonatomic,retain) GMSCircle *circle; -@property(nonatomic,retain) GMSMutablePath *path; - @end diff --git a/iphone/Classes/TiGooglemapsCircleProxy.m b/iphone/Classes/TiGooglemapsCircleProxy.m index 01b92d7..8e4d3a6 100644 --- a/iphone/Classes/TiGooglemapsCircleProxy.m +++ b/iphone/Classes/TiGooglemapsCircleProxy.m @@ -9,22 +9,81 @@ @implementation TiGooglemapsCircleProxy -@synthesize circle = _circle, path = _path; +@synthesize circle = _circle; -(GMSCircle*)circle { if (_circle == nil) { - _circle = [GMSCircle circleWithPosition:[self positionFromPoint:[self valueForKey:@"center"]] - radius:[TiUtils doubleValue:[self valueForKey:@"radius"]]]; - - _circle.fillColor = [[TiUtils colorValue:[self valueForKey:@"fillColor"]] _color]; - _circle.strokeColor = [[TiUtils colorValue:[self valueForKey:@"strokeColor"]] _color]; - _circle.strokeWidth = [TiUtils floatValue:[self valueForKey:@"strokeWidth"] def:1]; + _circle = [[GMSCircle alloc] init]; + _circle.tappable = YES; } return _circle; } +#pragma mark Public APIs + +-(void)setCenter:(id)args +{ + ENSURE_UI_THREAD(setCenter, args); + [self replaceValue:args forKey:@"center" notification:NO]; + + if(![args isKindOfClass:[NSArray class]] && ![args isKindOfClass:[NSDictionary class]]) { + NSLog(@"[WARN] Ti.GoogleMaps: You need to specify the center either using an array or object."); + return; + } + + [[self circle] setPosition:[self positionFromPoint:args]]; +} + +-(void)setRadius:(id)value +{ + ENSURE_UI_THREAD(setRadius, value); + ENSURE_TYPE(value, NSNumber); + + [self replaceValue:value forKey:@"radius" notification:NO]; + [[self circle] setRadius:[TiUtils doubleValue:value]]; +} + +-(void)setTappable:(id)value +{ + ENSURE_UI_THREAD(setTappable, value); + ENSURE_TYPE(value, NSNumber); + + [self replaceValue:value forKey:@"tappable" notification:NO]; + + [[self circle] setTappable:[TiUtils boolValue:value]]; +} + +-(void)setFillColor:(id)value +{ + ENSURE_UI_THREAD(setFillColor, value); + + [self replaceValue:value forKey:@"fillColor" notification:NO]; + + [[self circle] setFillColor:[[TiUtils colorValue:value] _color]]; +} + +-(void)setStrokeColor:(id)value +{ + ENSURE_UI_THREAD(setStrokeColor, value); + + [self replaceValue:value forKey:@"strokeColor" notification:NO]; + + [[self circle] setStrokeColor:[[TiUtils colorValue:value] _color]]; +} + +-(void)setStrokeWidth:(id)value +{ + ENSURE_UI_THREAD(setStrokeWidth, value); + + [self replaceValue:value forKey:@"strokeWidth" notification:NO]; + + [[self circle] setStrokeWidth:[TiUtils floatValue:value def:1]]; +} + +#pragma mark Utilities + -(CLLocationCoordinate2D)positionFromPoint:(id)point { if ([point isKindOfClass:[NSDictionary class]]) { diff --git a/iphone/Classes/TiGooglemapsMapView.m b/iphone/Classes/TiGooglemapsMapView.m index 7dd38d7..94cd9e5 100644 --- a/iphone/Classes/TiGooglemapsMapView.m +++ b/iphone/Classes/TiGooglemapsMapView.m @@ -8,6 +8,9 @@ #import "TiGooglemapsMapView.h" #import "TiGooglemapsMarkerProxy.h" #import "TiGooglemapsMapViewProxy.h" +#import "TiGooglemapsCircleProxy.h" +#import "TiGooglemapsPolygonProxy.h" +#import "TiGooglemapsPolylineProxy.h" @implementation TiGooglemapsMapView @@ -145,21 +148,9 @@ - (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)mark - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay { - - if ([overlay isKindOfClass:[GMSPolygon class]]) { - - } else if([overlay isKindOfClass:[GMSPolyline class]]) { - - } else if([overlay isKindOfClass:[GMSCircle class]]) { - - } - /* if ([[self proxy] _hasListeners:@"overlayclick"]) { - NSDictionary *event = @{ - @"overlay" : [self dictionaryFromOverlay:overlay] - }; - [[self proxy] fireEvent:@"overlayclick" withObject:event]; - }*/ + [[self proxy] fireEvent:@"overlayclick" withObject:[self dictionaryFromOverlay:overlay]]; + } } - (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker @@ -195,7 +186,7 @@ - (void)mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *)marker - (BOOL)didTapMyLocationButtonForMapView:(GMSMapView *)mapView { if ([[self proxy] _hasListeners:@"locationclick"]) { - TiGooglemapsMapViewProxy *mapViewProxy = [[TiGooglemapsMapViewProxy alloc] init]; + TiGooglemapsMapViewProxy *mapViewProxy = [[TiGooglemapsMapViewProxy alloc] _initWithPageContext:[[self proxy] pageContext]]; [mapViewProxy setMapView:mapView]; NSDictionary *event = @{ @@ -232,18 +223,31 @@ -(NSDictionary*)dictionaryFromCoordinate:(CLLocationCoordinate2D)coordinate -(NSDictionary*)dictionaryFromOverlay:(GMSOverlay*)overlay { - if (overlay == nil) { - return @{}; - } + NSString *type = nil; + TiProxy *proxy = nil; - TiGooglemapsMapViewProxy *mapViewProxy = [[TiGooglemapsMapViewProxy alloc] init]; - [mapViewProxy setMapView:[overlay map]]; + if([overlay isKindOfClass:[GMSPolygon class]]) { + proxy = [[[TiGooglemapsPolygonProxy alloc] _initWithPageContext:[[self proxy] pageContext]] autorelease]; + [(TiGooglemapsPolygonProxy*)proxy setPolygon: (GMSPolygon*)overlay]; + type = @"polygon"; + } else if([overlay isKindOfClass:[GMSPolyline class]]) { + proxy = [[TiGooglemapsPolylineProxy alloc] _initWithPageContext:[[self proxy] pageContext]]; + [(TiGooglemapsPolylineProxy*)proxy setPolyline: (GMSPolyline*)overlay]; + type = @"polyline"; + + } else if([overlay isKindOfClass:[GMSCircle class]]) { + proxy = [[TiGooglemapsCircleProxy alloc] _initWithPageContext:[[self proxy] pageContext]]; + [(TiGooglemapsCircleProxy*)proxy setCircle:(GMSCircle*)overlay]; + type = @"circle"; + } + + if (proxy == nil) { + [self throwException:@"Unknown overlay clicked" subreason:@"Overlay could not be assigned." location:CODELOCATION]; + } return @{ - @"title" : overlay.title, - @"mapView" : mapViewProxy, - @"tappable": NUMBOOL(overlay.tappable), - @"zIndex": NUMINT(overlay.zIndex) + @"overlayType" : type, + @"overlay" : proxy }; } @@ -253,7 +257,7 @@ -(TiGooglemapsMarkerProxy*)markerProxyFromMarker:(GMSMarker*)marker return nil; } - TiGooglemapsMarkerProxy* markerProxy = [[TiGooglemapsMarkerProxy alloc] init]; + TiGooglemapsMarkerProxy* markerProxy = [[TiGooglemapsMarkerProxy alloc] _initWithPageContext:[[self proxy] pageContext]]; [markerProxy setMarker:marker]; return markerProxy; diff --git a/iphone/Classes/TiGooglemapsModule.h b/iphone/Classes/TiGooglemapsModule.h index c0a174c..5266c82 100644 --- a/iphone/Classes/TiGooglemapsModule.h +++ b/iphone/Classes/TiGooglemapsModule.h @@ -1,8 +1,8 @@ /** - * ti.googlemaps - * - * Created by Your Name - * Copyright (c) 2015 Your Company. All rights reserved. + * Appcelerator Titanium Mobile + * Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. + * Licensed under the terms of the Apache Public License + * Please see the LICENSE included with this distribution for details. */ #import "TiModule.h" diff --git a/iphone/Classes/TiGooglemapsModule.m b/iphone/Classes/TiGooglemapsModule.m index f7e6f15..4db4bcf 100644 --- a/iphone/Classes/TiGooglemapsModule.m +++ b/iphone/Classes/TiGooglemapsModule.m @@ -1,8 +1,8 @@ /** - * ti.googlemaps - * - * Created by Your Name - * Copyright (c) 2015 Your Company. All rights reserved. + * Appcelerator Titanium Mobile + * Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. + * Licensed under the terms of the Apache Public License + * Please see the LICENSE included with this distribution for details. */ #import "TiBase.h" diff --git a/iphone/Classes/TiGooglemapsPolygonProxy.h b/iphone/Classes/TiGooglemapsPolygonProxy.h index 58d745b..ba90bbf 100644 --- a/iphone/Classes/TiGooglemapsPolygonProxy.h +++ b/iphone/Classes/TiGooglemapsPolygonProxy.h @@ -12,6 +12,4 @@ @property(nonatomic,retain) GMSPolygon *polygon; -@property(nonatomic,retain) GMSMutablePath *path; - @end diff --git a/iphone/Classes/TiGooglemapsPolygonProxy.m b/iphone/Classes/TiGooglemapsPolygonProxy.m index e34eb43..800d5c3 100644 --- a/iphone/Classes/TiGooglemapsPolygonProxy.m +++ b/iphone/Classes/TiGooglemapsPolygonProxy.m @@ -9,49 +9,97 @@ @implementation TiGooglemapsPolygonProxy -@synthesize polygon = _polygon, path = _path; +@synthesize polygon = _polygon; -(GMSPolygon*)polygon { if (_polygon == nil) { - [self setPath:[GMSMutablePath path]]; - [self setPolygon:[GMSPolygon polygonWithPath:_path]]; + _polygon = [[GMSPolygon alloc] init]; + _polygon.tappable = YES; + } - id points = [self valueForKey:@"points"]; - - ENSURE_TYPE_OR_NIL(points, NSArray); + return _polygon; +} + +#pragma mark Public API's + +-(void)setPoints:(id)points +{ + ENSURE_UI_THREAD(setPoints, points); + ENSURE_TYPE_OR_NIL(points, NSArray); + + [self replaceValue:points forKey:@"points" notification:NO]; + + GMSMutablePath *path = [GMSMutablePath path]; + + if (points != nil) { + if ([points count] < 2) { + NSLog(@"[WARN] Ti.GoogleMaps: You need to specify at least 2 points to create a polygon."); + return _polygon; + } - if (points != nil) { - if ([points count] < 2) { - NSLog(@"[WARN] GoogleMaps: You need to specify at least 2 points to create a polygon"); - return _polygon; - } - - for(id point in points) { + for(id point in points) { + if ([point isKindOfClass:[NSDictionary class]]) { + CLLocationDegrees latitude = [TiUtils doubleValue:[point valueForKey:@"latitude"]]; + CLLocationDegrees longitude = [TiUtils doubleValue:[point valueForKey:@"longitude"]]; + + [path addLatitude:latitude longitude:longitude]; + } else if ([point isKindOfClass:[NSArray class]]) { + CLLocationDegrees latitude = [TiUtils doubleValue:[point objectAtIndex:0]]; + CLLocationDegrees longitude = [TiUtils doubleValue:[point objectAtIndex:1]]; - if ([point isKindOfClass:[NSDictionary class]]) { - CLLocationDegrees latitude = [TiUtils doubleValue:[point valueForKey:@"latitude"]]; - CLLocationDegrees longitude = [TiUtils doubleValue:[point valueForKey:@"longitude"]]; - - [self.path addLatitude:latitude longitude:longitude]; - } else if ([point isKindOfClass:[NSArray class]]) { - CLLocationDegrees latitude = [TiUtils doubleValue:[point objectAtIndex:0]]; - CLLocationDegrees longitude = [TiUtils doubleValue:[point objectAtIndex:1]]; - - [self.path addLatitude:latitude longitude:longitude]; - } + [path addLatitude:latitude longitude:longitude]; } } - - _polygon.path = self.path; - _polygon.fillColor = [[TiUtils colorValue:[self valueForKey:@"fillColor"]] _color]; - _polygon.strokeColor = [[TiUtils colorValue:[self valueForKey:@"strokeColor"]] _color]; - _polygon.strokeWidth = [TiUtils floatValue:[self valueForKey:@"strokeWidth"] def:1]; - _polygon.geodesic = [TiUtils boolValue:[self valueForKey:@"geodesic"] def:NO]; - } - return _polygon; + [[self polygon] setPath:path]; +} + +-(void)setTappable:(id)value +{ + ENSURE_UI_THREAD(setTappable, value); + ENSURE_TYPE(value, NSNumber); + + [self replaceValue:value forKey:@"tappable" notification:NO]; + + [[self polygon] setTappable:[TiUtils boolValue:value]]; +} + +-(void)setFillColor:(id)value +{ + ENSURE_UI_THREAD(setFillColor, value); + + [self replaceValue:value forKey:@"fillColor" notification:NO]; + + [[self polygon] setFillColor:[[TiUtils colorValue:value] _color]]; +} + +-(void)setStrokeColor:(id)value +{ + ENSURE_UI_THREAD(setStrokeColor, value); + + [self replaceValue:value forKey:@"strokeColor" notification:NO]; + + [[self polygon] setStrokeColor:[[TiUtils colorValue:value] _color]]; +} + +-(void)setStrokeWidth:(id)value +{ + ENSURE_UI_THREAD(setStrokeWidth, value); + + [self replaceValue:value forKey:@"strokeWidth" notification:NO]; + + [[self polygon] setStrokeWidth:[TiUtils floatValue:value def:1]]; +} + +-(void)setGeodesic:(id)value +{ + ENSURE_UI_THREAD(setGeodesic, value); + + [self replaceValue:value forKey:@"setGeodesic" notification:NO]; + + [[self polygon] setGeodesic:[TiUtils boolValue:value def:NO]]; } @end diff --git a/iphone/Classes/TiGooglemapsPolylineProxy.h b/iphone/Classes/TiGooglemapsPolylineProxy.h index 64388de..8d6664b 100644 --- a/iphone/Classes/TiGooglemapsPolylineProxy.h +++ b/iphone/Classes/TiGooglemapsPolylineProxy.h @@ -12,6 +12,4 @@ @property(nonatomic,retain) GMSPolyline *polyline; -@property(nonatomic,retain) GMSMutablePath *path; - @end diff --git a/iphone/Classes/TiGooglemapsPolylineProxy.m b/iphone/Classes/TiGooglemapsPolylineProxy.m index 862a3e1..90e66df 100644 --- a/iphone/Classes/TiGooglemapsPolylineProxy.m +++ b/iphone/Classes/TiGooglemapsPolylineProxy.m @@ -9,47 +9,86 @@ @implementation TiGooglemapsPolylineProxy -@synthesize polyline = _polyline, path = _path; +@synthesize polyline = _polyline; -(GMSPolyline*)polyline { if (_polyline == nil) { - [self setPath:[GMSMutablePath path]]; - [self setPolyline:[GMSPolyline polylineWithPath:_path]]; + _polyline = [[GMSPolyline alloc] init]; + _polyline.tappable = YES; + } - id points = [self valueForKey:@"points"]; - - ENSURE_TYPE_OR_NIL(points, NSArray); + return _polyline; +} + +-(void)setPoints:(id)points +{ + ENSURE_UI_THREAD(setPoints, points); + ENSURE_TYPE_OR_NIL(points, NSArray); + + [self replaceValue:points forKey:@"points" notification:NO]; + + GMSMutablePath *path = [GMSMutablePath path]; + + if (points != nil) { + if ([points count] < 2) { + NSLog(@"[WARN] Ti.GoogleMaps: You need to specify at least 2 points to create a polygon."); + return; + } - if (points != nil) { - if ([points count] < 2) { - NSLog(@"[WARN] GoogleMaps: You need to specify at least 2 points to create a polyline"); - return _polyline; - } - - for(id point in points) { + for(id point in points) { + if ([point isKindOfClass:[NSDictionary class]]) { + CLLocationDegrees latitude = [TiUtils doubleValue:[point valueForKey:@"latitude"]]; + CLLocationDegrees longitude = [TiUtils doubleValue:[point valueForKey:@"longitude"]]; - if ([point isKindOfClass:[NSDictionary class]]) { - CLLocationDegrees latitude = [TiUtils doubleValue:[point valueForKey:@"latitude"]]; - CLLocationDegrees longitude = [TiUtils doubleValue:[point valueForKey:@"longitude"]]; - - [self.path addLatitude:latitude longitude:longitude]; - } else if ([point isKindOfClass:[NSArray class]]) { - CLLocationDegrees latitude = [TiUtils doubleValue:[point objectAtIndex:0]]; - CLLocationDegrees longitude = [TiUtils doubleValue:[point objectAtIndex:1]]; - - [self.path addLatitude:latitude longitude:longitude]; - } + [path addLatitude:latitude longitude:longitude]; + } else if ([point isKindOfClass:[NSArray class]]) { + CLLocationDegrees latitude = [TiUtils doubleValue:[point objectAtIndex:0]]; + CLLocationDegrees longitude = [TiUtils doubleValue:[point objectAtIndex:1]]; + + [path addLatitude:latitude longitude:longitude]; } } - - _polyline.path = self.path; - _polyline.strokeColor = [[TiUtils colorValue:[self valueForKey:@"strokeColor"]] _color]; - _polyline.strokeWidth = [TiUtils floatValue:[self valueForKey:@"strokeWidth"] def:1]; - _polyline.geodesic = [TiUtils boolValue:[self valueForKey:@"geodesic"] def:NO]; } - return _polyline; + [[self polyline] setPath:path]; +} + +-(void)setTappable:(id)value +{ + ENSURE_UI_THREAD(setTappable, value); + ENSURE_TYPE(value, NSNumber); + + [self replaceValue:value forKey:@"tappable" notification:NO]; + + [[self polyline] setTappable:[TiUtils boolValue:value]]; +} + +-(void)setStrokeColor:(id)value +{ + ENSURE_UI_THREAD(setStrokeColor, value); + + [self replaceValue:value forKey:@"strokeColor" notification:NO]; + + [[self polyline] setStrokeColor:[[TiUtils colorValue:value] _color]]; +} + +-(void)setStrokeWidth:(id)value +{ + ENSURE_UI_THREAD(setStrokeWidth, value); + + [self replaceValue:value forKey:@"strokeWidth" notification:NO]; + + [[self polyline] setStrokeWidth:[TiUtils floatValue:value def:1]]; +} + +-(void)setGeodesic:(id)value +{ + ENSURE_UI_THREAD(setGeodesic, value); + + [self replaceValue:value forKey:@"setGeodesic" notification:NO]; + + [[self polyline] setGeodesic:[TiUtils boolValue:value def:NO]]; } @end diff --git a/iphone/ti.googlemaps.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate b/iphone/ti.googlemaps.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate index 1eebba9..e83ac9f 100644 Binary files a/iphone/ti.googlemaps.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate and b/iphone/ti.googlemaps.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate differ