-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathMKMapView.m
More file actions
695 lines (572 loc) · 22.1 KB
/
MKMapView.m
File metadata and controls
695 lines (572 loc) · 22.1 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
//
// MKMapView.m
// MapKit
//
// Created by Rick Fillion on 7/11/10.
// Copyright 2010 Centrix.ca. All rights reserved.
//
#import "MKMapView.h"
#import "MKMapView+Private.h"
#import "JSON.h"
#import <MapKit/MKUserLocation.h>
#import "MKUserLocation+Private.h"
#import <MapKit/MKCircleView.h>
#import <MapKit/MKCircle.h>
#import <MapKit/MKPolyline.h>
#import <MapKit/MKPolygon.h>
#import <MapKit/MKAnnotationView.h>
#import <MapKit/MKPointAnnotation.h>
#import "MKMapView+DelegateWrappers.h"
#import "MKMapView+WebViewIntegration.h"
#import "MKWebView.h"
@implementation MKMapView
@synthesize delegate, mapType, userLocation, showsUserLocation,visibleMapRect;
- (id)initWithFrame:(NSRect)frame {
if (self = [super initWithFrame:frame])
{
[self customInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super initWithCoder:decoder])
{
[self customInit];
[self setMapType:[decoder decodeIntegerForKey:@"mapType"]];
[self setShowsUserLocation:[decoder decodeBoolForKey:@"showsUserLocation"]];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[super encodeWithCoder:encoder];
//[encoder encodeObject:webView forKey:@"webView"];
[encoder encodeInteger:[self mapType] forKey:@"mapType"];
[encoder encodeBool:[self showsUserLocation] forKey:@"showsUserLocation"];
}
- (void)dealloc
{
[webView close];
[webView setFrameLoadDelegate:nil];
delegate = nil;
[webView removeFromSuperview];
[webView autorelease];
[locationManager stopUpdatingLocation];
[locationManager release];
[userLocation release];
[overlays release];
[overlayViews release];
[overlayScriptObjects release];
[annotations release];
[selectedAnnotations release];
[annotationViews release];
[annotationScriptObjects release];
[super dealloc];
}
- (void)setFrame:(NSRect)frameRect
{
[self delegateRegionWillChangeAnimated:NO];
[super setFrame:frameRect];
[self willChangeValueForKey:@"region"];
[self didChangeValueForKey:@"region"];
[self willChangeValueForKey:@"centerCoordinate"];
[self didChangeValueForKey:@"centerCoordinate"];
[self delegateRegionDidChangeAnimated:NO];
}
- (void)setMapType:(MKMapType)type
{
mapType = type;
WebScriptObject *webScriptObject = [webView windowScriptObject];
NSArray *args = [NSArray arrayWithObject:[NSNumber numberWithInt:mapType]];
[webScriptObject callWebScriptMethod:@"setMapType" withArguments:args];
}
- (CLLocationCoordinate2D)centerCoordinate
{
WebScriptObject *webScriptObject = [webView windowScriptObject];
NSNumber *latitude = nil;
NSNumber *longitude = nil;
NSString *json = [webScriptObject evaluateWebScript:@"getCenterCoordinate()"];
if ([json isKindOfClass:[NSString class]])
{
NSDictionary *latlong = [json JSONValue];
latitude = [latlong objectForKey:@"latitude"];
longitude = [latlong objectForKey:@"longitude"];
}
CLLocationCoordinate2D centerCoordinate;
centerCoordinate.latitude = [latitude doubleValue];
centerCoordinate.longitude = [longitude doubleValue];
return centerCoordinate;
}
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate
{
[self setCenterCoordinate:coordinate animated: NO];
}
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated
{
[self willChangeValueForKey:@"region"];
NSArray *args = [NSArray arrayWithObjects:
[NSNumber numberWithDouble:coordinate.latitude],
[NSNumber numberWithDouble:coordinate.longitude],
[NSNumber numberWithBool:animated],
nil];
WebScriptObject *webScriptObject = [webView windowScriptObject];
[webScriptObject callWebScriptMethod:@"setCenterCoordinateAnimated" withArguments:args];
[self didChangeValueForKey:@"region"];
hasSetCenterCoordinate = YES;
}
- (MKCoordinateRegion)region
{
WebScriptObject *webScriptObject = [webView windowScriptObject];
NSString *json = [webScriptObject evaluateWebScript:@"getRegion()"];
NSDictionary *regionDict = [json JSONValue];
NSNumber *centerLatitude = [regionDict valueForKeyPath:@"center.latitude"];
NSNumber *centerLongitude = [regionDict valueForKeyPath:@"center.longitude"];
NSNumber *latitudeDelta = [regionDict objectForKey:@"latitudeDelta"];
NSNumber *longitudeDelta = [regionDict objectForKey:@"longitudeDelta"];
MKCoordinateRegion region;
region.center.longitude = [centerLongitude doubleValue];
region.center.latitude = [centerLatitude doubleValue];
region.span.latitudeDelta = [latitudeDelta doubleValue];
region.span.longitudeDelta = [longitudeDelta doubleValue];
return region;
}
- (void)setRegion:(MKCoordinateRegion)region
{
[self setRegion:region animated: NO];
}
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
{
[self delegateRegionWillChangeAnimated:animated];
[self willChangeValueForKey:@"centerCoordinate"];
WebScriptObject *webScriptObject = [webView windowScriptObject];
NSArray *args = [NSArray arrayWithObjects:
[NSNumber numberWithDouble:region.center.latitude],
[NSNumber numberWithDouble:region.center.longitude],
[NSNumber numberWithDouble:region.span.latitudeDelta],
[NSNumber numberWithDouble:region.span.longitudeDelta],
[NSNumber numberWithBool:animated],
nil];
[webScriptObject callWebScriptMethod:@"setRegionAnimated" withArguments:args];
[self didChangeValueForKey:@"centerCoordinate"];
[self delegateRegionDidChangeAnimated:animated];
}
- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate
{
[self willChangeValueForKey:@"visibleMapRect"];
visibleMapRect = mapRect;
[self setRegion:MKCoordinateRegionForMapRect(visibleMapRect) animated:NO];
[self didChangeValueForKey:@"visibleMapRect"];
}
- (void)setShowsUserLocation:(BOOL)show
{
BOOL oldValue = showsUserLocation;
showsUserLocation = show;
if (oldValue == NO && showsUserLocation == YES)
{
[self delegateWillStartLocatingUser];
// To be sure we get all of the delegate calls from CoreLocation, we have to recreate the manager.
// Unfortunately if you just call stop/start, it'll never resend the kCLErrorDenied error.
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
}
if (showsUserLocation)
{
[userLocation _setUpdating:YES];
[locationManager startUpdatingLocation];
}
else
{
[self setUserLocationMarkerVisible: NO];
[userLocation _setUpdating:NO];
[locationManager stopUpdatingLocation];
[locationManager release];
locationManager = nil;
[userLocation _setLocation:nil];
}
if (oldValue == YES && showsUserLocation == NO)
{
[self delegateDidStopLocatingUser];
}
}
- (BOOL)isUserLocationVisible
{
if (!self.showsUserLocation || !userLocation.location)
return NO;
WebScriptObject *webScriptObject = [webView windowScriptObject];
NSNumber *visible = [webScriptObject callWebScriptMethod:@"isUserLocationVisible" withArguments:[NSArray array]];
return [visible boolValue];
}
#pragma mark Overlays
- (NSArray *)overlays
{
return [[overlays copy] autorelease];
}
- (void)addOverlay:(id < MKOverlay >)overlay
{
[self insertOverlay:overlay atIndex:[overlays count]];
}
- (void)addOverlays:(NSArray *)someOverlays
{
for (id<MKOverlay>overlay in someOverlays)
{
[self addOverlay: overlay];
}
}
- (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2
{
if (index1 >= [overlays count] || index2 >= [overlays count])
{
NSLog(@"exchangeOverlayAtIndex: either index1 or index2 is above the bounds of the overlays array.");
return;
}
id < MKOverlay > overlay1 = [[overlays objectAtIndex: index1] retain];
id < MKOverlay > overlay2 = [[overlays objectAtIndex: index2] retain];
[overlays replaceObjectAtIndex:index2 withObject:overlay1];
[overlays replaceObjectAtIndex:index1 withObject:overlay2];
[overlay1 release];
[overlay2 release];
[self updateOverlayZIndexes];
}
- (void)insertOverlay:(id < MKOverlay >)overlay aboveOverlay:(id < MKOverlay >)sibling
{
if (![overlays containsObject:sibling])
return;
NSUInteger indexOfSibling = [overlays indexOfObject:sibling];
[self insertOverlay:overlay atIndex: indexOfSibling+1];
}
- (void)insertOverlay:(id < MKOverlay >)overlay atIndex:(NSUInteger)index
{
// check if maybe we already have this one.
if ([overlays containsObject:overlay])
return;
// Make sure we have a valid index.
if (index > [overlays count])
index = [overlays count];
WebScriptObject *webScriptObject = [webView windowScriptObject];
if ([webScriptObject isKindOfClass:[WebUndefined class]])
{
NSLog(@"MapKit view isn't ready to add overlay: %@", overlay);
return;
}
MKOverlayView *overlayView = nil;
if ([self.delegate respondsToSelector:@selector(mapView:viewForOverlay:)])
overlayView = [self.delegate mapView:self viewForOverlay:overlay];
if (!overlayView)
{
// TODO: Handle the case where we have no view
NSLog(@"Wasn't able to create a MKOverlayView for overlay: %@", overlay);
return;
}
WebScriptObject *overlayScriptObject = [overlayView overlayScriptObjectFromMapScriptObject:webScriptObject];
if (![overlayScriptObject isKindOfClass:[WebScriptObject class]])
{
NSLog(@"Error creating internal representation of overlay view for overlay: %@", overlay);
return;
}
[overlays insertObject:overlay atIndex:index];
[overlayViews setObject:overlayView forKey:overlay];
[overlayScriptObjects setObject:overlayScriptObject forKey:overlay];
NSArray *args = [NSArray arrayWithObject:overlayScriptObject];
[webScriptObject callWebScriptMethod:@"addOverlay" withArguments:args];
[overlayView draw:overlayScriptObject];
[self updateOverlayZIndexes];
// TODO: refactor how this works so that we can send one batch call
// when they called addOverlays:
[self delegateDidAddOverlayViews:[NSArray arrayWithObject:overlayView]];
}
- (void)insertOverlay:(id < MKOverlay >)overlay belowOverlay:(id < MKOverlay >)sibling
{
if (![overlays containsObject:sibling])
return;
NSUInteger indexOfSibling = [overlays indexOfObject:sibling];
[self insertOverlay:overlay atIndex: indexOfSibling];
}
- (void)removeOverlay:(id < MKOverlay >)overlay
{
if (![overlays containsObject:overlay])
return;
WebScriptObject *webScriptObject = [webView windowScriptObject];
WebScriptObject *overlayScriptObject = (WebScriptObject *)[overlayScriptObjects objectForKey: overlay];
NSArray *args = [NSArray arrayWithObject:overlayScriptObject];
[webScriptObject callWebScriptMethod:@"removeOverlay" withArguments:args];
[overlayViews removeObjectForKey:overlay];
[overlayScriptObjects removeObjectForKey:overlay];
[overlays removeObject:overlay];
[self updateOverlayZIndexes];
}
- (void)removeOverlays:(NSArray *)someOverlays
{
for (id<MKOverlay>overlay in someOverlays)
{
[self removeOverlay: overlay];
}
}
- (MKOverlayView *)viewForOverlay:(id < MKOverlay >)overlay
{
if (![overlays containsObject:overlay])
return nil;
return (MKOverlayView *)[overlayViews objectForKey: overlay];
}
#pragma mark Annotations
- (NSArray *)annotations
{
return [[annotations copy] autorelease];
}
- (void)addAnnotation:(id < MKAnnotation >)annotation
{
// check if maybe we already have this one.
if ([annotations containsObject:annotation])
return;
WebScriptObject *webScriptObject = [webView windowScriptObject];
if ([webScriptObject isKindOfClass:[WebUndefined class]])
{
NSLog(@"MapKit view isn't ready to add annotation: %@", annotation);
return;
}
MKAnnotationView *annotationView = nil;
if ([self.delegate respondsToSelector:@selector(mapView:viewForAnnotation:)])
annotationView = [self.delegate mapView:self viewForAnnotation:annotation];
if (!annotationView)
{
// TODO: Handle the case where we have no view
NSLog(@"Wasn't able to create a MKAnnotationView for annotation: %@", annotation);
return;
}
WebScriptObject *annotationScriptObject = [annotationView overlayScriptObjectFromMapScriptObject:webScriptObject];
if (![annotationScriptObject isKindOfClass:[WebScriptObject class]])
{
NSLog(@"Error creating internal representation of annotation view for annotation: %@", annotation);
return;
}
[annotations addObject:annotation];
[annotationViews setObject:annotationView forKey:annotation];
[annotationScriptObjects setObject:annotationScriptObject forKey:annotation];
NSArray *args = [NSArray arrayWithObject:annotationScriptObject];
[webScriptObject callWebScriptMethod:@"addAnnotation" withArguments:args];
[annotationView draw:annotationScriptObject];
[self updateAnnotationZIndexes];
// TODO: refactor how this works so that we can send one batch call
// when they called addAnnotations:
[self delegateDidAddAnnotationViews:[NSArray arrayWithObject:annotationView]];
}
- (void)addAnnotations:(NSArray *)someAnnotations
{
for (id<MKAnnotation>annotation in someAnnotations)
{
[self addAnnotation: annotation];
}
}
- (void)removeAnnotation:(id < MKAnnotation >)annotation
{
if (![annotations containsObject:annotation])
return;
WebScriptObject *webScriptObject = [webView windowScriptObject];
WebScriptObject *annotationScriptObject = (WebScriptObject *)[annotationScriptObjects objectForKey: annotation];
NSArray *args = [NSArray arrayWithObject:annotationScriptObject];
[webScriptObject callWebScriptMethod:@"removeAnnotation" withArguments:args];
[annotationViews removeObjectForKey: annotation];
[annotationScriptObjects removeObjectForKey: annotation];
[annotations removeObject:annotation];
}
- (void)removeAnnotations:(NSArray *)someAnnotations
{
for (id<MKAnnotation>annotation in someAnnotations)
{
[self removeAnnotation: annotation];
}
}
- (MKAnnotationView *)viewForAnnotation:(id < MKAnnotation >)annotation
{
if (![annotations containsObject:annotation])
return nil;
return (MKAnnotationView *)[annotationViews objectForKey: annotation];
}
- (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier
{
// Unsupported for now.
return nil;
}
- (void)selectAnnotation:(id < MKAnnotation >)annotation animated:(BOOL)animated
{
if ([selectedAnnotations containsObject:annotation])
return;
MKAnnotationView *annotationView = (id)[annotationViews objectForKey: annotation];
[selectedAnnotations addObject:annotation];
[self delegateDidSelectAnnotationView:annotationView];
WebScriptObject *webScriptObject = [webView windowScriptObject];
WebScriptObject *annotationScriptObject = (WebScriptObject *)[annotationScriptObjects objectForKey: annotation];
if (annotation.title && annotationView.canShowCallout)
{
NSArray *args = [NSArray arrayWithObjects:annotationScriptObject, annotation.title, nil];
[webScriptObject callWebScriptMethod:@"setAnnotationCalloutText" withArguments:args];
args = [NSArray arrayWithObjects:annotationScriptObject, [NSNumber numberWithBool:NO], nil];
[webScriptObject callWebScriptMethod:@"setAnnotationCalloutHidden" withArguments:args];
}
}
- (void)deselectAnnotation:(id < MKAnnotation >)annotation animated:(BOOL)animated
{
// TODO : animate this if called for.
if (![selectedAnnotations containsObject:annotation])
return;
MKAnnotationView *annotationView = (id)[annotationViews objectForKey: annotation];
[selectedAnnotations removeObject:annotation];
[self delegateDidDeselectAnnotationView:annotationView];
WebScriptObject *webScriptObject = [webView windowScriptObject];
WebScriptObject *annotationScriptObject = (WebScriptObject *)[annotationScriptObjects objectForKey: annotation];
NSArray *args = [NSArray arrayWithObjects:annotationScriptObject, [NSNumber numberWithBool:YES], nil];
[webScriptObject callWebScriptMethod:@"setAnnotationCalloutHidden" withArguments:args];
}
- (NSArray *)selectedAnnotations
{
return [[selectedAnnotations copy] autorelease];
}
- (void)setSelectedAnnotations:(NSArray *)someAnnotations
{
// Deselect whatever was selected
NSArray *oldSelectedAnnotations = [self selectedAnnotations];
for (id <MKAnnotation> annotation in oldSelectedAnnotations)
{
[self deselectAnnotation:annotation animated:NO];
}
NSMutableArray *newSelectedAnnotations = [NSMutableArray arrayWithArray: [[someAnnotations copy] autorelease]];
[selectedAnnotations release];
selectedAnnotations = [newSelectedAnnotations retain];
// If it's manually set and there's more than one, you only select the first according to the docs.
if ([selectedAnnotations count] > 0)
[self selectAnnotation:[selectedAnnotations objectAtIndex:0] animated:NO];
}
#pragma mark Converting Map Coordinates
- (NSPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(NSView *)view
{
NSPoint point = {0,0};
NSArray *args = [NSArray arrayWithObjects:
[NSNumber numberWithDouble:coordinate.latitude],
[NSNumber numberWithDouble:coordinate.longitude],
nil];
WebScriptObject *webScriptObject = [webView windowScriptObject];
NSString *json = [webScriptObject callWebScriptMethod:@"convertCoordinate" withArguments:args];
NSNumber *x = nil;
NSNumber *y = nil;
if ([json isKindOfClass:[NSString class]])
{
NSDictionary *xy = [json JSONValue];
x = [xy objectForKey:@"x"];
y = [xy objectForKey:@"y"];
}
point.x = [x integerValue];
point.y = [y integerValue];
point = [webView convertPoint:point toView:view];
return point;
}
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(NSView *)view
{
// TODO: Implement
NSLog(@"-[MKMapView convertPoint: toCoordinateFromView:] not implemented yet");
CLLocationCoordinate2D coordinate;
return coordinate;
}
- (MKCoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(NSView *)view
{
// TODO: Implement
NSLog(@"-[MKMapView convertRect: toRegionFromView:] not implemented yet");
MKCoordinateRegion region;
return region;
}
- (NSRect)convertRegion:(MKCoordinateRegion)region toRectToView:(NSView *)view
{
// TODO: Implement
NSLog(@"-[MKMapView convertRegion: toRectToView:] not implemented yet");
return NSZeroRect;
}
#pragma mark Faked Properties
- (BOOL)isScrollEnabled
{
return YES;
}
- (void)setScrollEnabled:(BOOL)scrollEnabled
{
if (!scrollEnabled)
NSLog(@"setting scrollEnabled to NO on MKMapView not supported.");
}
- (BOOL)isZoomEnabled
{
return YES;
}
- (void)setZoomEnabled:(BOOL)zoomEnabled
{
if (!zoomEnabled)
NSLog(@"setting zoomEnabled to NO on MKMapView not supported");
}
#pragma mark CoreLocationManagerDelegate
- (void) locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *)newLocation
fromLocation: (CLLocation *)oldLocation
{
if (!hasSetCenterCoordinate)
[self setCenterCoordinate:newLocation.coordinate];
[userLocation _setLocation:newLocation];
[self updateUserLocationMarkerWithLocaton:newLocation];
[self setUserLocationMarkerVisible:YES];
[self delegateDidUpdateUserLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
[self delegateDidFailToLocateUserWithError:error];
[self setUserLocationMarkerVisible:NO];
if ([error code] == kCLErrorDenied)
{
[self setShowsUserLocation:NO];
}
}
#pragma mark WebFrameLoadDelegate
- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowScriptObject forFrame:(WebFrame *)frame
{
[windowScriptObject setValue:windowScriptObject forKey:@"WindowScriptObject"];
[windowScriptObject setValue:self forKey:@"MKMapView"];
}
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
{
if ([frame isEqual:[webView mainFrame]])
[self delegateWillStartLoadingMap];
}
- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
{
if ([frame isEqual:[webView mainFrame]])
[self delegateDidFailLoadingMapWithError:error];
}
- (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
{
if ([frame isEqual:[webView mainFrame]])
[self delegateDidFailLoadingMapWithError:error];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
// CoreLocation can sometimes trigger before the page has even finished loading.
if (self.showsUserLocation && userLocation.location)
{
[self locationManager: locationManager didUpdateToLocation: userLocation.location fromLocation:nil];
}
if ([frame isEqual:[webView mainFrame]])
{
// In case we have to resume state from NSCoding
[self setMapType:[self mapType]];
[self setShowsUserLocation:[self showsUserLocation]];
[self performSelector:@selector(delegateDidFinishLoadingMap) withObject:nil afterDelay:0.5];
}
}
#pragma mark WebUIDelegate
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems
{
return [NSArray array];
}
- (NSUInteger)webView:(WebView *)sender dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
{
return WebDragDestinationActionNone;
}
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
{
NSLog(@"alert: %@", message);
}
@end