summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLFeature_Private.h
blob: d4074b53ed8b1a750fe74e42f379f79dffedbe4b (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
#import "MGLFoundation.h"
#import "MGLFeature.h"
#import "MGLShape.h"

#import <mbgl/util/geo.hpp>
#import <mbgl/util/feature.hpp>
#import <mbgl/style/conversion/geojson.hpp>

NS_ASSUME_NONNULL_BEGIN

/**
 Returns an array of `MGLFeature` objects converted from the given vector of
 vector tile features.
 */
MGL_EXPORT
NSArray<MGLShape <MGLFeature> *> *MGLFeaturesFromMBGLFeatures(const std::vector<mbgl::Feature> &features);

/**
 Returns an `MGLFeature` object converted from the given mbgl::Feature
 */
id <MGLFeature> MGLFeatureFromMBGLFeature(const mbgl::Feature &feature);

/**
 Returns an `MGLShape` representing the given geojson. The shape can be
 a feature, a collection of features, or a geometry.
 */
MGLShape* MGLShapeFromGeoJSON(const mapbox::geojson::geojson &geojson);

/**
 Takes an `mbgl::Feature` object, an identifer, and attributes dictionary and
 returns the feature object with converted `mbgl::FeatureIdentifier` and
 `mbgl::PropertyMap` properties.
 */
mbgl::Feature mbglFeature(mbgl::Feature feature, id identifier, NSDictionary *attributes);

/**
 Returns an `NSDictionary` representation of an `MGLFeature`.
 */
NSDictionary<NSString *, id> *NSDictionaryFeatureForGeometry(NSDictionary *geometry, NSDictionary *attributes, id identifier);

NS_ASSUME_NONNULL_END

#define MGL_DEFINE_FEATURE_INIT_WITH_CODER() \
    - (instancetype)initWithCoder:(NSCoder *)decoder { \
        if (self = [super initWithCoder:decoder]) { \
            NSSet<Class> *identifierClasses = [NSSet setWithArray:@[[NSString class], [NSNumber class]]]; \
            identifier = [decoder decodeObjectOfClasses:identifierClasses forKey:@"identifier"]; \
            attributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"attributes"]; \
        } \
        return self; \
    }

#define MGL_DEFINE_FEATURE_ENCODE() \
    - (void)encodeWithCoder:(NSCoder *)coder { \
        [super encodeWithCoder:coder]; \
        [coder encodeObject:identifier forKey:@"identifier"]; \
        [coder encodeObject:attributes forKey:@"attributes"]; \
    }

#define MGL_DEFINE_FEATURE_IS_EQUAL() \
    - (BOOL)isEqual:(id)other { \
        if (other == self) return YES; \
        if (![other isKindOfClass:[self class]]) return NO; \
        __typeof(self) otherFeature = other; \
        return [super isEqual:other] && [self geoJSONObject] == [otherFeature geoJSONObject]; \
    } \
    - (NSUInteger)hash { \
        return [super hash] + [[self geoJSONDictionary] hash]; \
    }