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 has been archived by the owner on Aug 8, 2023. It is now read-only.
In the iOS and macOS SDKs, automatic label localization (MGLStyle.localizesLabels) replaces references to one name_* field with another in every symbol layer. This is a trivial operation for constant expressions and was a manageable operation for legacy style functions, but expressions are far too complex to transform in an ad-hoc manner. For now, #10726 will avoid localizing non-constant expressions, and #10713 would reenable the feature for data and/or camera expressions.
Essentially what’s needed is a way to visit every subexpression and transform it according to a block. It might piggyback on eachChild() to some extent, but it would recurse through the entire subexpression tree, and the callback would return a replacement object. This transformation function could be implemented purely at the Objective-C level, but a pure C++ implementation would be much more robust, avoiding any risk from lossy roundtripping between C++ and Objective-C types.
It would be ideal if mbgl could expose a dedicated way to transform an expression, but after #11156 lands, this feature could also be implemented at the SDK level, albeit with an impact on performance:
Serialize the expression as an mbgl::Value.
Convert the mbgl::Value to an NSArray.
Use NSKeyedArchiver or NSJSONSerialization to archive the NSArray.
Use NSKeyedUnarchiver or NSJSONSerialization to unarchive an NSMutableArray with mutable descendants.
Manually recurse down the NSMutableArray, calling the callback on each object encountered.
@1ec5 I'm thinking that a round-tripping approach like #10944 (comment) might actually be preferable to adding a general-purpose transformation API. The former would have the advantage of going through the expression parsing (and thus type checking) code path, and the latter seems like adding a lot to the expression API surface for a single, specific use case.
A general framework for expression transformations is no longer needed in mbgl for #10713. In fact, we have a pretty good start to such a framework in the NSExpression category, because NSExpression’s AST made it quite easy to do so. Round-tripping is no longer much of a concern after the changes in #11472.
In the iOS and macOS SDKs, automatic label localization (
MGLStyle.localizesLabels
) replaces references to onename_*
field with another in every symbol layer. This is a trivial operation for constant expressions and was a manageable operation for legacy style functions, but expressions are far too complex to transform in an ad-hoc manner. For now, #10726 will avoid localizing non-constant expressions, and #10713 would reenable the feature for data and/or camera expressions.Essentially what’s needed is a way to visit every subexpression and transform it according to a block. It might piggyback on
eachChild()
to some extent, but it would recurse through the entire subexpression tree, and the callback would return a replacement object. This transformation function could be implemented purely at the Objective-C level, but a pure C++ implementation would be much more robust, avoiding any risk from lossy roundtripping between C++ and Objective-C types./cc @anandthakker @tobrun
The text was updated successfully, but these errors were encountered: