You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
mbgl should have a mechanism for converting an mbgl::style::expression::Expression to a JSON structure or string. Perhaps it could live in stringify.hpp. This would be useful for implementing the style property getters on iOS/macOS for #8074: instead of working with the specialized C++ types, the getter code could transform JSON-like structures, just as the setter code produces JSON-like structures via a converter.
This mechanism or one that converts to mbgl::Value would also enable the SDKs to expose alternative setters and getters in JSON format. Studio just added an “Edit property as JSON” option that these setters and getters could tie into, and React Native Mapbox GL would also benefit from not having to reverse-engineer the native SDKs’ expression APIs.
On the iOS/macOS side, we’re still going to prefer the NSExpression syntax, as it would require far fewer @s in code, but an +[NSExpression mgl_expressionForJSONObject:] and -[NSExpression mgl_jsonObject] would be a sensible alternative for certain workflows.
I'm not sure on the Android side -- do you know how we'll expose it @tobrun? On the iOS side there is currently MGLJSONObjectFromMBGLExpression, which @1ec5 plans to re-implement as a thin wrapper on this functionality. I take it react-native-mapbox-gl is implemented on top of the iOS/Android SDK interface so it can't call directly into mbgl-core code?
@nitaliano, as of #11072, the iOS map SDK already exposes two methods for roundtripping between NSExpression and JSON-style Foundation objects (like NSArray). The MGLJSONObjectFromMBGLExpression() refactoring in #11254 plus these issues will fix a number of roundtripping bugs, but there are no plans to allow e.g. MGLSymbolStyleLayer.text to be set to a JSON object directly, since the paint and layout properties are declared with the type NSExpression.
Activity
1ec5 commentedon Jan 4, 2018
This mechanism or one that converts to
mbgl::Valuewould also enable the SDKs to expose alternative setters and getters in JSON format. Studio just added an “Edit property as JSON” option that these setters and getters could tie into, and React Native Mapbox GL would also benefit from not having to reverse-engineer the native SDKs’ expression APIs.On the iOS/macOS side, we’re still going to prefer the NSExpression syntax, as it would require far fewer
@s in code, but an+[NSExpression mgl_expressionForJSONObject:]and-[NSExpression mgl_jsonObject]would be a sensible alternative for certain workflows./cc @nitaliano @davidtheclark
anandthakker commentedon Jan 16, 2018
👍 this shouldn't be too hard to add.
Might be easier for this to be a member function on each
mbgl::style::expression::Expressionsubclass.[core] Implement Expression::serialize()
[core] Implement Expression::serialize()
ChrisLoer commentedon Feb 16, 2018
Implemented in #11156.
nitaliano commentedon Feb 16, 2018
@ChrisLoer @1ec5 so will this be exposed in the Android/iOS SDK so from react native I can just send a JSON blob?
ChrisLoer commentedon Feb 16, 2018
I'm not sure on the Android side -- do you know how we'll expose it @tobrun? On the iOS side there is currently
MGLJSONObjectFromMBGLExpression, which @1ec5 plans to re-implement as a thin wrapper on this functionality. I take itreact-native-mapbox-glis implemented on top of the iOS/Android SDK interface so it can't call directly intombgl-corecode?nitaliano commentedon Feb 16, 2018
yes that is correct
1ec5 commentedon Feb 20, 2018
@nitaliano, as of #11072, the iOS map SDK already exposes two methods for roundtripping between NSExpression and JSON-style Foundation objects (like NSArray). The
MGLJSONObjectFromMBGLExpression()refactoring in #11254 plus these issues will fix a number of roundtripping bugs, but there are no plans to allow e.g.MGLSymbolStyleLayer.textto be set to a JSON object directly, since the paint and layout properties are declared with the type NSExpression.tobrun commentedon Feb 20, 2018
@nitaliano
Input
#11158 was ticketed out to support that use-case.
Output
You can use Expression.toString() that will generate a json string that is compliant to the syntax form the style spec.
eg.
Note that I'm still working on the getters support for this in #10721
[core] Implement Expression::serialize()
[core] Implement Expression::serialize()
[core] Implement Expression::serialize()