From 50059659d100759978c8bebb04ac7beb9e6d618f Mon Sep 17 00:00:00 2001 From: Nadia Barbosa Date: Mon, 13 Aug 2018 17:24:56 -0700 Subject: Warn if MGLShapeSource is initialized with MGLShapeCollection Move warning from ShapeCollection to ShapeSource Try checking MGLComputedShapeSources Include MGLShapeCollection header Add changelog entry --- platform/darwin/src/MGLComputedShapeSource.mm | 17 +++++++++++++++++ platform/darwin/src/MGLShapeCollection.mm | 1 + platform/darwin/src/MGLShapeSource.mm | 8 ++++++++ platform/ios/CHANGELOG.md | 1 + 4 files changed, 27 insertions(+) diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index 609db7f399..0493131922 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -4,6 +4,7 @@ #import "MGLSource_Private.h" #import "MGLShape_Private.h" #import "MGLGeometry_Private.h" +#import "MGLShapeCollection.h" #include #include @@ -131,6 +132,14 @@ mbgl::style::CustomGeometrySource::Options MBGLCustomGeometrySourceOptionsFromDi mbgl::FeatureCollection featureCollection; featureCollection.reserve(data.count); for (MGLShape * feature in data) { + if ([feature isMemberOfClass:[MGLShapeCollection class]]) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSLog(@"MGLShapeCollection initialized with MGLFeatures will not retain attributes." + @"Use MGLShapeCollectionFeature to retain attributes instead." + @"This will be logged only once."); + }); + } mbgl::Feature geoJsonObject = [feature geoJSONObject].get(); featureCollection.push_back(geoJsonObject); } @@ -196,6 +205,14 @@ mbgl::style::CustomGeometrySource::Options MBGLCustomGeometrySourceOptionsFromDi for (MGLShape * feature in features) { mbgl::Feature geoJsonObject = [feature geoJSONObject].get(); featureCollection.push_back(geoJsonObject); + if ([feature isMemberOfClass:[MGLShapeCollection class]]) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSLog(@"MGLShapeCollection initialized with MGLFeatures will not retain attributes." + @"Use MGLShapeCollectionFeature to retain attributes instead." + @"This will be logged only once."); + }); + } } const auto geojson = mbgl::GeoJSON{featureCollection}; static_cast(self.rawSource)->setTileData(tileID, geojson); diff --git a/platform/darwin/src/MGLShapeCollection.mm b/platform/darwin/src/MGLShapeCollection.mm index 74e78a764a..5db1ee335c 100644 --- a/platform/darwin/src/MGLShapeCollection.mm +++ b/platform/darwin/src/MGLShapeCollection.mm @@ -1,6 +1,7 @@ #import "MGLShapeCollection.h" #import "MGLShape_Private.h" +#import "MGLFeature.h" #import diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 1425269012..9457d2569a 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -105,6 +105,14 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary(identifier.UTF8String, geoJSONOptions); if (self = [super initWithPendingSource:std::move(source)]) { + if ([shape isMemberOfClass:[MGLShapeCollection class]]) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSLog(@"MGLShapeCollection initialized with MGLFeatures will not retain attributes." + @"Use MGLShapeCollectionFeature to retain attributes instead." + @"This will be logged only once."); + }); + } self.shape = shape; } return self; diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index edebf57dc6..d4254554d1 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -9,6 +9,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * The `-[MGLMapView visibleFeaturesAtPoint:]` method can now return features near tile boundaries at high zoom levels. ([#12570](https://github.com/mapbox/mapbox-gl-native/pull/12570)) * Fixed inconsistencies in exception naming. ([#12583](https://github.com/mapbox/mapbox-gl-native/issues/12583)) * Added `MGLShapeOfflineRegion` for defining arbitrarily shaped offline regions [#11447](https://github.com/mapbox/mapbox-gl-native/pull/11447) +* Added a one-time warning about possible attribute loss when initializing an `MGLShapeSource` with an `MGLShapeCollection` [#12625](https://github.com/mapbox/mapbox-gl-native/pull/12625) ## 4.3.0 - August 15, 2018 -- cgit v1.2.1