blob: ab68d45ba1e675e6b8fca674d0467a33e7816da1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#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
{
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.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
|