Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Warn if MGLShapeSource is initialized with MGLShapeCollection #12625

Merged
merged 1 commit into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions platform/darwin/src/MGLComputedShapeSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "MGLSource_Private.h"
#import "MGLShape_Private.h"
#import "MGLGeometry_Private.h"
#import "MGLShapeCollection.h"

#include <mbgl/map/map.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>
Expand Down Expand Up @@ -131,6 +132,14 @@ - (void)main {
mbgl::FeatureCollection featureCollection;
featureCollection.reserve(data.count);
for (MGLShape <MGLFeature> * 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<mbgl::Feature>();
featureCollection.push_back(geoJsonObject);
}
Expand Down Expand Up @@ -196,6 +205,14 @@ - (void)setFeatures:(NSArray<MGLShape <MGLFeature> *>*)features inTileAtX:(NSUIn
for (MGLShape <MGLFeature> * feature in features) {
mbgl::Feature geoJsonObject = [feature geoJSONObject].get<mbgl::Feature>();
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<mbgl::style::CustomGeometrySource *>(self.rawSource)->setTileData(tileID, geojson);
Expand Down
1 change: 1 addition & 0 deletions platform/darwin/src/MGLShapeCollection.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "MGLShapeCollection.h"

#import "MGLShape_Private.h"
#import "MGLFeature.h"

#import <mbgl/style/conversion/geojson.hpp>

Expand Down
8 changes: 8 additions & 0 deletions platform/darwin/src/MGLShapeSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ - (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLSha
auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options);
auto source = std::make_unique<mbgl::style::GeoJSONSource>(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;
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down