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

Stringify expressions #10714

Closed
Closed

Description

@1ec5

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.

/ref #7563
/cc @anandthakker

Activity

  1. added
    iOS
    macOS
    on Dec 16, 2017
  2. 1ec5 commented on Jan 4, 2018

    @1ec5
    ContributorAuthor

    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.

    /cc @nitaliano @davidtheclark

  3. anandthakker commented on Jan 16, 2018

    @anandthakker
    Contributor

    👍 this shouldn't be too hard to add.

    Perhaps it could live in stringify.hpp

    Might be easier for this to be a member function on each mbgl::style::expression::Expression subclass.

  4. added this to the milestone on Jan 18, 2018
  5. self-assigned this
    on Feb 7, 2018
  6. ChrisLoer commented on Feb 16, 2018

    @ChrisLoer
    Contributor

    Implemented in #11156.

  7. nitaliano commented on Feb 16, 2018

    @nitaliano
    Contributor

    @ChrisLoer @1ec5 so will this be exposed in the Android/iOS SDK so from react native I can just send a JSON blob?

  8. ChrisLoer commented on Feb 16, 2018

    @ChrisLoer
    Contributor

    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?

  9. nitaliano commented on Feb 16, 2018

    @nitaliano
    Contributor

    yes that is correct

  10. 1ec5 commented on Feb 20, 2018

    @1ec5
    ContributorAuthor

    @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.

  11. tobrun commented on Feb 20, 2018

    @tobrun
    Member

    @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.

      @Test
      public void testExpressionMinToString() throws Exception {
        String expected = "[\"min\", 0, 1, 2, 3]";
        String actual = min(0, 1, 2, 3).toString();
        assertEquals("toString should match", expected, actual);
      }

    Note that I'm still working on the getters support for this in #10721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureiOSmacOSruntime styling

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions