summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLFeature.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLFeature.mm')
-rw-r--r--platform/darwin/src/MGLFeature.mm71
1 files changed, 33 insertions, 38 deletions
diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm
index ba2ea6e605..c1e0c312a0 100644
--- a/platform/darwin/src/MGLFeature.mm
+++ b/platform/darwin/src/MGLFeature.mm
@@ -1,5 +1,4 @@
#import "MGLFeature_Private.h"
-#import "MGLShapeCollectionFeature_Private.h"
#import "MGLPointAnnotation.h"
#import "MGLPolyline.h"
@@ -18,7 +17,7 @@
#import <mbgl/style/conversion/geojson.hpp>
#import <mapbox/geometry/feature.hpp>
-@interface MGLPointFeature () <MGLFeaturePrivate>
+@interface MGLPointFeature ()
@end
@implementation MGLPointFeature
@@ -34,13 +33,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
+- (mbgl::GeoJSON)geoJSONObject {
return mbglFeature({[self geometryObject]}, identifier, self.attributes);
}
@end
-@interface MGLPolylineFeature () <MGLFeaturePrivate>
+@interface MGLPolylineFeature ()
@end
@implementation MGLPolylineFeature
@@ -56,13 +55,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
+- (mbgl::GeoJSON)geoJSONObject {
return mbglFeature({[self geometryObject]}, identifier, self.attributes);
}
@end
-@interface MGLPolygonFeature () <MGLFeaturePrivate>
+@interface MGLPolygonFeature ()
@end
@implementation MGLPolygonFeature
@@ -78,13 +77,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
+- (mbgl::GeoJSON)geoJSONObject {
return mbglFeature({[self geometryObject]}, identifier, self.attributes);
}
@end
-@interface MGLPointCollectionFeature () <MGLFeaturePrivate>
+@interface MGLPointCollectionFeature ()
@end
@implementation MGLPointCollectionFeature
@@ -100,13 +99,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
+- (mbgl::GeoJSON)geoJSONObject {
return mbglFeature({[self geometryObject]}, identifier, self.attributes);
}
@end
-@interface MGLMultiPolylineFeature () <MGLFeaturePrivate>
+@interface MGLMultiPolylineFeature ()
@end
@implementation MGLMultiPolylineFeature
@@ -122,13 +121,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
+- (mbgl::GeoJSON)geoJSONObject {
return mbglFeature({[self geometryObject]}, identifier, self.attributes);
}
@end
-@interface MGLMultiPolygonFeature () <MGLFeaturePrivate>
+@interface MGLMultiPolygonFeature ()
@end
@implementation MGLMultiPolygonFeature
@@ -144,13 +143,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
+- (mbgl::GeoJSON)geoJSONObject {
return mbglFeature({[self geometryObject]}, identifier, self.attributes);
}
@end
-@interface MGLShapeCollectionFeature () <MGLFeaturePrivate>
+@interface MGLShapeCollectionFeature ()
@end
@implementation MGLShapeCollectionFeature
@@ -172,17 +171,13 @@
return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier);
}
-- (mbgl::Feature)mbglFeature {
- [NSException raise:@"Method unavailable" format:@"%s is not available on %@.", __PRETTY_FUNCTION__, [self class]];
- mbgl::Polygon<double> geometry;
- return mbgl::Feature{geometry};
-}
-
-- (mbgl::FeatureCollection)mbglFeatureCollection {
+- (mbgl::GeoJSON)geoJSONObject {
mbgl::FeatureCollection featureCollection;
featureCollection.reserve(self.shapes.count);
- for (id <MGLFeaturePrivate> feature in self.shapes) {
- featureCollection.push_back([feature mbglFeature]);
+ for (MGLShape <MGLFeature> *feature in self.shapes) {
+ auto geoJSONObject = feature.geoJSONObject;
+ NSAssert(geoJSONObject.is<mbgl::Feature>(), @"Feature collection must only contain features.");
+ featureCollection.push_back(geoJSONObject.get<mbgl::Feature>());
}
return featureCollection;
}
@@ -196,27 +191,27 @@
template <typename T>
class GeometryEvaluator {
public:
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Point<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::Point<T> &geometry) const {
MGLPointFeature *feature = [[MGLPointFeature alloc] init];
feature.coordinate = toLocationCoordinate2D(geometry);
return feature;
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::LineString<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::LineString<T> &geometry) const {
std::vector<CLLocationCoordinate2D> coordinates = toLocationCoordinates2D(geometry);
return [MGLPolylineFeature polylineWithCoordinates:&coordinates[0] count:coordinates.size()];
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Polygon<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::Polygon<T> &geometry) const {
return toShape<MGLPolygonFeature>(geometry);
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::MultiPoint<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::MultiPoint<T> &geometry) const {
std::vector<CLLocationCoordinate2D> coordinates = toLocationCoordinates2D(geometry);
return [[MGLPointCollectionFeature alloc] initWithCoordinates:&coordinates[0] count:coordinates.size()];
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::MultiLineString<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::MultiLineString<T> &geometry) const {
NSMutableArray *polylines = [NSMutableArray arrayWithCapacity:geometry.size()];
for (auto &lineString : geometry) {
std::vector<CLLocationCoordinate2D> coordinates = toLocationCoordinates2D(lineString);
@@ -227,7 +222,7 @@ public:
return [MGLMultiPolylineFeature multiPolylineWithPolylines:polylines];
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::MultiPolygon<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::MultiPolygon<T> &geometry) const {
NSMutableArray *polygons = [NSMutableArray arrayWithCapacity:geometry.size()];
for (auto &polygon : geometry) {
[polygons addObject:toShape(polygon)];
@@ -236,11 +231,11 @@ public:
return [MGLMultiPolygonFeature multiPolygonWithPolygons:polygons];
}
- MGLShape <MGLFeaturePrivate> * operator()(const mapbox::geometry::geometry_collection<T> &collection) const {
+ MGLShape <MGLFeature> * operator()(const mapbox::geometry::geometry_collection<T> &collection) const {
NSMutableArray *shapes = [NSMutableArray arrayWithCapacity:collection.size()];
for (auto &geometry : collection) {
// This is very much like the transformation that happens in MGLFeaturesFromMBGLFeatures(), but these are raw geometries with no associated feature IDs or attributes.
- MGLShape <MGLFeaturePrivate> *shape = mapbox::geometry::geometry<T>::visit(geometry, *this);
+ MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<T>::visit(geometry, *this);
[shapes addObject:shape];
}
return [MGLShapeCollectionFeature shapeCollectionWithShapes:shapes];
@@ -280,23 +275,23 @@ private:
template <typename T>
class GeoJSONEvaluator {
public:
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Geometry<T> &geometry) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::Geometry<T> &geometry) const {
GeometryEvaluator<T> evaluator;
- MGLShape <MGLFeaturePrivate> *shape = mapbox::geometry::geometry<T>::visit(geometry, evaluator);
+ MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<T>::visit(geometry, evaluator);
return shape;
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Feature &feature) const {
- MGLShape <MGLFeaturePrivate> *shape = (MGLShape <MGLFeaturePrivate> *)MGLFeatureFromMBGLFeature(feature);
+ MGLShape <MGLFeature> * operator()(const mbgl::Feature &feature) const {
+ MGLShape <MGLFeature> *shape = (MGLShape <MGLFeature> *)MGLFeatureFromMBGLFeature(feature);
return shape;
}
- MGLShape <MGLFeaturePrivate> * operator()(const mbgl::FeatureCollection &collection) const {
+ MGLShape <MGLFeature> * operator()(const mbgl::FeatureCollection &collection) const {
NSMutableArray *shapes = [NSMutableArray arrayWithCapacity:collection.size()];
for (const auto &feature : collection) {
[shapes addObject:MGLFeatureFromMBGLFeature(feature)];
}
- return [MGLShapeCollection<MGLFeaturePrivate> shapeCollectionWithShapes:shapes];
+ return [MGLShapeCollectionFeature shapeCollectionWithShapes:shapes];
}
};
@@ -316,7 +311,7 @@ id <MGLFeature> MGLFeatureFromMBGLFeature(const mbgl::Feature &feature) {
attributes[@(pair.first.c_str())] = mbgl::Value::visit(value, evaluator);
}
GeometryEvaluator<double> evaluator;
- MGLShape <MGLFeaturePrivate> *shape = mapbox::geometry::geometry<double>::visit(feature.geometry, evaluator);
+ MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<double>::visit(feature.geometry, evaluator);
if (feature.id) {
shape.identifier = mbgl::FeatureIdentifier::visit(*feature.id, ValueEvaluator());
}