blob: b2e0ca0a4ad079b40206c16bc2b658465839045e (
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
|
#pragma once
#include "value.hpp"
#include <mapbox/geojson.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/platform/log.hpp>
#include <jni/jni.hpp>
#include <sstream>
#include <string>
namespace mbgl {
namespace style {
namespace conversion {
template <>
Result<GeoJSON> convertGeoJSON(const mbgl::android::Value& value) {
//Value should be a string wrapped in an object
mbgl::android::Value jsonValue = value.get("data");
if(value.isNull()) {
return Error { "no json data found" };
}
std::string jsonString = value.get("data").toString();
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
d.Parse(jsonString.c_str());
if (d.HasParseError()) {
std::stringstream message;
message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
return Error { message.str() };
}
conversion::Result<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d);
if (!geoJSON) {
return Error { geoJSON.error().message };
}
return geoJSON;
}
} // namespace conversion
} // namespace style
} // namespace mbgl
|