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

Commit

Permalink
[ios, macos] Use ugly nested ternaries for now
Browse files Browse the repository at this point in the history
Until the match operator is implemented.
  • Loading branch information
1ec5 committed Jan 5, 2018
1 parent b59590c commit a2a6747
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
19 changes: 8 additions & 11 deletions platform/darwin/test/MGLDocumentationGuideTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,17 @@ class MGLDocumentationGuideTests: XCTestCase, MGLMapViewDelegate {

//#-example-code
#if os(macOS)
let colors: [String: NSColor] = [
"earthquake": .orange,
"explosion": .red,
"quarry blast": .yellow,
]
let colors: [NSColor] = [.orange, .red, .yellow, .blue]
#else
let colors: [String: UIColor] = [
"earthquake": .orange,
"explosion": .red,
"quarry blast": .yellow,
]
let colors: [UIColor] = [.orange, .red, .yellow, .blue]
#endif

layer.circleColor = NSExpression(format: "%@.(type)", colors)
layer.circleColor = NSExpression(format:
"TERNARY(FUNCTION(type, 'stringValue') = 'earthquake', %@, " +
"TERNARY(FUNCTION(type, 'stringValue') = 'explosion', %@, " +
"TERNARY(FUNCTION(type, 'stringValue') = 'quarry blast', %@, " +
"%@)))",
argumentArray: colors)
//#-end-example-code
}

Expand Down
15 changes: 8 additions & 7 deletions platform/ios/docs/guides/Using Style Functions at Runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ At each stop, `MGLInterpolationModeCategorical` produces an output value equal t
There are three main types of events in the dataset: earthquakes, explosions, and quarry blasts. In this case, the color of the circle layer will be determined by the type of event, with a default value of blue to catch any events that do not fall into any of those categories.

```swift
let colors: [String: UIColor] = [
"earthquake": .orange,
"explosion": .red,
"quarry blast": .yellow,
]

layer.circleColor = NSExpression(format: "%@.(type)", colors)
let colors: [UIColor] = [.orange, .red, .yellow, .blue]

layer.circleColor = NSExpression(format:
"TERNARY(FUNCTION(type, 'stringValue') = 'earthquake', %@, " +
"TERNARY(FUNCTION(type, 'stringValue') = 'explosion', %@, " +
"TERNARY(FUNCTION(type, 'stringValue') = 'quarry blast', %@, " +
"%@)))",
argumentArray: colors)
```

![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png)
Expand Down
15 changes: 8 additions & 7 deletions platform/macos/docs/guides/Using Style Functions at Runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ At each stop, `MGLInterpolationModeCategorical` produces an output value equal t
There are three main types of events in the dataset: earthquakes, explosions, and quarry blasts. In this case, the color of the circle layer will be determined by the type of event, with a default value of blue to catch any events that do not fall into any of those categories.

```swift
let colors: [String: NSColor] = [
"earthquake": .orange,
"explosion": .red,
"quarry blast": .yellow,
]

layer.circleColor = NSExpression(format: "%@.(type)", colors)
let colors: [NSColor] = [.orange, .red, .yellow, .blue]

layer.circleColor = NSExpression(format:
"TERNARY(FUNCTION(type, 'stringValue') = 'earthquake', %@, " +
"TERNARY(FUNCTION(type, 'stringValue') = 'explosion', %@, " +
"TERNARY(FUNCTION(type, 'stringValue') = 'quarry blast', %@, " +
"%@)))",
argumentArray: colors)
```

![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png)
Expand Down

0 comments on commit a2a6747

Please sign in to comment.