Skip to content

Commit

Permalink
Added ios google maps polygon, polyline, maptype support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Italiano committed Oct 24, 2016
1 parent d183c0f commit 16f362b
Show file tree
Hide file tree
Showing 20 changed files with 471 additions and 146 deletions.
5 changes: 2 additions & 3 deletions components/MapPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from 'react-native';
import decorateMapComponent, {
USES_DEFAULT_IMPLEMENTATION,
NOT_SUPPORTED,
SUPPORTED,
} from './decorateMapComponent';

const propTypes = {
Expand Down Expand Up @@ -92,7 +92,6 @@ const propTypes = {
* points on the Earth's surface. The geodesic curve is constructed assuming the Earth is
* a sphere.
*
* @platform android
*/
geodesic: PropTypes.bool,

Expand Down Expand Up @@ -145,7 +144,7 @@ module.exports = decorateMapComponent(MapPolygon, {
componentType: 'Polygon',
providers: {
google: {
ios: NOT_SUPPORTED,
ios: SUPPORTED,
android: USES_DEFAULT_IMPLEMENTATION,
},
},
Expand Down
4 changes: 2 additions & 2 deletions components/MapPolyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from 'react-native';
import decorateMapComponent, {
USES_DEFAULT_IMPLEMENTATION,
NOT_SUPPORTED,
SUPPORTED,
} from './decorateMapComponent';

const propTypes = {
Expand Down Expand Up @@ -140,7 +140,7 @@ module.exports = decorateMapComponent(MapPolyline, {
componentType: 'Polyline',
providers: {
google: {
ios: NOT_SUPPORTED,
ios: SUPPORTED,
android: USES_DEFAULT_IMPLEMENTATION,
},
},
Expand Down
11 changes: 2 additions & 9 deletions components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ const MAP_TYPES = {
NONE: 'none',
};

const ANDROID_ONLY_MAP_TYPES = [
MAP_TYPES.TERRAIN,
MAP_TYPES.NONE,
];

const viewConfig = {
uiViewClassName: 'AIR<provider>Map',
validAttributes: {
Expand Down Expand Up @@ -208,7 +203,8 @@ const propTypes = {
* - standard: standard road map (default)
* - satellite: satellite view
* - hybrid: satellite view with roads and points of interest overlayed
* - terrain: (Android only) topographic view
* - terrain: topographic view
* - none: no base map
*/
mapType: PropTypes.oneOf(Object.values(MAP_TYPES)),

Expand Down Expand Up @@ -502,9 +498,6 @@ class MapView extends React.Component {
onMapReady: this._onMapReady,
onLayout: this._onLayout,
};
if (Platform.OS === 'ios' && ANDROID_ONLY_MAP_TYPES.includes(props.mapType)) {
props.mapType = MAP_TYPES.STANDARD;
}
props.handlePanDrag = !!props.onPanDrag;
} else {
props = {
Expand Down
4 changes: 2 additions & 2 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class App extends React.Component {
[EventListener, 'Events', true, '(incomplete)'],
[MarkerTypes, 'Image Based Markers', true],
[DraggableMarkers, 'Draggable Markers', true],
[PolygonCreator, 'Polygon Creator'],
[PolylineCreator, 'Polyline Creator'],
[PolygonCreator, 'Polygon Creator', true],
[PolylineCreator, 'Polyline Creator', true],
[AnimatedViews, 'Animating with MapViews'],
[AnimatedMarkers, 'Animated Marker Position'],
[Callouts, 'Custom Callouts', true],
Expand Down
1 change: 1 addition & 0 deletions example/examples/PolygonCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PolygonCreator extends React.Component {
<MapView
provider={this.props.provider}
style={styles.map}
mapType={MapView.MAP_TYPES.HYBRID}
initialRegion={this.state.region}
onPress={e => this.onPress(e)}
{...mapOptions}
Expand Down
250 changes: 121 additions & 129 deletions example/ios/AirMapsExplorer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ SPEC CHECKSUMS:
GoogleMaps: 06589b9a38097bce0cd6e90f0fd9b5e4b4a9344c
React: d80af5410aa500d0cb1bce2cc4493a584cf2ec92

COCOAPODS: 0.39.0
PODFILE CHECKSUM: be65689c848eff5d4099a483239b72acab62f6a4

COCOAPODS: 1.1.1
2 changes: 2 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
@property (nonatomic, copy) RCTDirectEventBlock onRegionChange;
@property (nonatomic, copy) RCTDirectEventBlock onRegionChangeComplete;
@property (nonatomic, strong) NSMutableArray *markers;
@property (nonatomic, strong) NSMutableArray *polygons;
@property (nonatomic, strong) NSMutableArray *polylines;

@property (nonatomic, assign) BOOL showsBuildings;
@property (nonatomic, assign) BOOL showsTraffic;
Expand Down
21 changes: 21 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#import "AIRGoogleMap.h"
#import "AIRGoogleMapMarker.h"
#import "AIRGoogleMapPolygon.h"
#import "AIRGoogleMapPolyline.h"
#import <GoogleMaps/GoogleMaps.h>
#import <MapKit/MapKit.h>
#import "RCTConvert+MapKit.h"
Expand Down Expand Up @@ -73,6 +75,8 @@ - (instancetype)init
if ((self = [super init])) {
_reactSubviews = [NSMutableArray new];
_markers = [NSMutableArray array];
_polygons = [NSMutableArray array];
_polylines = [NSMutableArray array];
_initialRegionSet = false;
}
return self;
Expand Down Expand Up @@ -102,6 +106,14 @@ - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
AIRGoogleMapMarker *marker = (AIRGoogleMapMarker*)subview;
marker.realMarker.map = self;
[self.markers addObject:marker];
} else if ([subview isKindOfClass:[AIRGoogleMapPolygon class]]) {
AIRGoogleMapPolygon *polygon = (AIRGoogleMapPolygon*)subview;
polygon.polygon.map = self;
[self.polygons addObject:polygon];
} else if ([subview isKindOfClass:[AIRGoogleMapPolyline class]]) {
AIRGoogleMapPolyline *polyline = (AIRGoogleMapPolyline*)subview;
polyline.polyline.map = self;
[self.polylines addObject:polyline];
}
[_reactSubviews insertObject:(UIView *)subview atIndex:(NSUInteger) atIndex];
}
Expand All @@ -117,6 +129,14 @@ - (void)removeReactSubview:(id<RCTComponent>)subview {
AIRGoogleMapMarker *marker = (AIRGoogleMapMarker*)subview;
marker.realMarker.map = nil;
[self.markers removeObject:marker];
} else if ([subview isKindOfClass:[AIRGoogleMapPolygon class]]) {
AIRGoogleMapPolygon *polygon = (AIRGoogleMapPolygon*)subview;
polygon.polygon.map = nil;
[self.polygons removeObject:polygon];
} else if ([subview isKindOfClass:[AIRGoogleMapPolyline class]]) {
AIRGoogleMapPolyline *polyline = (AIRGoogleMapPolyline*)subview;
polyline.polyline.map = nil;
[self.polylines removeObject:polyline];
}
[_reactSubviews removeObject:(UIView *)subview];
}
Expand Down Expand Up @@ -244,4 +264,5 @@ - (void)setShowsUserLocation:(BOOL)showsUserLocation {
- (BOOL)showsUserLocation {
return self.myLocationEnabled;
}

@end
2 changes: 2 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "RCTUIManager.h"
#import "RCTConvert+CoreLocation.h"
#import "RCTConvert+MapKit.h"
#import "RCTConvert+GMSMapViewType.h"
#import "RCTEventDispatcher.h"
#import "AIRGoogleMap.h"
#import "UIView+React.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(onMarkerPress, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onRegionChange, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onRegionChangeComplete, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(mapType, GMSMapViewType)

RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
animated:(BOOL)animated)
Expand Down
21 changes: 21 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapPolygon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AIRGoogleMapPolygon.h
//
// Created by Nick Italiano on 10/22/16.
//

#import <GoogleMaps/GoogleMaps.h>
#import "AIRMapCoordinate.h"

@interface AIRGoogleMapPolygon : UIView

@property (nonatomic, strong) GMSPolygon *polygon;
@property (nonatomic, strong) NSArray<AIRMapCoordinate *> *coordinates;

@property (nonatomic, assign) UIColor *fillColor;
@property (nonatomic, assign) double strokeWidth;
@property (nonatomic, assign) UIColor *strokeColor;
@property (nonatomic, assign) BOOL geodesic;
@property (nonatomic, assign) int zIndex;

@end
64 changes: 64 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapPolygon.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// AIRGoogleMapPolygon.m
//
// Created by Nick Italiano on 10/22/16.
//

#import "AIRGoogleMapPolygon.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation AIRGoogleMapPolygon

- (instancetype)init
{
if (self = [super init]) {
_polygon = [[GMSPolygon alloc] init];
}

return self;
}

- (void)setCoordinates:(NSArray<AIRMapCoordinate *> *)coordinates
{
_coordinates = coordinates;

GMSMutablePath *path = [GMSMutablePath path];
for(int i = 0; i < coordinates.count; i++)
{
[path addCoordinate:coordinates[i].coordinate];
}

_polygon.path = path;
}

-(void)setFillColor:(UIColor *)fillColor
{
_fillColor = fillColor;
_polygon.fillColor = fillColor;
}

-(void)setStrokeWidth:(double)strokeWidth
{
_strokeWidth = strokeWidth;
_polygon.strokeWidth = strokeWidth;
}

-(void)setStrokeColor:(UIColor *) strokeColor
{
_strokeColor = strokeColor;
_polygon.strokeColor = strokeColor;
}

-(void)setGeodesic:(BOOL)geodesic
{
_geodesic = geodesic;
_polygon.geodesic = geodesic;
}

-(void)setZIndex:(int)zIndex
{
_zIndex = zIndex;
_polygon.zIndex = zIndex;
}

@end
11 changes: 11 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapPolygonManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// AIRGoogleMapPolylgoneManager.h
//
// Created by Nick Italiano on 10/22/16.
//

#import "RCTViewManager.h"

@interface AIRGoogleMapPolygonManager : RCTViewManager

@end
38 changes: 38 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapPolygonManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// AIRGoogleMapPolylgoneManager.m
//
// Created by Nick Italiano on 10/22/16.
//
#import "AIRGoogleMapPolygonManager.h"

#import "RCTBridge.h"
#import "RCTConvert.h"
#import "RCTConvert+CoreLocation.h"
#import "RCTConvert+MoreMapKit.h"
#import "RCTEventDispatcher.h"
#import "UIView+React.h"
#import "RCTViewManager.h"
#import "AIRGoogleMapPolygon.h"

@interface AIRGoogleMapPolygonManager()

@end

@implementation AIRGoogleMapPolygonManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
AIRGoogleMapPolygon *polygon = [AIRGoogleMapPolygon new];
return polygon;
}

RCT_EXPORT_VIEW_PROPERTY(coordinates, AIRMapCoordinateArray)
RCT_EXPORT_VIEW_PROPERTY(fillColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(strokeWidth, double)
RCT_EXPORT_VIEW_PROPERTY(strokeColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(geodesic, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zIndex, int)

@end
22 changes: 22 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapPolyline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AIRGoogleMapPolyline.h
//
// Created by Nick Italiano on 10/22/16.
//
#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import "AIRMapCoordinate.h"
#import "AIRGoogleMapMarker.h"

@interface AIRGoogleMapPolyline : UIView

@property (nonatomic, strong) GMSPolyline* polyline;
@property (nonatomic, strong) NSArray<AIRMapCoordinate *> *coordinates;
@property (nonatomic, strong) UIColor *strokeColor;
@property (nonatomic, assign) double strokeWidth;
@property (nonatomic, assign) UIColor *fillColor;
@property (nonatomic, assign) BOOL geodesic;
@property (nonatomic, assign) NSString *title;
@property (nonatomic, assign) int zIndex;

@end
Loading

0 comments on commit 16f362b

Please sign in to comment.