Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapPolygon should support polygon hole #791

Closed
therealgilles opened this issue Nov 12, 2016 · 5 comments
Closed

MapPolygon should support polygon hole #791

therealgilles opened this issue Nov 12, 2016 · 5 comments

Comments

@therealgilles
Copy link
Contributor

Apple Maps MkPolygon has support for interiorPolygons:
https://developer.apple.com/reference/mapkit/mkpolygon

Google Maps has support for polygon hole with an array of arrays in paths in google.maps.Polygon:
https://developers.google.com/maps/documentation/javascript/examples/polygon-hole

How can I get support for these in react-native-maps? Thank you

@therealgilles
Copy link
Contributor Author

I've taken a stab at adding support for polygon holes for Google Maps on iOS. The changes below seem to work.

+++ b/traveller/ios/AirGoogleMaps/AIRGoogleMapPolygon.h
 @property (nonatomic, strong) NSArray<AIRMapCoordinate *> *coordinates;
+@property (nonatomic, strong) NSArray<NSArray<AIRMapCoordinate *> *> *holes;
+++ b/traveller/ios/AirGoogleMaps/AIRGoogleMapPolygon.m
   _polygon.path = path;
 }

+- (void)setHoles:(NSArray<NSArray<AIRMapCoordinate *> *> *)holes
+{
+  _holes = holes;
+
+  NSMutableArray<GMSMutablePath *> *interiorPolygons = [NSMutableArray array];
+  for(int h = 0; h < holes.count; h++)
+  {
+    // NSArray<AIRMapCoordinate *> *coordinates = [NSArray<AIRMapCoordinate *> coordinates];
+    // coordinates = holes[h];
+
+    // create path for interior polygon
+    GMSMutablePath *path = [GMSMutablePath path];
+    for(int i = 0; i < holes[h].count; i++)
+    {
+      [path addCoordinate:holes[h][i].coordinate];
+    }
+
+    // add path to holes array
+    [interiorPolygons addObject:path];
+  }
+
+  _polygon.holes = interiorPolygons;
+}
+
 -(void)setFillColor:(UIColor *)fillColor
+++ b/traveller/ios/AirGoogleMaps/AIRGoogleMapPolygonManager.m
 RCT_EXPORT_VIEW_PROPERTY(coordinates, AIRMapCoordinateArray)
+RCT_EXPORT_VIEW_PROPERTY(holes, AIRMapCoordinateArrayArray)
+++ b/traveller/ios/AirMaps/AIRMapPolygon.h
 @property (nonatomic, strong) NSArray<AIRMapCoordinate *> *coordinates;
+//@property (nonatomic, strong) NSArray *interiorPolygons;
+++ b/traveller/ios/AirMaps/RCTConvert+MoreMapKit.m 
 RCT_ARRAY_CONVERTER(AIRMapCoordinate)

++ (NSArray<NSArray<AIRMapCoordinate *> *> *)AIRMapCoordinateArrayArray:(id)json
+{
+    return RCTConvertArrayValue(@selector(AIRMapCoordinateArray:), json);
+}
+

@therealgilles
Copy link
Contributor Author

Forgot this one in Components/MapPolygon.js:

   longitude: PropTypes.number.isRequired,
  })),
+
+  holes: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.shape({
+    /**
+     * Latitude/Longitude coordinates
+     */
+    latitude: PropTypes.number.isRequired,
+    longitude: PropTypes.number.isRequired,
+  }))),

@therealgilles
Copy link
Contributor Author

therealgilles commented Nov 14, 2016

See pull request #801 (iOS only).

@prjmax
Copy link

prjmax commented Jul 16, 2017

Is this feature going to be available for Android as well?

@alvelig
Copy link
Contributor

alvelig commented Jan 19, 2018

@prjmax see #1781. It was merged finally!

@alvelig alvelig closed this as completed Jan 19, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants