-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMKPolygon.j
68 lines (57 loc) · 1.66 KB
/
MKPolygon.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@import <AppKit/CPView.j>
@import "MKMapItem.j"
@import "MKMapView.j"
@import "MKLocation.j"
@implementation MKPolygon : MKMapItem
{
CPArray _locations @accessors(property=locations);
CPString _lineColorCode @accessors(property=lineColorCode);
int _lineStroke @accessors(property=lineStroke);
int _fillColorCode @accessors(property=fillColorCode);
float _fillOpacity @accessors(property=fillOpacity);
float _lineOpacity @accessors(property=lineOpacity);
}
+ (MKPolygon)polygon
{
return [[MKPolygon alloc] init];
}
- (id)init {
return [self initWithLocations:nil];
}
- (id)initWithLocations:(CPArray)someLocations
{
if (self = [super init]) {
_locations = someLocations;
_lineColorCode = @"#ff0000";
_fillColorCode = @"#000000";
_fillOpacity = 0.7;
_lineOpacity = 1;
_lineStroke = 5;
}
return self;
}
- (void)addLocation:(MKLocation)aLocation {
if (!_locations) {
_locations = [[CPArray alloc] init];
}
[_locations addObject:aLocation];
}
- (Polygon)googlePolygon {
if (_locations) {
var gm = [MKMapView gmNamespace];
var locEnum = [_locations objectEnumerator];
var loc = nil
var lineCoordinates = [];
while (loc = [locEnum nextObject]) {
lineCoordinates.push([loc googleLatLng]);
}
return new gm.Polygon(lineCoordinates, _lineColorCode, _lineStroke, _lineOpacity, _fillColorCode, _fillOpacity);
}
return nil;
}
- (void)addToMapView:(MKMapView)mapView
{
var googleMap = [mapView gMap];
googleMap.addOverlay([self googlePolygon]);
}
@end