summaryrefslogtreecommitdiff
path: root/include/mbgl/style/conversion/custom_geometry_source_options.hpp
blob: dedecd1aa4819593dbbf3e3523238b4e975b6938 (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
#pragma once

#include <mbgl/style/conversion.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>

namespace mbgl {
namespace style {
namespace conversion {

template <>
struct Converter<CustomGeometrySource::Options> {

    template <class V>
    optional<CustomGeometrySource::Options> operator()(const V& value, Error& error) const {
        CustomGeometrySource::Options options;

        const auto minzoomValue = objectMember(value, "minzoom");
        if (minzoomValue) {
            if (toNumber(*minzoomValue)) {
                options.zoomRange.min = static_cast<uint8_t>(*toNumber(*minzoomValue));
            } else {
                error = { "GeoJSON source minzoom value must be a number" };
                return {};
            }
        }

        const auto maxzoomValue = objectMember(value, "maxzoom");
        if (maxzoomValue) {
            if (toNumber(*maxzoomValue)) {
                options.zoomRange.max = static_cast<uint8_t>(*toNumber(*maxzoomValue));
            } else {
                error = { "GeoJSON source maxzoom value must be a number" };
                return {};
            }
        }

        const auto bufferValue = objectMember(value, "buffer");
        if (bufferValue) {
            if (toNumber(*bufferValue)) {
                options.tileOptions.buffer = static_cast<uint16_t>(*toNumber(*bufferValue));
            } else {
                error = { "GeoJSON source buffer value must be a number" };
                return {};
            }
        }

        const auto toleranceValue = objectMember(value, "tolerance");
        if (toleranceValue) {
            if (toNumber(*toleranceValue)) {
                options.tileOptions.tolerance = static_cast<double>(*toNumber(*toleranceValue));
            } else {
                error = { "GeoJSON source tolerance value must be a number" };
                return {};
            }
        }

        const auto wrapValue = objectMember(value, "wrap");
        if (wrapValue) {
            if (toBool(*wrapValue)) {
                options.tileOptions.wrap = static_cast<bool>(*toBool(*wrapValue));
            } else {
                error = { "CustomGeometrySource TileOptions wrap value must be a boolean" };
                return {};
            }
        }

        const auto clipValue = objectMember(value, "clip");
        if (clipValue) {
            if (toBool(*clipValue)) {
                options.tileOptions.clip = static_cast<double>(*toBool(*clipValue));
            } else {
                error = { "CustomGeometrySource TileOptiosn clip value must be a boolean" };
                return {};
            }
        }

        return { options };
    }

};

} // namespace conversion
} // namespace style
} // namespace mbgl