summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLSource.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLSource.mm')
-rw-r--r--platform/darwin/src/MGLSource.mm27
1 files changed, 15 insertions, 12 deletions
diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm
index ee012f4d66..6d57e14e8c 100644
--- a/platform/darwin/src/MGLSource.mm
+++ b/platform/darwin/src/MGLSource.mm
@@ -1,7 +1,9 @@
#import "MGLSource_Private.h"
#import "MGLStyle_Private.h"
+#import "MGLMapView_Private.h"
#include <mbgl/style/style.hpp>
+#include <mbgl/map/map.hpp>
#include <mbgl/style/source.hpp>
@interface MGLSource ()
@@ -10,7 +12,7 @@
// special internal source types like mbgl::AnnotationSource.
@property (nonatomic, readonly) mbgl::style::Source *rawSource;
-@property (nonatomic, readonly, weak) MGLStyle *style;
+@property (nonatomic, readonly, weak) MGLMapView *mapView;
@end
@@ -27,37 +29,38 @@
return self;
}
-- (instancetype)initWithRawSource:(mbgl::style::Source *)rawSource {
+- (instancetype)initWithRawSource:(mbgl::style::Source *)rawSource mapView:(MGLMapView *)mapView {
NSString *identifier = @(rawSource->getID().c_str());
if (self = [self initWithIdentifier:identifier]) {
_rawSource = rawSource;
_rawSource->peer = SourceWrapper { self };
+ _mapView = mapView;
}
return self;
}
- (instancetype)initWithPendingSource:(std::unique_ptr<mbgl::style::Source>)pendingSource {
- if (self = [self initWithRawSource:pendingSource.get()]) {
+ if (self = [self initWithRawSource:pendingSource.get() mapView:nil]) {
_pendingSource = std::move(pendingSource);
}
return self;
}
-- (void)addToStyle:(MGLStyle *)style {
+- (void)addToMapView:(MGLMapView *)mapView {
if (_pendingSource == nullptr) {
[NSException raise:@"MGLRedundantSourceException"
format:@"This instance %@ was already added to %@. Adding the same source instance " \
- "to the style more than once is invalid.", self, style];
+ "to the style more than once is invalid.", self, mapView.style];
}
-
- _style = style;
- style.rawStyle->addSource(std::move(_pendingSource));
+
+ _mapView = mapView;
+ _mapView.style.rawStyle->addSource(std::move(_pendingSource));
}
-- (void)removeFromStyle:(MGLStyle *)style {
- if (self.rawSource == style.rawStyle->getSource(self.identifier.UTF8String)) {
- _pendingSource = style.rawStyle->removeSource(self.identifier.UTF8String);
- _style = nil;
+- (void)removeFromMapView:(MGLMapView *)mapView {
+ if (self.rawSource == mapView.style.rawStyle->getSource(self.identifier.UTF8String)) {
+ _pendingSource = mapView.style.rawStyle->removeSource(self.identifier.UTF8String);
+ _mapView = nil;
}
}