summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLShape.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLShape.mm')
-rw-r--r--platform/darwin/src/MGLShape.mm52
1 files changed, 45 insertions, 7 deletions
diff --git a/platform/darwin/src/MGLShape.mm b/platform/darwin/src/MGLShape.mm
index e3d92c38c8..889ef8b3d7 100644
--- a/platform/darwin/src/MGLShape.mm
+++ b/platform/darwin/src/MGLShape.mm
@@ -1,14 +1,52 @@
-#import "MGLShape.h"
+#import "MGLShape_Private.h"
+
+#import "MGLFeature_Private.h"
@implementation MGLShape
-- (CLLocationCoordinate2D)coordinate
-{
- [[NSException exceptionWithName:@"MGLAbstractClassException"
- reason:@"MGLShape is an abstract class"
- userInfo:nil] raise];
++ (nullable MGLShape *)shapeWithData:(NSData *)data encoding:(NSStringEncoding)encoding error:(NSError * _Nullable *)outError {
+ NSString *string = [[NSString alloc] initWithData:data encoding:encoding];
+ if (!string) {
+ if (outError) {
+ *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:nil];
+ }
+ return nil;
+ }
+
+ try {
+ const auto geojson = mapbox::geojson::parse(string.UTF8String);
+ return MGLShapeFromGeoJSON(geojson);
+ } catch (std::runtime_error &err) {
+ if (outError) {
+ *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
+ NSLocalizedFailureReasonErrorKey: @(err.what()),
+ }];
+ }
+ return nil;
+ }
+}
+
+- (mbgl::GeoJSON)geoJSONObject {
+ return self.geometryObject;
+}
+
+- (mbgl::Geometry<double>)geometryObject {
+ [NSException raise:@"MGLAbstractClassException"
+ format:@"MGLShape is an abstract class"];
+ return mbgl::Point<double>();
+}
+
+- (NSData *)geoJSONDataUsingEncoding:(NSStringEncoding)encoding {
+ auto geometry = self.geoJSONObject;
+ NSString *string = @(mapbox::geojson::stringify(geometry).c_str());
+ return [string dataUsingEncoding:NSUTF8StringEncoding];
+}
+
+- (CLLocationCoordinate2D)coordinate {
+ [NSException raise:@"MGLAbstractClassException"
+ format:@"MGLShape is an abstract class"];
- return CLLocationCoordinate2DMake(MAXFLOAT, MAXFLOAT);
+ return kCLLocationCoordinate2DInvalid;
}
@end