-
Notifications
You must be signed in to change notification settings - Fork 3
/
RLMapView.j
244 lines (196 loc) · 7.73 KB
/
RLMapView.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@implementation RLMapView : CPView
{
CPMapView mapView;
CPView editView;
CPTextField addressField;
CPPopUpButton mapTypeMenu;
CPButton changeButton;
CPButton bigCurl;
BOOL isEditing;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
isEditing = NO;
var bundle = [CPBundle mainBundle],
colorImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"content-background.png"] size:CGSizeMake(159, 159)];
editView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height)];
[editView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[editView setBackgroundColor:[CPColor colorWithPatternImage:colorImage]];
self._DOMElement.style.border = "1px solid #bbb";
addressField = [LocationEditView customMultiLineTextField];
[addressField setDelegate:self];
[addressField setFrame:CGRectMake(15,15, aFrame.size.width -30, 60)];
[addressField setFont:[CPFont boldSystemFontOfSize:13]];
[addressField setPlaceholderString:@"Location Address"];
// addressField = [[CPTextField alloc] initWithFrame:];
// [addressField setBezeled:YES];
// [addressField setBezelStyle:CPTextFieldRoundedBezel];
// [addressField setEditable:YES];
[addressField setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[addressField setTarget:self];
[addressField setAction:@selector(updateAddress:)];
[editView addSubview:addressField];
var label = [CPTextField new];
[label setFrameOrigin:CGPointMake(15, 90)];
[label setStringValue:"Map Type:"];
[label setFont:[CPFont boldSystemFontOfSize:12]];
[label setValue:[CPColor colorWithCalibratedWhite:79.0 / 255.0 alpha:.8] forThemeAttribute:@"text-color"];
[label setValue:[CPColor colorWithCalibratedWhite:240.0 / 255.0 alpha:1.0] forThemeAttribute:@"text-shadow-color"];
[label setValue:CGSizeMake(0.0, 1.0) forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateBordered];
[label sizeToFit];
[editView addSubview:label];
mapTypeMenu = [[CPPopUpButton alloc] initWithFrame:CGRectMake(15, 110, aFrame.size.width -30, 24)];
[mapTypeMenu setAutoresizingMask:CPViewWidthSizable];
[mapTypeMenu addItemsWithTitles:[@"Standard", @"Hybrid", @"Satellite", @"Terrain"]];
[mapTypeMenu setTarget:self];
[mapTypeMenu setAction:@selector(setMapType:)];
[editView addSubview:mapTypeMenu];
var doneButton = [[CPButton alloc] initWithFrame:CGRectMake(aFrame.size.width - 115, aFrame.size.height - 39, 100, 24)];
[doneButton setTitle:@"Done"];
[doneButton setDefaultButton:YES];
[doneButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin];
[doneButton setTarget:self];
[doneButton setAction:@selector(hideEditView:)];
[editView addSubview:doneButton];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,0,aFrame.size.width,aFrame.size.height)];
//[mapView setDelegate:self];
[mapView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
//[mapView setLocation:[[CPLocation alloc] initWithString:@"4336 Griggstown Rd. Calvert City, KY"]];
[mapView setDoubleTarget:self];
[mapView setDoubleAction:@selector(showEditView:)];
[self addSubview:mapView];
changeButton = [[CPButton alloc] initWithFrame:CGRectMake(aFrame.size.width-45,aFrame.size.height-40,45,40)];
[changeButton setBordered:NO];
[changeButton setImage: [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"RLMapViewCorner.png"] size:CGSizeMake(45,40)]];
[changeButton setImagePosition:CPImageOnly];
[changeButton setAutoresizingMask:CPViewMinYMargin|CPViewMinXMargin];
[changeButton setTarget:self];
[changeButton setAction:@selector(showEditView:)];
/*bigCurl = [[CPButton alloc] initWithFrame:CGRectMake(aFrame.size.width-256, 0, 256, 306)];
[bigCurl setBordered:NO];
[bigCurl setImage: [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"RLMapViewBigCurl.png"] size:CGSizeMake(256,306)]];
[bigCurl setImagePosition:CPImageOnly];
[bigCurl setAutoresizingMask:CPViewMinYMargin|CPViewMinXMargin];
[bigCurl setTarget:self];
[bigCurl setAction:@selector(hideEditView:)];*/
[self addSubview:changeButton];
//[self addSubview:editView];
}
return self;
}
- (void)mapViewDidLoad:(id)sender
{
console.log("bam");
}
- (void)mapViewWillLoad:(id)sender
{
console.log("load");
}
- (void)updateAddress:(id)sender
{
}
- (void)showEditView:(id)sender
{
isEditing = YES;
var options = {modalView: editView};
[self addSubview:editView];
//[mapView flip:options];
var animationDict = [CPDictionary new],
mapViewFrame = [mapView frame];
[self addSubview:editView];
[animationDict setValue:editView forKey:CPViewAnimationTargetKey];
[animationDict setValue:mapViewFrame forKey:CPViewAnimationStartFrameKey];
[animationDict setValue:mapViewFrame forKey:CPViewAnimationEndFrameKey];
[animationDict setValue:CPViewAnimationFadeInEffect forKey:CPViewAnimationEffectKey];
var animation = [[CPViewAnimation alloc] initWithViewAnimations:[animationDict]];
[animation startAnimation];
}
- (void)hideEditView:(id)sender
{
//console.log("in hideEditView: of RLMapView we need to implement some editing stuff kthxbia");
isEditing = NO;
//[editView setFrame:[mapView frame]];
//var options = {modalView: editView};
[self addSubview:editView];
//[mapView unflip];
var animationDict = [CPDictionary new],
mapViewFrame = [mapView frame];
[animationDict setValue:editView forKey:CPViewAnimationTargetKey];
[animationDict setValue:mapViewFrame forKey:CPViewAnimationStartFrameKey];
[animationDict setValue:mapViewFrame forKey:CPViewAnimationEndFrameKey];
[animationDict setValue:CPViewAnimationFadeOutEffect forKey:CPViewAnimationEffectKey];
var animation = [[CPViewAnimation alloc] initWithViewAnimations:[animationDict]];
[animation startAnimation];
}
- (void)mouseDown:(CPEvent)anEvent
{
if ([anEvent clickCount] < 2)
return;
if (isEditing)
[self hideEditView:self];
else
[self showEditView:self];
}
- (void)setAddress:(CPString)anAddress
{
// alert(addressField);
[addressField setStringValue:anAddress];
[mapView takeStringAddressFrom:addressField];
}
- (void)setMapType:(id)valueOrSender
{
if ([valueOrSender isKindOfClass:[CPPopUpButton class]])
{
var valueOrSender = [valueOrSender indexOfSelectedItem];
}
else
{
// we may consider passing the actual value here...
}
[mapView setMapType:valueOrSender];
}
@end
@implementation MKMapView (doubleClicker)
{
id doubleTarget;
SEL doubleAction;
}
- (void)setDoubleTarget:(id)target
{
doubleTarget = target;
}
- (void)setDoubleAction:(id)action
{
doubleAction = action;
}
- (void)mouseDown:(CPEvent)anEvent
{
if ([anEvent clickCount] === 2 && doubleTarget && doubleAction)
{
objj_msgSend(doubleTarget, doubleAction, self);
return;
}
[self trackPan:anEvent];
[super mouseDown:anEvent];
}
- (MKMarker)addMarker:(MKMarker)aMarker atLocation:(MKLocation)aLocation
{
if (_mapReady) {
var gMarker = [aMarker gMarker];
gMarker.setLatLng([aLocation googleLatLng]);
m_map.addOverlay(gMarker);
} else {
// TODO some sort of queue?
}
return marker;
}
- (void)clearOverlays
{
if (_mapReady) {
m_map.clearOverlays();
}
}
@end