summaryrefslogtreecommitdiff
path: root/include/mbgl/util/feature.hpp
blob: 390cc65720d4f24cfbce45eaae0add5218d90111 (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
#pragma once

#include <mbgl/util/optional.hpp>
#include <mbgl/util/string.hpp>

#include <mapbox/feature.hpp>

namespace mbgl {

using Value = mapbox::feature::value;
using NullValue = mapbox::feature::null_value_t;
using PropertyMap = mapbox::feature::property_map;
using FeatureIdentifier = mapbox::feature::identifier;
using Feature = mapbox::feature::feature<double>;
using FeatureState = PropertyMap;
using FeatureStates = std::unordered_map<std::string, FeatureState>;       // <featureID, FeatureState>
using LayerFeatureStates = std::unordered_map<std::string, FeatureStates>; // <sourceLayer, FeatureStates>

template <class T>
optional<T> numericValue(const Value& value) {
    return value.match(
        [] (uint64_t t) {
            return optional<T>(t);
        },
        [] (int64_t t) {
            return optional<T>(t);
        },
        [] (double t) {
            return optional<T>(t);
        },
        [] (auto) {
            return optional<T>();
        });
}

inline optional<std::string> featureIDtoString(const FeatureIdentifier& id) {
    if (id.is<NullValue>()) {
        return nullopt;
    }

    return id.match(
        [](const std::string& value_) { return value_; }, [](uint64_t value_) { return util::toString(value_); },
        [](int64_t value_) { return util::toString(value_); }, [](double value_) { return util::toString(value_); },
        [](const auto&) -> optional<std::string> { return nullopt; });
}

} // namespace mbgl