Files
MapLibreParticleLab/platform/darwin/src/MGLVectorSource.mm
Minh Nguyễn 850b70ff91 [core, ios, macos] Added layers and sources properties to MGLStyle
Added new layers and sources properties to MGLStyle that contain all the style’s layers and sources, respectively. These properties are KVC-compliant with all the mutable to-many methods. Layers are ordered from topmost to bottommost, for consistency with Cocoa APIs where front/first means top and back/last means bottom.

Also added storage for mbgl::style::Source in MGLSource proper for wrapping AnnotationSource. Until the style finishes loading, its name property is set to nil.

Fixes #6003.
2016-11-28 15:45:37 -08:00

80 lines
2.0 KiB
Plaintext

#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;
}
- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url
{
if (self = [super initWithIdentifier:identifier])
{
_URL = url;
[self commonInit];
}
return self;
}
- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet
{
if (self = [super initWithIdentifier:identifier])
{
_tileSet = tileSet;
[self commonInit];
}
return self;
}
- (void)commonInit
{
std::unique_ptr<mbgl::style::VectorSource> source;
if (self.URL)
{
source = std::make_unique<mbgl::style::VectorSource>(self.identifier.UTF8String,
self.URL.mgl_URLByStandardizingScheme.absoluteString.UTF8String);
}
else
{
source = std::make_unique<mbgl::style::VectorSource>(self.identifier.UTF8String,
self.tileSet.mbglTileset);
}
_pendingSource = std::move(source);
self.rawSource = _pendingSource.get();
}
- (void)addToMapView:(MGLMapView *)mapView
{
mapView.mbglMap->addSource(std::move(_pendingSource));
}
- (void)removeFromMapView:(MGLMapView *)mapView
{
auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
_pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::VectorSource> &>(removedSource));
self.rawSource = _pendingSource.get();
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; tileSet = %@>",
NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.tileSet];
}
@end