Skip to content

Commit

Permalink
Support "overlayclick" event, work on proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Nov 22, 2015
1 parent 9fd7a0c commit 655b493
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 108 deletions.
2 changes: 0 additions & 2 deletions iphone/Classes/TiGooglemapsCircleProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

@property(nonatomic,retain) GMSCircle *circle;

@property(nonatomic,retain) GMSMutablePath *path;

@end
73 changes: 66 additions & 7 deletions iphone/Classes/TiGooglemapsCircleProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]]) {
Expand Down
54 changes: 29 additions & 25 deletions iphone/Classes/TiGooglemapsMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#import "TiGooglemapsMapView.h"
#import "TiGooglemapsMarkerProxy.h"
#import "TiGooglemapsMapViewProxy.h"
#import "TiGooglemapsCircleProxy.h"
#import "TiGooglemapsPolygonProxy.h"
#import "TiGooglemapsPolylineProxy.h"

@implementation TiGooglemapsMapView

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = @{
Expand Down Expand Up @@ -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
};
}

Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions iphone/Classes/TiGooglemapsModule.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 4 additions & 4 deletions iphone/Classes/TiGooglemapsModule.m
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 0 additions & 2 deletions iphone/Classes/TiGooglemapsPolygonProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

@property(nonatomic,retain) GMSPolygon *polygon;

@property(nonatomic,retain) GMSMutablePath *path;

@end
112 changes: 80 additions & 32 deletions iphone/Classes/TiGooglemapsPolygonProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions iphone/Classes/TiGooglemapsPolylineProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

@property(nonatomic,retain) GMSPolyline *polyline;

@property(nonatomic,retain) GMSMutablePath *path;

@end
Loading

0 comments on commit 655b493

Please sign in to comment.