Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] Update toGeoJSON in android_conversion.hpp #16243

Merged
merged 3 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions platform/android/src/style/android_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,31 @@ class ConversionTraits<mbgl::android::Value> {
}

static optional<GeoJSON> toGeoJSON(const mbgl::android::Value &value, Error &error) {
if (value.isNull() || !value.isString()) {
if (value.isNull()) {
Chaoba marked this conversation as resolved.
Show resolved Hide resolved
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 {
Chaoba marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
}
}
error = {"no json data found"};
return {};
Chaoba marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down