summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLVectorSource.mm
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-10-26 17:08:27 -0700
committerGitHub <noreply@github.com>2016-10-26 17:08:27 -0700
commit67ffc9685e573b10e4761b0bdb9962c79139f5da (patch)
tree89215ac8c3bc212ea3cf4e569d48d10e999590e2 /platform/darwin/src/MGLVectorSource.mm
parent12093c10ad7557a92c8852bd6b61428990311dd4 (diff)
downloadqtlocation-mapboxgl-67ffc9685e573b10e4761b0bdb9962c79139f5da.tar.gz
[ios, macos] Make source ownership consistent and GeoJSON content properties writable
Use common initialization logic to create an unique pointer to an mbgl source object, up front, when a MGL source is created. Keep a raw pointer to the unique pointer that is pointed at the mbgl source instance when a MGL source is created or when a MGL source is obtained by identifier from MGLStyle. Once the transfer of ownership of the mbgl source takes place, the unique ptr is null. The raw pointer can be used internally for future work that involves mutating the source. This also changes the URL, features, and geoJSONData content properties for MGLGeoJSON source to be writable. If they are set with valid data after a source has been added to the map then the map will update to reflect the new data.
Diffstat (limited to 'platform/darwin/src/MGLVectorSource.mm')
-rw-r--r--platform/darwin/src/MGLVectorSource.mm22
1 files changed, 20 insertions, 2 deletions
diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm
index 3597812359..995565419f 100644
--- a/platform/darwin/src/MGLVectorSource.mm
+++ b/platform/darwin/src/MGLVectorSource.mm
@@ -1,12 +1,22 @@
#import "MGLVectorSource.h"
+#import "MGLMapView_Private.h"
#import "MGLSource_Private.h"
#import "MGLTileSet_Private.h"
#import "NSURL+MGLAdditions.h"
#include <mbgl/style/sources/vector_source.hpp>
+@interface MGLVectorSource ()
+
+@property (nonatomic) mbgl::style::VectorSource *rawSource;
+
+@end
+
@implementation MGLVectorSource
+{
+ std::unique_ptr<mbgl::style::VectorSource> _pendingSource;
+}
static NSString *MGLVectorSourceType = @"vector";
@@ -15,6 +25,7 @@ static NSString *MGLVectorSourceType = @"vector";
if (self = [super initWithIdentifier:identifier])
{
_URL = url;
+ [self commonInit];
}
return self;
}
@@ -24,11 +35,12 @@ static NSString *MGLVectorSourceType = @"vector";
if (self = [super initWithIdentifier:identifier])
{
_tileSet = tileSet;
+ [self commonInit];
}
return self;
}
-- (std::unique_ptr<mbgl::style::Source>)mbglSource
+- (void)commonInit
{
std::unique_ptr<mbgl::style::VectorSource> source;
@@ -43,7 +55,13 @@ static NSString *MGLVectorSourceType = @"vector";
self.tileSet.mbglTileset);
}
- return std::move(source);
+ _pendingSource = std::move(source);
+ self.rawSource = _pendingSource.get();
+}
+
+- (void)addToMapView:(MGLMapView *)mapView
+{
+ mapView.mbglMap->addSource(std::move(_pendingSource));
}
@end