-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support polygon, polyline & circle, add basic docs
- Loading branch information
1 parent
5e5f12c
commit 07caf43
Showing
16 changed files
with
483 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,73 @@ | ||
// This is a test harness for your module | ||
// You should do something interesting in this harness | ||
// to test out the module and to provide instructions | ||
// to users on how to use it by example. | ||
var win = Ti.UI.createWindow(); | ||
var maps = require("de.hansknoechel.googlemaps"); | ||
maps.setAPIKey("AIzaSyC8XCAFXe_oGrkM0o7God1YNeMApwLFQ3c"); | ||
|
||
/* | ||
* MapView | ||
*/ | ||
var mapView = maps.createMapView(); | ||
mapView.setMapType(maps.MAP_TYPE_TERRAIN); | ||
|
||
// open a single window | ||
var win = Ti.UI.createWindow({ | ||
backgroundColor:'white' | ||
/* | ||
* Marker | ||
*/ | ||
var marker = maps.createMarker({ | ||
latitude : -32.9689, | ||
longitude : 151.7721, | ||
title : "Newcastle", | ||
snippet : "Australia" | ||
}); | ||
var label = Ti.UI.createLabel(); | ||
win.add(label); | ||
win.open(); | ||
|
||
// TODO: write your module tests here | ||
var ti_googlemaps = require('de.hansknoechel.googlemaps'); | ||
Ti.API.info("module is => " + ti_googlemaps); | ||
mapView.addMarker(marker); | ||
// mapView.addMarkers([marker]); | ||
// mapView.removeMarker(marker); | ||
|
||
label.text = ti_googlemaps.example(); | ||
/* | ||
* Overlays - Polyline | ||
*/ | ||
var polyline = maps.createPolyline({ | ||
points : [{ // Can handle both object and array | ||
latitude : -37.81319, | ||
longitude : 144.96298 | ||
}, [-31.95285, 115.85734]], | ||
strokeWidth : 3, | ||
strokeColor : "#f00" | ||
}); | ||
|
||
Ti.API.info("module exampleProp is => " + ti_googlemaps.exampleProp); | ||
ti_googlemaps.exampleProp = "This is a test value"; | ||
mapView.addPolyline(polyline); | ||
// mapView.removePolyline(polyline); | ||
|
||
if (Ti.Platform.name == "android") { | ||
var proxy = ti_googlemaps.createExample({ | ||
message: "Creating an example Proxy", | ||
backgroundColor: "red", | ||
width: 100, | ||
height: 100, | ||
top: 100, | ||
left: 150 | ||
}); | ||
/* | ||
* Overlays - Polygon | ||
*/ | ||
var polygon = maps.createPolygon({ | ||
points : [{ // Can handle both object and array | ||
latitude : -37.81819, | ||
longitude : 144.96798 | ||
}, | ||
[-32.95785, 115.86234], | ||
[-33.91785, 115.82234]], | ||
strokeWidth : 3, | ||
fillColor : "yellow", | ||
strokeColor : "green" | ||
}); | ||
|
||
proxy.printMessage("Hello world!"); | ||
proxy.message = "Hi world!. It's me again."; | ||
proxy.printMessage("Hello world!"); | ||
win.add(proxy); | ||
} | ||
mapView.addPolygon(polygon); | ||
// mapView.removePolygon(polygon); | ||
|
||
/* | ||
* Overlays - Circle | ||
*/ | ||
var circle = maps.createCircle({ | ||
center : [-32.9689, 151.7721], // Can handle both object and array | ||
radius : 500 * 1000, // 500km | ||
// fillColor: "blue", | ||
strokeWidth : 3, | ||
strokeColor : "orange" | ||
}); | ||
|
||
mapView.addCircle(circle); | ||
// mapView.removeCircle(circle); | ||
|
||
win.add(mapView); | ||
win.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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 "TiProxy.h" | ||
#import <GoogleMaps/GoogleMaps.h> | ||
#import "TiUtils.h" | ||
|
||
@interface DeHansknoechelGooglemapsCircleProxy : TiProxy { | ||
GMSCircle *circle; | ||
} | ||
|
||
@property(nonatomic,retain) GMSMutablePath *path; | ||
|
||
-(GMSCircle*)circle; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* 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 "DeHansknoechelGooglemapsCircleProxy.h" | ||
|
||
@implementation DeHansknoechelGooglemapsCircleProxy | ||
|
||
-(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]; | ||
} | ||
|
||
return circle; | ||
} | ||
|
||
-(CLLocationCoordinate2D)positionFromPoint:(id)point | ||
{ | ||
if ([point isKindOfClass:[NSDictionary class]]) { | ||
CLLocationDegrees latitude = [TiUtils doubleValue:[point valueForKey:@"latitude"]]; | ||
CLLocationDegrees longitude = [TiUtils doubleValue:[point valueForKey:@"longitude"]]; | ||
|
||
return CLLocationCoordinate2DMake(latitude, longitude); | ||
} else if ([point isKindOfClass:[NSArray class]]) { | ||
CLLocationDegrees latitude = [TiUtils doubleValue:[point objectAtIndex:0]]; | ||
CLLocationDegrees longitude = [TiUtils doubleValue:[point objectAtIndex:1]]; | ||
|
||
return CLLocationCoordinate2DMake(latitude, longitude); | ||
} | ||
} | ||
|
||
@end |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* 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 "DeHansknoechelGooglemapsMapViewProxy.h" | ||
#import "DeHansknoechelGooglemapsMarkerProxy.h" | ||
#import "DeHansknoechelGooglemapsPolylineProxy.h" | ||
#import "DeHansknoechelGooglemapsPolygonProxy.h" | ||
#import "DeHansknoechelGooglemapsCircleProxy.h" | ||
#import "TiUtils.h" | ||
|
||
@implementation DeHansknoechelGooglemapsMapViewProxy | ||
|
||
-(DeHansknoechelGooglemapsMapView*)mapView | ||
{ | ||
return (DeHansknoechelGooglemapsMapView*)[self view]; | ||
} | ||
|
||
-(void)setMapView:(GMSMapView*)_mapView | ||
{ | ||
[self setMapView:_mapView]; | ||
} | ||
|
||
#pragma mark Public API's | ||
|
||
-(void)addMarker:(id)args | ||
{ | ||
DeHansknoechelGooglemapsMarkerProxy *marker = [args objectAtIndex:0]; | ||
|
||
ENSURE_TYPE(marker, DeHansknoechelGooglemapsMarkerProxy); | ||
ENSURE_UI_THREAD_1_ARG(args); | ||
|
||
[[marker marker] setMap:[[self mapView] mapView]]; | ||
} | ||
|
||
-(void)addMarkers:(id)args | ||
{ | ||
id markers = [args objectAtIndex:0]; | ||
|
||
ENSURE_TYPE(markers, NSArray); | ||
ENSURE_UI_THREAD_1_ARG(args); | ||
|
||
for(DeHansknoechelGooglemapsMarkerProxy *marker in markers) { | ||
[[marker marker] setMap:[[self mapView] mapView]]; | ||
} | ||
} | ||
|
||
-(void)removeMarker:(id)args | ||
{ | ||
DeHansknoechelGooglemapsMarkerProxy *marker = [args objectAtIndex:0]; | ||
|
||
ENSURE_TYPE(marker, DeHansknoechelGooglemapsMarkerProxy); | ||
ENSURE_UI_THREAD_1_ARG(args); | ||
|
||
[[marker marker] setMap:nil]; | ||
} | ||
|
||
-(void)addPolyline:(id)args | ||
{ | ||
id polyline = [args objectAtIndex:0]; | ||
|
||
ENSURE_UI_THREAD_1_ARG(args); | ||
ENSURE_TYPE(polyline, DeHansknoechelGooglemapsPolylineProxy); | ||
|
||
[[polyline polyline] setMap:[[self mapView] mapView]]; | ||
} | ||
|
||
-(void)removePolyline:(id)args | ||
{ | ||
id polyline = [args objectAtIndex:0]; | ||
|
||
ENSURE_UI_THREAD_1_ARG(args); | ||
ENSURE_TYPE(polyline, DeHansknoechelGooglemapsPolylineProxy); | ||
|
||
[[polyline polyline] setMap:nil]; | ||
} | ||
|
||
-(void)addPolygon:(id)args | ||
{ | ||
id polygon = [args objectAtIndex:0]; | ||
|
||
ENSURE_UI_THREAD_1_ARG(args); | ||
ENSURE_TYPE(polygon, DeHansknoechelGooglemapsPolygonProxy); | ||
|
||
[[polygon polygon] setMap:[[self mapView] mapView]]; | ||
} | ||
|
||
-(void)removePolygon:(id)args | ||
{ | ||
id polygon = [args objectAtIndex:0]; | ||
|
||
ENSURE_UI_THREAD_1_ARG(args); | ||
ENSURE_TYPE(polygon, DeHansknoechelGooglemapsPolygonProxy); | ||
|
||
[[polygon polygon] setMap:nil]; | ||
} | ||
|
||
-(void)addCircle:(id)args | ||
{ | ||
id circle = [args objectAtIndex:0]; | ||
|
||
ENSURE_UI_THREAD_1_ARG(args); | ||
ENSURE_TYPE(circle, DeHansknoechelGooglemapsCircleProxy); | ||
|
||
[[circle circle] setMap:[[self mapView] mapView]]; | ||
} | ||
|
||
-(void)removeCircle:(id)args | ||
{ | ||
id circle = [args objectAtIndex:0]; | ||
|
||
ENSURE_UI_THREAD_1_ARG(args); | ||
ENSURE_TYPE(circle, DeHansknoechelGooglemapsCircleProxy); | ||
|
||
[[circle circle] setMap:nil]; | ||
} | ||
|
||
@end |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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 "TiProxy.h" | ||
#import <GoogleMaps/GoogleMaps.h> | ||
#import "TiUtils.h" | ||
|
||
@interface DeHansknoechelGooglemapsPolygonProxy : TiProxy { | ||
GMSPolygon *polygon; | ||
} | ||
|
||
@property(nonatomic,retain) GMSMutablePath *path; | ||
|
||
-(GMSPolygon*)polygon; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* 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 "DeHansknoechelGooglemapsPolygonProxy.h" | ||
|
||
@implementation DeHansknoechelGooglemapsPolygonProxy | ||
|
||
-(GMSPolygon*)polygon | ||
{ | ||
if (polygon == nil) { | ||
_path = [GMSMutablePath path]; | ||
polygon = [GMSPolygon polygonWithPath:_path]; | ||
|
||
id points = [self valueForKey:@"points"]; | ||
|
||
ENSURE_TYPE_OR_NIL(points, NSArray); | ||
|
||
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) { | ||
|
||
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]; | ||
} | ||
} | ||
} | ||
|
||
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; | ||
} | ||
|
||
@end |
Oops, something went wrong.