mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

Match expression without hardcoding values?

Open bmt2018 opened this issue 2 years ago • 0 comments

New Feature

I'm using the Mapbox Maps iOS SDK and I have a layer that renders circles on the map which represent the location of various features. Each feature has several properties including a string "type" like "CAR", "BOAT", "AIRCRAFT", etc. I'm using a color expression to determine what color each circle should be based on the "type" value of the feature. Currently, that expression is constructed like this:

let colorExpression = Exp(.match) {
    Exp(.get) { "type" }
    "CAR"
    UIColor.systemBlue
    "BOAT"
    UIColor.systemRed
    "AIRCRAFT"
    UIColor.systemGreen
    UIColor.systemGray // default color if some other "type" value
}

However, the feature data comes from a server and new feature "types" (and their corresponding color values) are introduced on the server from time to time. Currently, when that happens, I'm manually updating the expression in the app source and then building a new release of the app.

Why

It would be nice if there were a way to build this expression more "dynamically" so that instead of hard coding the type and color values, the expression could be updated (or redefined) by passing in a dictionary (or some other structure) of feature types/colors. I've read through the expression documentation and looked at the examples in the repo that use expressions and I haven't seen anything that would appear to suggest that this is possible today (in the v10 or v11 SDKs). If it is, I'd love to know how to accomplish it! And if it isn't, I'd like to ask that you consider it as a possible enhancement for a future SDK release. Thanks very much!

bmt2018 avatar Dec 05 '23 18:12 bmt2018