blob: 92c5b87e895e65641e91207f8011ae38679ad208 (
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
|
#import "MGLGeoJSONSource.h"
#import "MGLSource_Private.hpp"
#include <mbgl/style/sources/geojson_source.hpp>
@interface MGLGeoJSONSource ()
@property (nonatomic, copy) NSURL *URL;
@end
@implementation MGLGeoJSONSource
static NSString *MGLGeoJSONSourceType = @"geojson";
static NSString *MGLGeoJSONDataKey = @"data";
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url
{
if (self = [super initWithSourceIdentifier:sourceIdentifier sourceType:MGLGeoJSONSourceType]) {
_URL = url;
if (url.isFileURL) {
_data = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];
} else {
_data = url.absoluteString;
}
}
return self;
}
- (std::unique_ptr<mbgl::style::Source>)mbgl_source
{
auto source = std::make_unique<mbgl::style::GeoJSONSource>(self.sourceIdentifier.UTF8String);
if (_URL.isFileURL) {
const auto geojson = mapbox::geojson::parse(self.data.UTF8String).get<mapbox::geojson::feature_collection>();
source->setGeoJSON(geojson);
} else {
source->setURL(self.data.UTF8String);
}
return std::move(source);
}
@end
|