# Conflicts: # cmake/core-files.cmake # include/mbgl/renderer/renderer_backend.hpp # platform/android/CHANGELOG.md # platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java # platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java # platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java # platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java # platform/android/dependencies.gradle # platform/darwin/src/MGLStyle.mm # platform/ios/CHANGELOG.md # platform/ios/app/Info.plist # platform/ios/app/MBXViewController.m # platform/ios/ios.xcodeproj/project.pbxproj # platform/macos/CHANGELOG.md # src/mbgl/gl/attribute.cpp # src/mbgl/gl/attribute.hpp # src/mbgl/gl/context.hpp # src/mbgl/gl/types.hpp # src/mbgl/gl/value.cpp # src/mbgl/gl/value.hpp # src/mbgl/map/backend_scope.cpp # src/mbgl/programs/attributes.hpp # src/mbgl/programs/program.hpp # src/mbgl/programs/segment.cpp # src/mbgl/programs/segment.hpp # src/mbgl/programs/symbol_program.hpp # src/mbgl/programs/uniforms.hpp # src/mbgl/renderer/buckets/symbol_bucket.hpp # src/mbgl/renderer/painter.cpp # src/mbgl/renderer/painter.hpp # src/mbgl/renderer/painter_background.cpp # src/mbgl/renderer/painter_circle.cpp # src/mbgl/renderer/painter_clipping.cpp # src/mbgl/renderer/painter_debug.cpp # src/mbgl/renderer/painter_fill.cpp # src/mbgl/renderer/painter_fill_extrusion.cpp # src/mbgl/renderer/painter_line.cpp # src/mbgl/renderer/painter_raster.cpp # src/mbgl/renderer/painter_symbol.cpp # src/mbgl/shaders/line.cpp # src/mbgl/shaders/line_pattern.cpp # test/renderer/backend_scope.test.cpp
73 lines
2.1 KiB
Plaintext
73 lines
2.1 KiB
Plaintext
#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 ()
|
|
|
|
// Even though this class is abstract, MGLStyle uses it to represent some
|
|
// special internal source types like mbgl::AnnotationSource.
|
|
@property (nonatomic, readonly) mbgl::style::Source *rawSource;
|
|
|
|
@property (nonatomic, readonly, weak) MGLMapView *mapView;
|
|
|
|
@end
|
|
|
|
@implementation MGLSource {
|
|
std::unique_ptr<mbgl::style::Source> _pendingSource;
|
|
}
|
|
|
|
|
|
- (instancetype)initWithIdentifier:(NSString *)identifier
|
|
{
|
|
if (self = [super init]) {
|
|
_identifier = identifier;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (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() mapView:nil]) {
|
|
_pendingSource = std::move(pendingSource);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (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, mapView.style];
|
|
}
|
|
|
|
_mapView = mapView;
|
|
_mapView.style.rawStyle->addSource(std::move(_pendingSource));
|
|
}
|
|
|
|
- (void)removeFromMapView:(MGLMapView *)mapView {
|
|
if (self.rawSource == mapView.style.rawStyle->getSource(self.identifier.UTF8String)) {
|
|
_pendingSource = mapView.style.rawStyle->removeSource(self.identifier.UTF8String);
|
|
_mapView = nil;
|
|
}
|
|
}
|
|
|
|
- (NSString *)description {
|
|
return [NSString stringWithFormat:@"<%@: %p; identifier = %@>",
|
|
NSStringFromClass([self class]), (void *)self, self.identifier];
|
|
}
|
|
|
|
@end
|