[android] Update toGeoJSON in android_conversion.hpp (#16243)

* [android] Update toGeoJSON in android_conversion.hpp

* Fix review comments

* Update android_conversion.hpp
This commit is contained in:
Kevin Li
2020-03-04 14:15:14 +08:00
committed by GitHub
parent 44ac1f008a
commit efc605bed6
2 changed files with 28 additions and 2 deletions

View File

@@ -10,6 +10,12 @@
- [default] Fix possible crash at RunLoop::wake() ([#16255](https://github.com/mapbox/mapbox-gl-native/pull/16255))
- [android] Update toGeoJSON in android_conversion.hpp [#16243](https://github.com/mapbox/mapbox-gl-native/pull/16243)
Before this chage, `toGeoJSON` method in `android_conversion.hpp` can't convert Object(Map in android) to GeoJSON object.
But `within` expression need to accept an Object and then convert to GeoJSON object, now `toGeoJSON` method can convert both string and Object to GeoJSON.
## maps-v1.3.0 (2020.02-relvanillashake)
### 🐞 Bug fixes

View File

@@ -110,11 +110,31 @@ public:
}
static optional<GeoJSON> toGeoJSON(const mbgl::android::Value &value, Error &error) {
if (value.isNull() || !value.isString()) {
if (value.isNull()) {
error = { "no json data found" };
return {};
}
return parseGeoJSON(value.toString(), error);
if (value.isString()) {
return parseGeoJSON(value.toString(), error);
}
if (value.isObject()) {
mbgl::android::Value keys = value.keyArray();
std::size_t length = arrayLength(keys);
for (std::size_t i = 0; i < length; ++i) {
if (keys.get(i).toString() == "json") {
auto v = value.get("json");
if (v.isString()) {
return parseGeoJSON(v.toString(), error);
} else {
break;
}
}
}
}
error = {"no json data found"};
return {};
}
};