react-native-maps 1.21.0-alpha.8 → 1.21.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/AirGoogleMaps/AIRGoogleMap.h +2 -2
- package/ios/AirGoogleMaps/AIRGoogleMap.m +57 -0
- package/ios/AirGoogleMaps/AIRGoogleMapManager.m +15 -28
- package/ios/AirGoogleMaps/RNMapsGoogleMapView.h +3 -3
- package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +1 -1
- package/ios/AirMaps/AIRMap.h +3 -1
- package/ios/AirMaps/AIRMap.m +165 -24
- package/ios/AirMaps/RNMapsAirModule.mm +40 -171
- package/ios/AirMaps/RNMapsMapView.h +3 -3
- package/ios/AirMaps/RNMapsMapView.mm +1 -1
- package/package.json +1 -1
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
#import <GoogleMaps/GoogleMaps.h>
|
|
14
14
|
#import <MapKit/MapKit.h>
|
|
15
15
|
#import "AIRGMSMarker.h"
|
|
16
|
-
|
|
16
|
+
#import "RNMapsAirModuleDelegate.h"
|
|
17
17
|
#import "AIRGoogleMapCoordinate.h"
|
|
18
18
|
|
|
19
|
-
@interface AIRGoogleMap : GMSMapView
|
|
19
|
+
@interface AIRGoogleMap : GMSMapView <RNMapsAirModuleDelegate>
|
|
20
20
|
|
|
21
21
|
// TODO: don't use MK region?
|
|
22
22
|
@property (nonatomic, weak) RCTBridge *bridge;
|
|
@@ -748,6 +748,63 @@ id regionAsJSON(MKCoordinateRegion region) {
|
|
|
748
748
|
return [map cameraForBounds:bounds insets:UIEdgeInsetsZero];
|
|
749
749
|
}
|
|
750
750
|
|
|
751
|
+
#pragma mark - RNMapsAirModuleDelegate
|
|
752
|
+
|
|
753
|
+
- (NSDictionary *) getCoordinatesForPoint:(CGPoint)point
|
|
754
|
+
{
|
|
755
|
+
CLLocationCoordinate2D coordinate = [self.projection coordinateForPoint:point];
|
|
756
|
+
return @{
|
|
757
|
+
@"latitude": @(coordinate.latitude),
|
|
758
|
+
@"longitude": @(coordinate.longitude),
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
- (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D)location
|
|
763
|
+
{
|
|
764
|
+
CGPoint touchPoint = [self.projection pointForCoordinate:location];
|
|
765
|
+
return @{
|
|
766
|
+
@"x": @(touchPoint.x),
|
|
767
|
+
@"y": @(touchPoint.y),
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
-(void) takeSnapshotWithConfig:(NSDictionary *)config callback:(RCTPromiseResolveBlock) callback
|
|
772
|
+
{
|
|
773
|
+
/* unused
|
|
774
|
+
NSNumber *width = [config objectForKey:@"width"];
|
|
775
|
+
NSNumber *height = [config objectForKey:@"height"];
|
|
776
|
+
*/
|
|
777
|
+
NSNumber *quality = [config objectForKey:@"quality"];
|
|
778
|
+
|
|
779
|
+
NSString *format = [config objectForKey:@"format"];
|
|
780
|
+
NSString *result = [config objectForKey:@"result"];
|
|
781
|
+
NSString *filePath = [config objectForKey:@"filePath"];
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
// TODO: currently we are ignoring width, height, region
|
|
785
|
+
|
|
786
|
+
UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 0.0f);
|
|
787
|
+
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
|
|
788
|
+
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
|
789
|
+
|
|
790
|
+
NSData *data;
|
|
791
|
+
if ([format isEqualToString:@"png"]) {
|
|
792
|
+
data = UIImagePNGRepresentation(image);
|
|
793
|
+
|
|
794
|
+
} else if([format isEqualToString:@"jpg"]) {
|
|
795
|
+
data = UIImageJPEGRepresentation(image, quality.floatValue);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if ([result isEqualToString:@"file"]) {
|
|
799
|
+
[data writeToFile:filePath atomically:YES];
|
|
800
|
+
callback(filePath);
|
|
801
|
+
} else if ([result isEqualToString:@"base64"]) {
|
|
802
|
+
callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
UIGraphicsEndImageContext();
|
|
806
|
+
}
|
|
807
|
+
|
|
751
808
|
#pragma mark - Utils
|
|
752
809
|
|
|
753
810
|
- (CGRect) frameForMarker:(AIRGoogleMapMarker*) mrkView {
|
|
@@ -253,7 +253,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
|
|
|
253
253
|
format:(nonnull NSString *)format
|
|
254
254
|
quality:(nonnull NSNumber *)quality
|
|
255
255
|
result:(nonnull NSString *)result
|
|
256
|
-
withCallback:(
|
|
256
|
+
withCallback:(RCTPromiseResolveBlock)callback)
|
|
257
257
|
{
|
|
258
258
|
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
|
|
259
259
|
NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
|
|
@@ -264,7 +264,17 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
|
|
|
264
264
|
if (![view isKindOfClass:[AIRGoogleMap class]]) {
|
|
265
265
|
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
266
266
|
} else {
|
|
267
|
-
|
|
267
|
+
AIRGoogleMap *mapView = (AIRGoogleMap *)view;
|
|
268
|
+
NSMutableDictionary* config = [NSMutableDictionary new];
|
|
269
|
+
|
|
270
|
+
[mapView takeSnapshotWithConfig:config callback:callback];
|
|
271
|
+
|
|
272
|
+
[config setObject:width forKey:@"width"];
|
|
273
|
+
[config setObject:height forKey:@"height"];
|
|
274
|
+
[config setObject:format forKey:@"format"];
|
|
275
|
+
[config setObject:quality forKey:@"quality"];
|
|
276
|
+
[config setObject:result forKey:@"result"];
|
|
277
|
+
[config setObject:filePath forKey:@"filePath"];
|
|
268
278
|
|
|
269
279
|
// TODO: currently we are ignoring width, height, region
|
|
270
280
|
|
|
@@ -310,13 +320,7 @@ RCT_EXPORT_METHOD(pointForCoordinate:(nonnull NSNumber *)reactTag
|
|
|
310
320
|
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
311
321
|
} else {
|
|
312
322
|
AIRGoogleMap *mapView = (AIRGoogleMap *)view;
|
|
313
|
-
|
|
314
|
-
CGPoint touchPoint = [mapView.projection pointForCoordinate:coord];
|
|
315
|
-
|
|
316
|
-
resolve(@{
|
|
317
|
-
@"x": @(touchPoint.x),
|
|
318
|
-
@"y": @(touchPoint.y),
|
|
319
|
-
});
|
|
323
|
+
resolve([mapView getPointForCoordinates:coord]);
|
|
320
324
|
}
|
|
321
325
|
}];
|
|
322
326
|
}
|
|
@@ -337,13 +341,7 @@ RCT_EXPORT_METHOD(coordinateForPoint:(nonnull NSNumber *)reactTag
|
|
|
337
341
|
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
338
342
|
} else {
|
|
339
343
|
AIRGoogleMap *mapView = (AIRGoogleMap *)view;
|
|
340
|
-
|
|
341
|
-
CLLocationCoordinate2D coordinate = [mapView.projection coordinateForPoint:pt];
|
|
342
|
-
|
|
343
|
-
resolve(@{
|
|
344
|
-
@"latitude": @(coordinate.latitude),
|
|
345
|
-
@"longitude": @(coordinate.longitude),
|
|
346
|
-
});
|
|
344
|
+
resolve([view getCoordinatesForPoint:pt]);
|
|
347
345
|
}
|
|
348
346
|
}];
|
|
349
347
|
}
|
|
@@ -373,18 +371,7 @@ RCT_EXPORT_METHOD(getMapBoundaries:(nonnull NSNumber *)reactTag
|
|
|
373
371
|
if (![view isKindOfClass:[AIRGoogleMap class]]) {
|
|
374
372
|
RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
|
|
375
373
|
} else {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
resolve(@{
|
|
379
|
-
@"northEast" : @{
|
|
380
|
-
@"longitude" : boundingBox[0][0],
|
|
381
|
-
@"latitude" : boundingBox[0][1]
|
|
382
|
-
},
|
|
383
|
-
@"southWest" : @{
|
|
384
|
-
@"longitude" : boundingBox[1][0],
|
|
385
|
-
@"latitude" : boundingBox[1][1]
|
|
386
|
-
}
|
|
387
|
-
});
|
|
374
|
+
resolve([view getMapBoundaries]);
|
|
388
375
|
}
|
|
389
376
|
}];
|
|
390
377
|
}
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
#import <React/RCTViewComponentView.h>
|
|
12
12
|
#import <UIKit/UIKit.h>
|
|
13
|
+
#import "RNMapsHostVewDelegate.h"
|
|
14
|
+
|
|
13
15
|
@class AIRGoogleMap;
|
|
14
16
|
|
|
15
17
|
NS_ASSUME_NONNULL_BEGIN
|
|
16
18
|
|
|
17
|
-
@interface RNMapsGoogleMapView : RCTViewComponentView
|
|
18
|
-
|
|
19
|
-
- (AIRGoogleMap *) mapView;
|
|
19
|
+
@interface RNMapsGoogleMapView : RCTViewComponentView<RNMapsHostVewDelegate>
|
|
20
20
|
|
|
21
21
|
@end
|
|
22
22
|
|
package/ios/AirMaps/AIRMap.h
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
#import "SMCalloutView.h"
|
|
15
15
|
#import "RCTConvert+AirMap.h"
|
|
16
16
|
#import "AIRMapCalloutSubview.h"
|
|
17
|
+
#import "RNMapsAirModuleDelegate.h"
|
|
18
|
+
|
|
17
19
|
@class AIRMapCoordinate;
|
|
18
20
|
@class AIRMapMarker;
|
|
19
21
|
|
|
@@ -21,7 +23,7 @@ extern const NSTimeInterval AIRMapRegionChangeObserveInterval;
|
|
|
21
23
|
extern const CGFloat AIRMapZoomBoundBuffer;
|
|
22
24
|
extern const NSInteger AIRMapMaxZoomLevel;
|
|
23
25
|
|
|
24
|
-
@interface AIRMap: MKMapView<SMCalloutViewDelegate>
|
|
26
|
+
@interface AIRMap: MKMapView<SMCalloutViewDelegate, RNMapsAirModuleDelegate>
|
|
25
27
|
|
|
26
28
|
@property (nonatomic, strong) SMCalloutView *calloutView;
|
|
27
29
|
@property (nonatomic, strong) UIImageView *cacheImageView;
|
package/ios/AirMaps/AIRMap.m
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
#import "AIRMapWMSTile.h"
|
|
21
21
|
#import "AIRMapLocalTile.h"
|
|
22
22
|
#import "AIRMapOverlay.h"
|
|
23
|
+
#import "AIRMapSnapshot.h"
|
|
23
24
|
|
|
24
25
|
const NSTimeInterval AIRMapRegionChangeObserveInterval = 0.1;
|
|
25
26
|
const CGFloat AIRMapZoomBoundBuffer = 0.01;
|
|
@@ -218,29 +219,6 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
|
|
|
218
219
|
return mrkFrame;
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
- (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible {
|
|
222
|
-
NSMutableDictionary* markersFrames = [NSMutableDictionary new];
|
|
223
|
-
for (AIRMapMarker* mrkAnn in self.markers) {
|
|
224
|
-
CGRect frame = [self frameForMarker:mrkAnn];
|
|
225
|
-
CGPoint point = [self convertCoordinate:mrkAnn.coordinate toPointToView:self];
|
|
226
|
-
NSDictionary* frameDict = @{
|
|
227
|
-
@"x": @(frame.origin.x),
|
|
228
|
-
@"y": @(frame.origin.y),
|
|
229
|
-
@"width": @(frame.size.width),
|
|
230
|
-
@"height": @(frame.size.height)
|
|
231
|
-
};
|
|
232
|
-
NSDictionary* pointDict = @{
|
|
233
|
-
@"x": @(point.x),
|
|
234
|
-
@"y": @(point.y)
|
|
235
|
-
};
|
|
236
|
-
NSString* k = mrkAnn.identifier;
|
|
237
|
-
BOOL isVisible = CGRectIntersectsRect(self.bounds, frame);
|
|
238
|
-
if (k != nil && (!onlyVisible || isVisible)) {
|
|
239
|
-
[markersFrames setObject:@{ @"frame": frameDict, @"point": pointDict } forKey:k];
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return markersFrames;
|
|
243
|
-
}
|
|
244
222
|
|
|
245
223
|
- (AIRMapMarker*) markerAtPoint:(CGPoint)point {
|
|
246
224
|
AIRMapMarker* mrk = nil;
|
|
@@ -334,7 +312,7 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
|
|
|
334
312
|
return kSMCalloutViewRepositionDelayForUIScrollView;
|
|
335
313
|
}
|
|
336
314
|
|
|
337
|
-
#pragma mark
|
|
315
|
+
#pragma mark RNMapsAirModuleDelegate.h
|
|
338
316
|
|
|
339
317
|
- (NSArray *)getMapBoundaries
|
|
340
318
|
{
|
|
@@ -354,6 +332,169 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
|
|
|
354
332
|
]
|
|
355
333
|
];
|
|
356
334
|
}
|
|
335
|
+
- (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D) location
|
|
336
|
+
{
|
|
337
|
+
CGPoint touchPoint = [self convertCoordinate:location toPointToView:self];
|
|
338
|
+
|
|
339
|
+
return @{
|
|
340
|
+
@"x": @(touchPoint.x),
|
|
341
|
+
@"y": @(touchPoint.y),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
- (NSDictionary *) getCoordinatesForPoint:(CGPoint)point
|
|
345
|
+
{
|
|
346
|
+
CLLocationCoordinate2D coordinate = [self convertPoint:point toCoordinateFromView:self];
|
|
347
|
+
return @{
|
|
348
|
+
@"latitude": @(coordinate.latitude),
|
|
349
|
+
@"longitude": @(coordinate.longitude),
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
- (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible {
|
|
355
|
+
NSMutableDictionary* markersFrames = [NSMutableDictionary new];
|
|
356
|
+
for (AIRMapMarker* mrkAnn in self.markers) {
|
|
357
|
+
CGRect frame = [self frameForMarker:mrkAnn];
|
|
358
|
+
CGPoint point = [self convertCoordinate:mrkAnn.coordinate toPointToView:self];
|
|
359
|
+
NSDictionary* frameDict = @{
|
|
360
|
+
@"x": @(frame.origin.x),
|
|
361
|
+
@"y": @(frame.origin.y),
|
|
362
|
+
@"width": @(frame.size.width),
|
|
363
|
+
@"height": @(frame.size.height)
|
|
364
|
+
};
|
|
365
|
+
NSDictionary* pointDict = @{
|
|
366
|
+
@"x": @(point.x),
|
|
367
|
+
@"y": @(point.y)
|
|
368
|
+
};
|
|
369
|
+
NSString* k = mrkAnn.identifier;
|
|
370
|
+
BOOL isVisible = CGRectIntersectsRect(self.bounds, frame);
|
|
371
|
+
if (k != nil && (!onlyVisible || isVisible)) {
|
|
372
|
+
[markersFrames setObject:@{ @"frame": frameDict, @"point": pointDict } forKey:k];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return markersFrames;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
- (NSDictionary *) getCamera {
|
|
379
|
+
MKMapCamera *camera = [self camera];
|
|
380
|
+
return @{
|
|
381
|
+
@"center": @{
|
|
382
|
+
@"latitude": @(camera.centerCoordinate.latitude),
|
|
383
|
+
@"longitude": @(camera.centerCoordinate.longitude),
|
|
384
|
+
},
|
|
385
|
+
@"pitch": @(camera.pitch),
|
|
386
|
+
@"heading": @(camera.heading),
|
|
387
|
+
@"altitude": @(camera.altitude),
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
- (void)takeSnapshotWithConfig:(NSDictionary *)config
|
|
391
|
+
callback:(RCTPromiseResolveBlock) callback
|
|
392
|
+
{
|
|
393
|
+
|
|
394
|
+
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
|
|
395
|
+
|
|
396
|
+
options.mapType = self.mapType;
|
|
397
|
+
NSNumber *width = config[@"width"];
|
|
398
|
+
NSNumber *height = config[@"height"];
|
|
399
|
+
NSNumber *quality = config[@"quality"];
|
|
400
|
+
NSString*format =config[@"format"];
|
|
401
|
+
NSString*result =config[@"result"];
|
|
402
|
+
MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:config[@"region"]];
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
options.region = (region.center.latitude && region.center.longitude) ? region : self.region;
|
|
406
|
+
options.size = CGSizeMake(
|
|
407
|
+
([width floatValue] == 0) ? self.bounds.size.width : [width floatValue],
|
|
408
|
+
([height floatValue] == 0) ? self.bounds.size.height : [height floatValue]
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
options.scale = [[UIScreen mainScreen] scale];
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
|
|
415
|
+
|
|
416
|
+
[self takeMapSnapshot:snapshotter
|
|
417
|
+
format:format
|
|
418
|
+
quality:[quality floatValue]
|
|
419
|
+
result:result
|
|
420
|
+
callback:callback];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
#pragma mark Take Snapshot
|
|
424
|
+
- (void)takeMapSnapshot:(MKMapSnapshotter *) snapshotter
|
|
425
|
+
format:(NSString *)format
|
|
426
|
+
quality:(CGFloat) quality
|
|
427
|
+
result:(NSString *)result
|
|
428
|
+
callback:(RCTPromiseResolveBlock) callback {
|
|
429
|
+
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
|
|
430
|
+
NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
|
|
431
|
+
NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent];
|
|
432
|
+
|
|
433
|
+
[snapshotter startWithQueue:dispatch_get_main_queue()
|
|
434
|
+
completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
|
|
435
|
+
if (error) {
|
|
436
|
+
callback(@[error]);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
|
|
440
|
+
|
|
441
|
+
UIImage *image = snapshot.image;
|
|
442
|
+
UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
|
|
443
|
+
{
|
|
444
|
+
[image drawAtPoint:CGPointMake(0.0f, 0.0f)];
|
|
445
|
+
|
|
446
|
+
CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
|
|
447
|
+
|
|
448
|
+
for (id <AIRMapSnapshot> overlay in self.overlays) {
|
|
449
|
+
if ([overlay respondsToSelector:@selector(drawToSnapshot:context:)]) {
|
|
450
|
+
[overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
for (id <MKAnnotation> annotation in self.annotations) {
|
|
455
|
+
CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
|
|
456
|
+
|
|
457
|
+
MKAnnotationView* anView = [self viewForAnnotation: annotation];
|
|
458
|
+
|
|
459
|
+
if (anView){
|
|
460
|
+
pin = anView;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (CGRectContainsPoint(rect, point)) {
|
|
464
|
+
point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
|
|
465
|
+
point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
|
|
466
|
+
if (pin.image) {
|
|
467
|
+
[pin.image drawAtPoint:point];
|
|
468
|
+
} else {
|
|
469
|
+
CGRect pinRect = CGRectMake(point.x, point.y, pin.bounds.size.width, pin.bounds.size.height);
|
|
470
|
+
[pin drawViewHierarchyInRect:pinRect afterScreenUpdates:NO];
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
476
|
+
|
|
477
|
+
NSData *data;
|
|
478
|
+
if ([format isEqualToString:@"png"]) {
|
|
479
|
+
data = UIImagePNGRepresentation(compositeImage);
|
|
480
|
+
}
|
|
481
|
+
else if([format isEqualToString:@"jpg"]) {
|
|
482
|
+
data = UIImageJPEGRepresentation(compositeImage, quality);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if ([result isEqualToString:@"file"]) {
|
|
486
|
+
[data writeToFile:filePath atomically:YES];
|
|
487
|
+
callback(filePath);
|
|
488
|
+
}
|
|
489
|
+
else if ([result isEqualToString:@"base64"]) {
|
|
490
|
+
callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
UIGraphicsEndImageContext();
|
|
494
|
+
}];
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
|
|
357
498
|
|
|
358
499
|
- (void)setShowsUserLocation:(BOOL)showsUserLocation
|
|
359
500
|
{
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
@synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
|
|
21
21
|
|
|
22
22
|
- (void)executeWithMapView:(double)tag
|
|
23
|
-
success:(void (^)(
|
|
23
|
+
success:(void (^)(id<RNMapsAirModuleDelegate> mapView))success
|
|
24
24
|
reject:(RCTPromiseRejectBlock)reject {
|
|
25
25
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
26
26
|
id view = [_viewRegistry_DEPRECATED viewForReactTag:[NSNumber numberWithDouble:tag]];
|
|
27
|
-
if (
|
|
28
|
-
|
|
27
|
+
if ([view conformsToProtocol:@protocol(RNMapsHostVewDelegate)]) {
|
|
28
|
+
id<RNMapsAirModuleDelegate> mapViewDelegate = [view mapView];
|
|
29
|
+
success(mapViewDelegate);
|
|
29
30
|
} else {
|
|
30
|
-
|
|
31
|
-
success(mapView);
|
|
31
|
+
reject(@"Invalid argument", [NSString stringWithFormat:@"Invalid view returned from registry, expecting RNMapsMapView, got: %@", view], NULL);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -36,17 +36,8 @@
|
|
|
36
36
|
- (void)getCamera:(double)tag
|
|
37
37
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
38
38
|
reject:(RCTPromiseRejectBlock)reject {
|
|
39
|
-
[self executeWithMapView:tag success:^(
|
|
40
|
-
|
|
41
|
-
resolve(@{
|
|
42
|
-
@"center": @{
|
|
43
|
-
@"latitude": @(camera.centerCoordinate.latitude),
|
|
44
|
-
@"longitude": @(camera.centerCoordinate.longitude),
|
|
45
|
-
},
|
|
46
|
-
@"pitch": @(camera.pitch),
|
|
47
|
-
@"heading": @(camera.heading),
|
|
48
|
-
@"altitude": @(camera.altitude),
|
|
49
|
-
});
|
|
39
|
+
[self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
|
|
40
|
+
resolve([mapView getCamera]);
|
|
50
41
|
} reject:reject];
|
|
51
42
|
|
|
52
43
|
}
|
|
@@ -56,7 +47,7 @@
|
|
|
56
47
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
57
48
|
reject:(RCTPromiseRejectBlock)reject
|
|
58
49
|
{
|
|
59
|
-
[self executeWithMapView:tag success:^(
|
|
50
|
+
[self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
|
|
60
51
|
resolve([mapView getMarkersFramesWithOnlyVisible:onlyVisible]);
|
|
61
52
|
} reject:reject];
|
|
62
53
|
}
|
|
@@ -64,7 +55,7 @@
|
|
|
64
55
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
65
56
|
reject:(RCTPromiseRejectBlock)reject
|
|
66
57
|
{
|
|
67
|
-
[self executeWithMapView:tag success:^(
|
|
58
|
+
[self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
|
|
68
59
|
resolve([mapView getMapBoundaries]);
|
|
69
60
|
} reject:reject];
|
|
70
61
|
}
|
|
@@ -73,42 +64,11 @@
|
|
|
73
64
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
74
65
|
reject:(RCTPromiseRejectBlock)reject
|
|
75
66
|
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
|
|
80
|
-
|
|
81
|
-
options.mapType = mapView.mapType;
|
|
82
|
-
NSNumber *width = config[@"width"];
|
|
83
|
-
NSNumber *height = config[@"height"];
|
|
84
|
-
NSNumber *quality = config[@"quality"];
|
|
85
|
-
NSString*format =config[@"format"];
|
|
86
|
-
NSString*result =config[@"result"];
|
|
87
|
-
MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:config[@"region"]];
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
options.region = (region.center.latitude && region.center.longitude) ? region : mapView.region;
|
|
91
|
-
options.size = CGSizeMake(
|
|
92
|
-
([width floatValue] == 0) ? mapView.bounds.size.width : [width floatValue],
|
|
93
|
-
([height floatValue] == 0) ? mapView.bounds.size.height : [height floatValue]
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
options.scale = [[UIScreen mainScreen] scale];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
|
|
100
|
-
|
|
101
|
-
[self takeMapSnapshot:mapView
|
|
102
|
-
snapshotter:snapshotter
|
|
103
|
-
format:format
|
|
104
|
-
quality:[quality floatValue]
|
|
105
|
-
result:result
|
|
106
|
-
callback:resolve];
|
|
107
|
-
|
|
67
|
+
[self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
|
|
68
|
+
[mapView takeSnapshotWithConfig:config callback:resolve];
|
|
108
69
|
} reject:reject];
|
|
109
|
-
|
|
110
|
-
|
|
111
70
|
}
|
|
71
|
+
|
|
112
72
|
- (void)getAddressFromCoordinates:(double)tag
|
|
113
73
|
coordinate:(JS::NativeAirMapsModule::LatLng &)coordinate
|
|
114
74
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
@@ -117,32 +77,30 @@
|
|
|
117
77
|
double latitude = coordinate.latitude();
|
|
118
78
|
double longitude = coordinate.longitude();
|
|
119
79
|
|
|
120
|
-
|
|
121
|
-
|
|
80
|
+
|
|
81
|
+
CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude
|
|
122
82
|
longitude:longitude];
|
|
123
|
-
|
|
124
|
-
|
|
83
|
+
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
|
|
84
|
+
[geoCoder reverseGeocodeLocation:location
|
|
125
85
|
completionHandler:^(NSArray *placemarks, NSError *error) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} reject:reject];
|
|
86
|
+
if (error == nil && [placemarks count] > 0){
|
|
87
|
+
CLPlacemark *placemark = placemarks[0];
|
|
88
|
+
resolve(@{
|
|
89
|
+
@"name" : [NSString stringWithFormat:@"%@", placemark.name],
|
|
90
|
+
@"thoroughfare" : [NSString stringWithFormat:@"%@", placemark.thoroughfare],
|
|
91
|
+
@"subThoroughfare" : [NSString stringWithFormat:@"%@", placemark.subThoroughfare],
|
|
92
|
+
@"locality" : [NSString stringWithFormat:@"%@", placemark.locality],
|
|
93
|
+
@"subLocality" : [NSString stringWithFormat:@"%@", placemark.subLocality],
|
|
94
|
+
@"administrativeArea" : [NSString stringWithFormat:@"%@", placemark.administrativeArea],
|
|
95
|
+
@"subAdministrativeArea" : [NSString stringWithFormat:@"%@", placemark.subAdministrativeArea],
|
|
96
|
+
@"postalCode" : [NSString stringWithFormat:@"%@", placemark.postalCode],
|
|
97
|
+
@"countryCode" : [NSString stringWithFormat:@"%@", placemark.ISOcountryCode],
|
|
98
|
+
@"country" : [NSString stringWithFormat:@"%@", placemark.country],
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
reject(@"Invalid argument", [NSString stringWithFormat:@"Can not get address location"], NULL);
|
|
102
|
+
}
|
|
103
|
+
}];
|
|
146
104
|
}
|
|
147
105
|
|
|
148
106
|
- (void)getPointForCoordinate:(double)tag
|
|
@@ -153,16 +111,10 @@
|
|
|
153
111
|
double latitude = coordinate.latitude();
|
|
154
112
|
double longitude = coordinate.longitude();
|
|
155
113
|
|
|
156
|
-
|
|
114
|
+
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latitude,longitude);
|
|
157
115
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
toPointToView:mapView];
|
|
161
|
-
|
|
162
|
-
resolve(@{
|
|
163
|
-
@"x": @(touchPoint.x),
|
|
164
|
-
@"y": @(touchPoint.y),
|
|
165
|
-
});
|
|
116
|
+
[self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
|
|
117
|
+
resolve([mapView getPointForCoordinates:location]);
|
|
166
118
|
|
|
167
119
|
} reject:reject];
|
|
168
120
|
|
|
@@ -174,20 +126,10 @@
|
|
|
174
126
|
{
|
|
175
127
|
double x = point.x();
|
|
176
128
|
double y = point.y();
|
|
177
|
-
|
|
178
|
-
[self executeWithMapView:tag success:^(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
CLLocationCoordinate2D coordinate = [mapView convertPoint:CGPointMake(x,y)
|
|
182
|
-
toCoordinateFromView:mapView];
|
|
183
|
-
|
|
184
|
-
resolve(@{
|
|
185
|
-
@"latitude": @(coordinate.latitude),
|
|
186
|
-
@"longitude": @(coordinate.longitude),
|
|
187
|
-
});
|
|
188
|
-
|
|
129
|
+
CGPoint pt = CGPointMake(x,y);
|
|
130
|
+
[self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
|
|
131
|
+
resolve([mapView getCoordinatesForPoint:pt]);
|
|
189
132
|
} reject:reject];
|
|
190
|
-
|
|
191
133
|
|
|
192
134
|
}
|
|
193
135
|
|
|
@@ -201,80 +143,7 @@
|
|
|
201
143
|
return nil;
|
|
202
144
|
}
|
|
203
145
|
|
|
204
|
-
#pragma mark Take Snapshot
|
|
205
|
-
- (void)takeMapSnapshot:(AIRMap *)mapView
|
|
206
|
-
snapshotter:(MKMapSnapshotter *) snapshotter
|
|
207
|
-
format:(NSString *)format
|
|
208
|
-
quality:(CGFloat) quality
|
|
209
|
-
result:(NSString *)result
|
|
210
|
-
callback:(RCTPromiseResolveBlock) callback {
|
|
211
|
-
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
|
|
212
|
-
NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
|
|
213
|
-
NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent];
|
|
214
|
-
|
|
215
|
-
[snapshotter startWithQueue:dispatch_get_main_queue()
|
|
216
|
-
completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
|
|
217
|
-
if (error) {
|
|
218
|
-
callback(@[error]);
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
|
|
222
|
-
|
|
223
|
-
UIImage *image = snapshot.image;
|
|
224
|
-
UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
|
|
225
|
-
{
|
|
226
|
-
[image drawAtPoint:CGPointMake(0.0f, 0.0f)];
|
|
227
|
-
|
|
228
|
-
CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
|
|
229
146
|
|
|
230
|
-
for (id <AIRMapSnapshot> overlay in mapView.overlays) {
|
|
231
|
-
if ([overlay respondsToSelector:@selector(drawToSnapshot:context:)]) {
|
|
232
|
-
[overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
for (id <MKAnnotation> annotation in mapView.annotations) {
|
|
237
|
-
CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
|
|
238
|
-
|
|
239
|
-
MKAnnotationView* anView = [mapView viewForAnnotation: annotation];
|
|
240
|
-
|
|
241
|
-
if (anView){
|
|
242
|
-
pin = anView;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (CGRectContainsPoint(rect, point)) {
|
|
246
|
-
point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
|
|
247
|
-
point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
|
|
248
|
-
if (pin.image) {
|
|
249
|
-
[pin.image drawAtPoint:point];
|
|
250
|
-
} else {
|
|
251
|
-
CGRect pinRect = CGRectMake(point.x, point.y, pin.bounds.size.width, pin.bounds.size.height);
|
|
252
|
-
[pin drawViewHierarchyInRect:pinRect afterScreenUpdates:NO];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
258
|
-
|
|
259
|
-
NSData *data;
|
|
260
|
-
if ([format isEqualToString:@"png"]) {
|
|
261
|
-
data = UIImagePNGRepresentation(compositeImage);
|
|
262
|
-
}
|
|
263
|
-
else if([format isEqualToString:@"jpg"]) {
|
|
264
|
-
data = UIImageJPEGRepresentation(compositeImage, quality);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if ([result isEqualToString:@"file"]) {
|
|
268
|
-
[data writeToFile:filePath atomically:YES];
|
|
269
|
-
callback(filePath);
|
|
270
|
-
}
|
|
271
|
-
else if ([result isEqualToString:@"base64"]) {
|
|
272
|
-
callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
UIGraphicsEndImageContext();
|
|
276
|
-
}];
|
|
277
|
-
}
|
|
278
147
|
|
|
279
148
|
@end
|
|
280
149
|
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
|
|
10
10
|
#import <React/RCTViewComponentView.h>
|
|
11
11
|
#import <UIKit/UIKit.h>
|
|
12
|
+
#import "RNMapsHostVewDelegate.h"
|
|
13
|
+
|
|
12
14
|
@class AIRMap;
|
|
13
15
|
|
|
14
16
|
NS_ASSUME_NONNULL_BEGIN
|
|
15
17
|
|
|
16
|
-
@interface RNMapsMapView : RCTViewComponentView
|
|
17
|
-
|
|
18
|
-
- (AIRMap *) mapView;
|
|
18
|
+
@interface RNMapsMapView : RCTViewComponentView<RNMapsHostVewDelegate>
|
|
19
19
|
|
|
20
20
|
@end
|
|
21
21
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Leland Richardson <leland.m.richardson@gmail.com>",
|
|
7
7
|
"homepage": "https://github.com/react-native-maps/react-native-maps#readme",
|
|
8
|
-
"version": "1.21.0-alpha.
|
|
8
|
+
"version": "1.21.0-alpha.9",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"lint": "eslint . --max-warnings 0",
|