mapbox / mapbox/mapbox-maps-ios

Match expression without hardcoding values?

Open
#2,072 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged feature :green_apple:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

## 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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the expression documentation and repository examples mentioned in the issue, focusing on the Swift Exp(.match) entry point. Determine whether a dictionary-driven match expression is supported; done would require a clearly defined SDK API or a documented conclusion that this enhancement needs further design.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.