[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:
@@ -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
|
||||
|
||||
@@ -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 {};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user