mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-27 11:01:13 +00:00
refactored getting polygon and polyline coordinate arrays into 2 new categories
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
C5DBB3461AF2EF2B00E611A9 /* RCTMapboxGL.m in Sources */ = {isa = PBXBuildFile; fileRef = C5DBB3451AF2EF2B00E611A9 /* RCTMapboxGL.m */; };
|
||||
C5DBB34C1AF2EF2B00E611A9 /* libRCTMapboxGL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C5DBB3401AF2EF2B00E611A9 /* libRCTMapboxGL.a */; };
|
||||
C5DBB3661AF2EFB500E611A9 /* RCTMapboxGLManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C5DBB3651AF2EFB500E611A9 /* RCTMapboxGLManager.m */; };
|
||||
CB7CB11F1F5092CD30562E07 /* MGLPolyline+RCTAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CB7CBE434C8597B1509C3FCA /* MGLPolyline+RCTAdditions.m */; };
|
||||
CB7CB49F42C4A55593F71A37 /* MGLPolygon+RCTAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CB7CBC07803C0F5C28ECB201 /* MGLPolygon+RCTAdditions.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -47,6 +49,10 @@
|
||||
C5DBB3511AF2EF2B00E611A9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
C5DBB3641AF2EFB500E611A9 /* RCTMapboxGLManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMapboxGLManager.h; sourceTree = "<group>"; };
|
||||
C5DBB3651AF2EFB500E611A9 /* RCTMapboxGLManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMapboxGLManager.m; sourceTree = "<group>"; };
|
||||
CB7CB655DADBFA72D7B5EB33 /* MGLPolygon+RCTAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+RCTAdditions.h"; sourceTree = "<group>"; };
|
||||
CB7CBC07803C0F5C28ECB201 /* MGLPolygon+RCTAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+RCTAdditions.m"; sourceTree = "<group>"; };
|
||||
CB7CBC3A586F235841D94946 /* MGLPolyline+RCTAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolyline+RCTAdditions.h"; sourceTree = "<group>"; };
|
||||
CB7CBE434C8597B1509C3FCA /* MGLPolyline+RCTAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+RCTAdditions.m"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -95,6 +101,10 @@
|
||||
C5DBB3651AF2EFB500E611A9 /* RCTMapboxGLManager.m */,
|
||||
C167F89A1D18111F007C7A42 /* RCTMapboxGLConversions.h */,
|
||||
C167F89B1D18112B007C7A42 /* RCTMapboxGLConversions.m */,
|
||||
CB7CBE434C8597B1509C3FCA /* MGLPolyline+RCTAdditions.m */,
|
||||
CB7CBC3A586F235841D94946 /* MGLPolyline+RCTAdditions.h */,
|
||||
CB7CBC07803C0F5C28ECB201 /* MGLPolygon+RCTAdditions.m */,
|
||||
CB7CB655DADBFA72D7B5EB33 /* MGLPolygon+RCTAdditions.h */,
|
||||
);
|
||||
path = RCTMapboxGL;
|
||||
sourceTree = "<group>";
|
||||
@@ -206,6 +216,8 @@
|
||||
C5DBB3461AF2EF2B00E611A9 /* RCTMapboxGL.m in Sources */,
|
||||
C5DBB3661AF2EFB500E611A9 /* RCTMapboxGLManager.m in Sources */,
|
||||
C167F89C1D18112B007C7A42 /* RCTMapboxGLConversions.m in Sources */,
|
||||
CB7CB11F1F5092CD30562E07 /* MGLPolyline+RCTAdditions.m in Sources */,
|
||||
CB7CB49F42C4A55593F71A37 /* MGLPolygon+RCTAdditions.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Mapbox/Mapbox.h>
|
||||
|
||||
@interface MGLPolygon (RCTAdditions)
|
||||
- (NSMutableArray *)coordinateArray;
|
||||
@end
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MGLPolygon+RCTAdditions.h"
|
||||
|
||||
|
||||
@implementation MGLPolygon (RCTAdditions)
|
||||
|
||||
- (NSMutableArray *)coordinateArray
|
||||
{
|
||||
NSMutableArray *coordinates = [[NSMutableArray alloc] init];
|
||||
|
||||
NSMutableArray *outerRingCoordinates = [[NSMutableArray alloc] init];
|
||||
for (int index = 0; index < self.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = self.coordinates[index];
|
||||
[outerRingCoordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
}
|
||||
[coordinates addObject:outerRingCoordinates];
|
||||
|
||||
for (MGLPolygon *interiorRing in self.interiorPolygons) {
|
||||
NSMutableArray *interiorRingCoordinates = [[NSMutableArray alloc] init];
|
||||
for (int index = 0; index < interiorRing.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = interiorRing.coordinates[index];
|
||||
[interiorRingCoordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
}
|
||||
[coordinates addObject:interiorRingCoordinates];
|
||||
}
|
||||
return coordinates;
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Mapbox/Mapbox.h>
|
||||
|
||||
@interface MGLPolyline (RCTAdditions)
|
||||
- (NSMutableArray *)coordinateArray;
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MGLPolyline+RCTAdditions.h"
|
||||
|
||||
|
||||
@implementation MGLPolyline (RCTAdditions)
|
||||
|
||||
- (NSMutableArray *)coordinateArray
|
||||
{
|
||||
NSMutableArray *coordinates = [[NSMutableArray alloc] init];
|
||||
for (int index = 0; index < self.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = self.coordinates[index];
|
||||
[coordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
}
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -16,6 +16,8 @@
|
||||
#import "UIView+React.h"
|
||||
#import "RCTUIManager.h"
|
||||
#import "RCTMapboxGLConversions.h"
|
||||
#import "MGLPolygon+RCTAdditions.h"
|
||||
#import "MGLPolyline+RCTAdditions.h"
|
||||
|
||||
@implementation RCTMapboxGLManager
|
||||
|
||||
@@ -643,7 +645,7 @@ RCT_EXPORT_METHOD(queryRenderedFeatures:(nonnull NSNumber *)reactTag
|
||||
features = [mapView visibleFeaturesInRect:rect inStyleLayersWithIdentifiers:styleLayerIdentifiers];
|
||||
}
|
||||
|
||||
NSMutableArray *geoJSONFeatures = [[NSMutableArray alloc] init];
|
||||
NSMutableArray *geoJSONFeatures = [NSMutableArray arrayWithCapacity:features.count];
|
||||
for (id <MGLFeature> feature in features) {
|
||||
NSDictionary *geoJSONGeometry = [self geoJSONGeometryFromMGLFeature:feature];
|
||||
NSDictionary *geoJSON = @{ @"type": @"Feature",
|
||||
@@ -677,26 +679,26 @@ RCT_EXPORT_METHOD(queryRenderedFeatures:(nonnull NSNumber *)reactTag
|
||||
|
||||
if ([feature isKindOfClass:[MGLPointFeature class]]) {
|
||||
geometryType = @"Point";
|
||||
coordinates = (NSMutableArray *) @[@(feature.coordinate.longitude), @(feature.coordinate.latitude)];
|
||||
coordinates = [[NSMutableArray alloc] initWithArray:@[@(feature.coordinate.longitude), @(feature.coordinate.latitude)]];
|
||||
} else if ([feature isKindOfClass:[MGLPolylineFeature class]]) {
|
||||
geometryType = @"LineString";
|
||||
MGLPolylineFeature *polyline = (MGLPolylineFeature *)feature;
|
||||
coordinates = [self getMGLPolylineCoordinates:polyline];
|
||||
coordinates = polyline.coordinateArray;
|
||||
} else if ([feature isKindOfClass:[MGLPolygonFeature class]]) {
|
||||
geometryType = @"Polygon";
|
||||
MGLPolygonFeature *polygon = (MGLPolygonFeature *)feature;
|
||||
coordinates = [self getMGLPolygonCoordinates:polygon];
|
||||
coordinates = polygon.coordinateArray;
|
||||
} else if ([feature isKindOfClass:[MGLMultiPolylineFeature class]]) {
|
||||
geometryType = @"MultiLineString";
|
||||
MGLMultiPolylineFeature *multiPolyline = (MGLMultiPolylineFeature *)feature;
|
||||
for (MGLPolylineFeature *polyline in multiPolyline.polylines) {
|
||||
[coordinates addObject:[self getMGLPolylineCoordinates:polyline]];
|
||||
for (MGLPolyline *polyline in multiPolyline.polylines) {
|
||||
[coordinates addObject:polyline.coordinateArray];
|
||||
}
|
||||
} else if ([feature isKindOfClass:[MGLMultiPolygonFeature class]]) {
|
||||
geometryType = @"MultiPolygon";
|
||||
MGLMultiPolygonFeature *multiPolygon = (MGLMultiPolygonFeature *)feature;
|
||||
for (MGLPolygonFeature *polygon in multiPolygon.polygons) {
|
||||
[coordinates addObject:[self getMGLPolygonCoordinates:polygon]];
|
||||
for (MGLPolygon *polygon in multiPolygon.polygons) {
|
||||
[coordinates addObject:polygon.coordinateArray];
|
||||
}
|
||||
} else if ([feature isKindOfClass:[MGLMultiPointFeature class]]) {
|
||||
// this is checked last since MGLPolyline and MGLPolygon inherit from MGLMultiPoint
|
||||
@@ -704,7 +706,7 @@ RCT_EXPORT_METHOD(queryRenderedFeatures:(nonnull NSNumber *)reactTag
|
||||
MGLMultiPointFeature *multiPoint = (MGLMultiPointFeature *)feature;
|
||||
for (int index = 0; index < multiPoint.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = multiPoint.coordinates[index];
|
||||
[coordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
[coordinates addObject:[[NSMutableArray alloc] initWithArray:@[@(coord.longitude), @(coord.latitude)]]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,36 +714,4 @@ RCT_EXPORT_METHOD(queryRenderedFeatures:(nonnull NSNumber *)reactTag
|
||||
@"coordinates": coordinates };
|
||||
}
|
||||
|
||||
- (NSMutableArray *)getMGLPolylineCoordinates:(MGLPolylineFeature *)polyline
|
||||
{
|
||||
NSMutableArray *coordinates = [[NSMutableArray alloc] init];
|
||||
for (int index = 0; index < polyline.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = polyline.coordinates[index];
|
||||
[coordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
}
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)getMGLPolygonCoordinates:(MGLPolygonFeature *)polygon
|
||||
{
|
||||
NSMutableArray *coordinates = [[NSMutableArray alloc] init];
|
||||
|
||||
NSMutableArray *outerRingCoordinates = [[NSMutableArray alloc] init];
|
||||
for (int index = 0; index < polygon.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = polygon.coordinates[index];
|
||||
[outerRingCoordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
}
|
||||
[coordinates addObject:outerRingCoordinates];
|
||||
|
||||
for (MGLPolygonFeature *interiorRing in polygon.interiorPolygons) {
|
||||
NSMutableArray *interiorRingCoordinates = [[NSMutableArray alloc] init];
|
||||
for (int index = 0; index < interiorRing.pointCount; index++) {
|
||||
CLLocationCoordinate2D coord = interiorRing.coordinates[index];
|
||||
[interiorRingCoordinates addObject:@[@(coord.longitude), @(coord.latitude)]];
|
||||
}
|
||||
[coordinates addObject:interiorRingCoordinates];
|
||||
}
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user