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

#include <mbgl/util/rapidjson.hpp>

#include <string>
#include <sstream>

namespace mbgl {
namespace style {
namespace conversion {

template <>
optional<GeoJSON> convertGeoJSON(const std::string& string, Error& error) {
    rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
    d.Parse(string.c_str());

    if (d.HasParseError()) {
        std::stringstream message;
        message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
        error = { message.str() };
        return {};
    }

    optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error);
    if (!geoJSON) {
        error = { error.message };
        return {};
    }

    return geoJSON;
}

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