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

#include <mbgl/style/conversion.hpp>
#include <mbgl/util/geo.hpp>

namespace mbgl {
namespace style {
namespace conversion {
            
template<>
struct Converter<LatLng> {
public:
    template <class V>
    optional<LatLng> operator() (const V& value, Error& error) const {
        if (!isArray(value) || arrayLength(value) < 2 ) {
            error = { "coordinate array must contain numeric longtitude and latitude values" };
            return {};
        }
        //Style spec uses GeoJSON convention for specifying coordinates
        optional<double> latitude = toDouble(arrayMember(value, 1));
        optional<double> longitude = toDouble(arrayMember(value, 0));
    
        if (!latitude || !longitude) {
            error = { "coordinate array must contain numeric longtitude and latitude values" };
            return {};
        }
        if (*latitude < -90 || *latitude > 90 ){
            error = { "coordinate latitude must be between -90 and 90" };
            return {};
        }
        return LatLng(*latitude, *longitude);
    }
};

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