diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-11-06 16:11:47 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-11-13 17:28:26 +0200 |
commit | bf8b24fa8d30df374ee36be781b6a572036187b9 (patch) | |
tree | bdca15eef94898a879e4f3737eee2dc44efa275f /platform | |
parent | 4e15a0c8cd7c906908d97da10f75b35a3bc2ed9e (diff) | |
download | qtlocation-mapboxgl-bf8b24fa8d30df374ee36be781b6a572036187b9.tar.gz |
[build] Update to geometry v1.0.0
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/src/geojson/feature.cpp | 15 | ||||
-rw-r--r-- | platform/android/src/geojson/geometry.cpp | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLFeature.h | 8 | ||||
-rw-r--r-- | platform/darwin/src/MGLFeature.mm | 45 | ||||
-rw-r--r-- | platform/darwin/test/MGLFeatureTests.mm | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapAccessibilityElement.h | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 6 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 8 | ||||
-rw-r--r-- | platform/node/src/node_feature.cpp | 8 |
9 files changed, 81 insertions, 20 deletions
diff --git a/platform/android/src/geojson/feature.cpp b/platform/android/src/geojson/feature.cpp index 767b145a89..8d30404a50 100644 --- a/platform/android/src/geojson/feature.cpp +++ b/platform/android/src/geojson/feature.cpp @@ -18,11 +18,12 @@ mbgl::Feature Feature::convert(jni::JNIEnv& env, const jni::Object<Feature>& jFe auto jId = jFeature.Call(env, id); + using mbid = mapbox::feature::identifier; + return mbgl::Feature { Geometry::convert(env, jFeature.Call(env, geometry)), JsonObject::convert(env, jFeature.Call(env, properties)), - jId ? std::experimental::optional<mapbox::geometry::identifier>(jni::Make<std::string>(env, jId)) - : std::experimental::nullopt + jId ? mbid { jni::Make<std::string>(env, jId) } : mbid { mapbox::feature::null_value } }; } @@ -41,7 +42,11 @@ public: } std::string operator()(const std::nullptr_t&) const { - return ""; + return {}; + } + + std::string operator()(const mapbox::feature::null_value_t&) const { + return {}; } }; @@ -52,7 +57,7 @@ jni::Local<jni::Object<Feature>> convertFeature(jni::JNIEnv& env, const mbgl::Fe return javaClass.Call(env, method, Geometry::New(env, value.geometry), JsonObject::New(env, value.properties), - jni::Make<jni::String>(env, value.id ? value.id.value().match(FeatureIdVisitor()) : "")); + jni::Make<jni::String>(env, value.id.is<mbgl::NullValue>() ? std::string {} : value.id.match(FeatureIdVisitor()))); } jni::Local<jni::Array<jni::Object<Feature>>> Feature::convert(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) { @@ -71,4 +76,4 @@ void Feature::registerNative(jni::JNIEnv& env) { } // namespace geojson } // namespace android -} // namespace mbgl
\ No newline at end of file +} // namespace mbgl diff --git a/platform/android/src/geojson/geometry.cpp b/platform/android/src/geojson/geometry.cpp index 2356af780a..0598b9fc59 100644 --- a/platform/android/src/geojson/geometry.cpp +++ b/platform/android/src/geojson/geometry.cpp @@ -22,6 +22,11 @@ public: jni::JNIEnv& env; + jni::Local<jni::Object<Geometry>> operator()(const mbgl::EmptyGeometry &) const { + // FIXME: mapbox-java needs to have its own Empty type. + return GeometryCollection::New(env, {}); + } + jni::Local<jni::Object<Geometry>> operator()(const mbgl::Point<double> &geometry) const { return Point::New(env, geometry); } @@ -89,4 +94,4 @@ void Geometry::registerNative(jni::JNIEnv &env) { } // namespace geojson } // namespace android -} // namespace mbgl
\ No newline at end of file +} // namespace mbgl diff --git a/platform/darwin/src/MGLFeature.h b/platform/darwin/src/MGLFeature.h index 62471abb16..430bf58f92 100644 --- a/platform/darwin/src/MGLFeature.h +++ b/platform/darwin/src/MGLFeature.h @@ -172,6 +172,14 @@ NS_ASSUME_NONNULL_BEGIN @end /** + An `MGLEmptyFeature` object associates an empty shape with an optional + identifier and attributes. + */ +MGL_EXPORT +@interface MGLEmptyFeature : MGLShape <MGLFeature> +@end + +/** An `MGLPointFeature` object associates a point shape with an optional identifier and attributes. */ diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm index 02f67dca6e..be327a23ab 100644 --- a/platform/darwin/src/MGLFeature.mm +++ b/platform/darwin/src/MGLFeature.mm @@ -16,7 +16,41 @@ #import <mbgl/util/geometry.hpp> #import <mbgl/style/conversion/geojson.hpp> -#import <mapbox/geometry/feature.hpp> +#import <mapbox/feature.hpp> + +@interface MGLEmptyFeature () +@end + +@implementation MGLEmptyFeature + +@synthesize identifier; +@synthesize attributes; + +MGL_DEFINE_FEATURE_INIT_WITH_CODER(); +MGL_DEFINE_FEATURE_ENCODE(); +MGL_DEFINE_FEATURE_IS_EQUAL(); + +- (id)attributeForKey:(NSString *)key { + return self.attributes[key]; +} + +- (NSDictionary *)geoJSONDictionary { + return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); +} + +- (mbgl::GeoJSON)geoJSONObject { + return mbglFeature({[self geometryObject]}, identifier, self.attributes); +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@, attributes = %@>", + NSStringFromClass([self class]), (void *)self, + self.identifier ? [NSString stringWithFormat:@"\"%@\"", self.identifier] : self.identifier, + self.attributes.count ? self.attributes : @"none"]; +} + +@end @interface MGLPointFeature () @end @@ -269,6 +303,11 @@ MGL_DEFINE_FEATURE_IS_EQUAL(); template <typename T> class GeometryEvaluator { public: + MGLShape <MGLFeature> * operator()(const mbgl::EmptyGeometry &) const { + MGLEmptyFeature *feature = [[MGLEmptyFeature alloc] init]; + return feature; + } + MGLShape <MGLFeature> * operator()(const mbgl::Point<T> &geometry) const { MGLPointFeature *feature = [[MGLPointFeature alloc] init]; feature.coordinate = toLocationCoordinate2D(geometry); @@ -390,8 +429,8 @@ id <MGLFeature> MGLFeatureFromMBGLFeature(const mbgl::Feature &feature) { } GeometryEvaluator<double> evaluator; MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<double>::visit(feature.geometry, evaluator); - if (feature.id) { - shape.identifier = mbgl::FeatureIdentifier::visit(*feature.id, ValueEvaluator()); + if (!feature.id.is<mapbox::feature::null_value_t>()) { + shape.identifier = mbgl::FeatureIdentifier::visit(feature.id, ValueEvaluator()); } shape.attributes = attributes; diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm index d135b018f4..cf57d0b4b6 100644 --- a/platform/darwin/test/MGLFeatureTests.mm +++ b/platform/darwin/test/MGLFeatureTests.mm @@ -91,7 +91,7 @@ mbgl::Point<double> point = { -90.066667, 29.95 }; mbgl::Feature pointFeature { point }; pointFeature.id = { UINT64_MAX }; - pointFeature.properties["null"] = mapbox::geometry::null_value; + pointFeature.properties["null"] = mapbox::feature::null_value; pointFeature.properties["bool"] = true; pointFeature.properties["unsigned int"] = UINT64_MAX; pointFeature.properties["int"] = INT64_MIN; diff --git a/platform/ios/src/MGLMapAccessibilityElement.h b/platform/ios/src/MGLMapAccessibilityElement.h index 952f6cbf2f..6c5fad62ce 100644 --- a/platform/ios/src/MGLMapAccessibilityElement.h +++ b/platform/ios/src/MGLMapAccessibilityElement.h @@ -7,7 +7,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; /// Unique identifier representing a single annotation in mbgl. -typedef uint32_t MGLAnnotationTag; +typedef uint64_t MGLAnnotationTag; /** An accessibility element representing something that appears on the map. */ MGL_EXPORT diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index bcd1e07ef8..a7046e2505 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1770,7 +1770,7 @@ public: if (hitAnnotationTag != _selectedAnnotationTag) { id <MGLAnnotation> annotation = [self annotationWithTag:hitAnnotationTag]; - NSAssert(annotation, @"Cannot select nonexistent annotation with tag %u", hitAnnotationTag); + NSAssert(annotation, @"Cannot select nonexistent annotation with tag %llu", hitAnnotationTag); return annotation; } } @@ -2666,7 +2666,7 @@ public: */ - (id)accessibilityElementForAnnotationWithTag:(MGLAnnotationTag)annotationTag { - NSAssert(_annotationContextsByAnnotationTag.count(annotationTag), @"Missing annotation for tag %u.", annotationTag); + NSAssert(_annotationContextsByAnnotationTag.count(annotationTag), @"Missing annotation for tag %llu.", annotationTag); MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); id <MGLAnnotation> annotation = annotationContext.annotation; @@ -3667,7 +3667,7 @@ public: } MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); - NSAssert(annotationContext.annotation, @"Missing annotation for tag %u.", annotationTag); + NSAssert(annotationContext.annotation, @"Missing annotation for tag %llu.", annotationTag); if (annotationContext.annotation) { [annotations addObject:annotationContext.annotation]; diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 9f9bb855d2..a1a5e8c2ab 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -102,10 +102,10 @@ const CGFloat MGLAnnotationImagePaddingForCallout = 4; const NSEdgeInsets MGLMapViewOffscreenAnnotationPadding = NSEdgeInsetsMake(-30.0f, -30.0f, -30.0f, -30.0f); /// Unique identifier representing a single annotation in mbgl. -typedef uint32_t MGLAnnotationTag; +typedef uint64_t MGLAnnotationTag; /// An indication that the requested annotation was not found or is nonexistent. -enum { MGLAnnotationTagNotFound = UINT32_MAX }; +enum { MGLAnnotationTagNotFound = UINT64_MAX }; /// Mapping from an annotation tag to metadata about that annotation, including /// the annotation itself. @@ -1520,7 +1520,7 @@ public: if (hitAnnotationTag != MGLAnnotationTagNotFound) { if (hitAnnotationTag != _selectedAnnotationTag) { id <MGLAnnotation> annotation = [self annotationWithTag:hitAnnotationTag]; - NSAssert(annotation, @"Cannot select nonexistent annotation with tag %u", hitAnnotationTag); + NSAssert(annotation, @"Cannot select nonexistent annotation with tag %llu", hitAnnotationTag); [self selectAnnotation:annotation atPoint:gesturePoint]; } } else { @@ -1843,7 +1843,7 @@ public: } MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); - NSAssert(annotationContext.annotation, @"Missing annotation for tag %u.", annotationTag); + NSAssert(annotationContext.annotation, @"Missing annotation for tag %llu.", annotationTag); if (annotationContext.annotation) { [annotations addObject:annotationContext.annotation]; diff --git a/platform/node/src/node_feature.cpp b/platform/node/src/node_feature.cpp index e5333f1b76..ee1cdab031 100644 --- a/platform/node/src/node_feature.cpp +++ b/platform/node/src/node_feature.cpp @@ -14,6 +14,10 @@ using Properties = mbgl::PropertyMap; template <class T> struct ToType { public: + v8::Local<v8::String> operator()(const empty&) { + return type("Empty"); + } + v8::Local<v8::String> operator()(const point<T>&) { return type("Point"); } @@ -159,8 +163,8 @@ v8::Local<v8::Object> toJS(const Feature& feature) { Nan::Set(result, Nan::New("geometry").ToLocalChecked(), toJS(feature.geometry)); Nan::Set(result, Nan::New("properties").ToLocalChecked(), toJS(feature.properties)); - if (feature.id) { - Nan::Set(result, Nan::New("id").ToLocalChecked(), FeatureIdentifier::visit(*feature.id, ToValue())); + if (!feature.id.is<mbgl::NullValue>()) { + Nan::Set(result, Nan::New("id").ToLocalChecked(), FeatureIdentifier::visit(feature.id, ToValue())); } return scope.Escape(result); |