summaryrefslogtreecommitdiff
path: root/src/mbgl/style/conversion/coordinate.cpp
blob: ee03bffb308561de7a69b213621fe72bb816c96e (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
#include <mbgl/style/conversion/coordinate.hpp>
#include <mbgl/style/conversion_impl.hpp>

namespace mbgl {
namespace style {
namespace conversion {

optional<LatLng> Converter<LatLng>::operator() (const Convertible& value, Error& error) const {
    if (!isArray(value) || arrayLength(value) < 2 ) {
        error.message = "coordinate array must contain numeric longitude and latitude values";
        return nullopt;
    }
    //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.message = "coordinate array must contain numeric longitude and latitude values";
        return nullopt;
    }
    if (*latitude < -90 || *latitude > 90 ){
        error.message = "coordinate latitude must be between -90 and 90";
        return nullopt;
    }
    return LatLng(*latitude, *longitude);
}

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