summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmkiley <jordan.kiley@mapbox.com>2018-04-19 15:14:53 -0700
committerjmkiley <jordan.kiley@mapbox.com>2018-04-19 15:14:53 -0700
commit8f7268ee1c3b8bc3a87a3b7236a992bd29d67cd4 (patch)
treeb77fb37d960f1ebeeab1d0a9fd18db5f960f157e
parentdf84e0138db6e48b407b3d9f1e8d820c6c231551 (diff)
downloadqtlocation-mapboxgl-8f7268ee1c3b8bc3a87a3b7236a992bd29d67cd4.tar.gz
[ios, macos] more failing tests
-rw-r--r--platform/darwin/docs/guides/Migrating to Expressions.md.ejs6
-rw-r--r--platform/darwin/test/MGLDocumentationGuideTests.swift26
-rw-r--r--platform/ios/docs/guides/Migrating to Expressions.md15
-rw-r--r--platform/macos/docs/guides/Migrating to Expressions.md20
4 files changed, 58 insertions, 9 deletions
diff --git a/platform/darwin/docs/guides/Migrating to Expressions.md.ejs b/platform/darwin/docs/guides/Migrating to Expressions.md.ejs
index 435a9d4a65..1a03534288 100644
--- a/platform/darwin/docs/guides/Migrating to Expressions.md.ejs
+++ b/platform/darwin/docs/guides/Migrating to Expressions.md.ejs
@@ -67,7 +67,7 @@ When we use the stops dictionary given above with an `'mgl_step:from:stops:'`, w
### Categorical
-Categorical interpolation mode took a stops dictionary. If the value for a specified feature attribute name matched one in that stops dictionary, the style value for that attribute value would be used. Categorical style functions can now be replaced with `MGL_MATCH()`.
+Categorical interpolation mode took a stops dictionary. If the value for a specified feature attribute name matched one in that stops dictionary, the style value for that attribute value would be used. Categorical style functions can now be replaced with `MGL_MATCH`.
`MGL_MATCH` takes an initial condition, which in this case is an attribute key. This is follow by possible matches for that key and the value to assign to the layer property if there is a match. The final argument can be a default style value that is to be used if none of the specified values match.
@@ -75,6 +75,10 @@ There are three main types of events in the USGS dataset: earthquakes, explosion
<%- guideExample(guide, 'Categorical', os) %>
+If your use case does not require a default value, you can either apply a predicate to your layer prior to styling it, or use the format string `"valueForKeyPath:".
+
+<%- guideExample(guide, 'CategoricalValue', os) %>
+
![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png)
### Identity
diff --git a/platform/darwin/test/MGLDocumentationGuideTests.swift b/platform/darwin/test/MGLDocumentationGuideTests.swift
index 437d37766b..43a7e69042 100644
--- a/platform/darwin/test/MGLDocumentationGuideTests.swift
+++ b/platform/darwin/test/MGLDocumentationGuideTests.swift
@@ -79,7 +79,7 @@ class MGLDocumentationGuideTests: XCTestCase, MGLMapViewDelegate {
//#-example-code
let url = URL(string: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson")!
let symbolSource = MGLSource(identifier: "source")
- let symbolLayer = mapView.style?.layer(withIdentifier: "place-city-sm")!
+ let symbolLayer = MGLSymbolStyleLayer(identifier: "place-city-sm", source: source)
let source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
mapView.style?.addSource(source)
@@ -142,7 +142,7 @@ class MGLDocumentationGuideTests: XCTestCase, MGLMapViewDelegate {
//#-end-example-code
layer.circleRadius = NSExpression(forConstantValue: 10)
- mapView.style?.insertLayer(layer, below: symbolLayer)
+ mapView.style?.addLayer(layer)
}
func testMigratingToExpressions$Exponential() {
@@ -224,6 +224,28 @@ class MGLDocumentationGuideTests: XCTestCase, MGLMapViewDelegate {
//#-end-example-code
}
+ func testMigratingToExpressions$CategoricalValue() {
+ let source = MGLShapeSource(identifier: "circles", shape: nil, options: nil)
+ let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
+
+ //#-example-code
+ #if os(macOS)
+ let stops : [String : NSColor] = ["earthquake" : NSColor.orange,
+ "explosion" : NSColor.red,
+ "quarry blast" : NSColor.yellow]
+ layer.circleColor = NSExpression(
+ format: "FUNCTION(%@, 'valueForKeyPath:', type)",
+ stops)
+ #else
+ let stops : [String : UIColor] = ["earthquake" : UIColor.orange,
+ "explosion" : UIColor.red,
+ "quarry blast" : UIColor.yellow]
+ layer.circleColor = NSExpression(
+ format: "FUNCTION(%@, 'valueForKeyPath:', type)",
+ stops)
+ #endif
+ //#-end-example-code
+ }
func testMigratingToExpressions$Identity() {
let source = MGLShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
diff --git a/platform/ios/docs/guides/Migrating to Expressions.md b/platform/ios/docs/guides/Migrating to Expressions.md
index 2652bdc3cd..2a9a22a3ff 100644
--- a/platform/ios/docs/guides/Migrating to Expressions.md
+++ b/platform/ios/docs/guides/Migrating to Expressions.md
@@ -44,7 +44,7 @@ The stops dictionary below, for example, shows colors that continuously shift fr
```swift
let url = URL(string: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson")!
let symbolSource = MGLSource(identifier: "source")
-let symbolLayer = MGLSymbolStyleLayer(identifier: "place-city-sm", source: symbolSource)
+let symbolLayer = MGLSymbolStyleLayer(identifier: "place-city-sm", source: source)
let source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
mapView.style?.addSource(source)
@@ -109,7 +109,7 @@ layer.circleColor = NSExpression(format: "mgl_step:from:stops:(mag, %@, %@)",
### Categorical
-Categorical interpolation mode took a stops dictionary. If the value for a specified feature attribute name matched one in that stops dictionary, the style value for that attribute value would be used. Categorical style functions can now be replaced with `MGL_MATCH()`.
+Categorical interpolation mode took a stops dictionary. If the value for a specified feature attribute name matched one in that stops dictionary, the style value for that attribute value would be used. Categorical style functions can now be replaced with `MGL_MATCH`.
`MGL_MATCH` takes an initial condition, which in this case is an attribute key. This is follow by possible matches for that key and the value to assign to the layer property if there is a match. The final argument can be a default style value that is to be used if none of the specified values match.
@@ -121,6 +121,17 @@ layer.circleColor = NSExpression(format: "MGL_MATCH(type, 'earthquake', %@, 'exp
UIColor.orange, UIColor.red, UIColor.yellow, defaultColor)
```
+If your use case does not require a default value, you can either apply a predicate to your layer prior to styling it, or use the format string `"valueForKeyPath:".
+
+```swift
+let stops : [String : UIColor] = ["earthquake" : UIColor.orange,
+ "explosion" : UIColor.red,
+ "quarry blast" : UIColor.yellow]
+layer.circleColor = NSExpression(
+format: "FUNCTION(%@, 'valueForKeyPath:', type)",
+stops)
+```
+
![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png)
### Identity
diff --git a/platform/macos/docs/guides/Migrating to Expressions.md b/platform/macos/docs/guides/Migrating to Expressions.md
index 56cc313f93..c8ad496230 100644
--- a/platform/macos/docs/guides/Migrating to Expressions.md
+++ b/platform/macos/docs/guides/Migrating to Expressions.md
@@ -44,7 +44,7 @@ The stops dictionary below, for example, shows colors that continuously shift fr
```swift
let url = URL(string: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson")!
let symbolSource = MGLSource(identifier: "source")
-let symbolLayer = MGLSymbolStyleLayer(identifier: "place-city-sm", source: symbolSource)
+let symbolLayer = MGLSymbolStyleLayer(identifier: "place-city-sm", source: source)
let source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
mapView.style?.addSource(source)
@@ -89,7 +89,7 @@ layer.circleRadius = NSExpression(format: "mgl_interpolate:withCurveType:paramet
### Interval
-Steps, or intervals, create a range using the keys from the stops dictionary. The range is from the given key to just less than the next key. The attribute values that fall into that range are then styled using the layout or paint value assigned to that key. You can use the format string `'mgl_step:from:stops:'` for cases where you previously used interval interpolation mode. The first parameter takes the feature attribute name and the second parameter (`from:`) optionally takes the default or fallback value for that function. The final parameter takes a stops dictionary as an argument.
+Steps, or intervals, create a range using the keys from the stops dictionary. The range is from the given key to just less than the next key. The attribute values that fall into that range are then styled using the layout or paint value assigned to that key. You can use the format string `'mgl_step:from:stops:'` for cases where you previously used interval interpolation mode. The first parameter takes the feature attribute name and the second parameter (`from:`) optionally takes the default or fallback value for that function. The final parameter takes a stops dictionary as an argument.
When we use the stops dictionary given above with an `'mgl_step:from:stops:'`, we create ranges where earthquakes with a magnitude of 0 to just less than 2.5 would be yellow, 2.5 to just less than 5 would be orange, and so on.
```swift
@@ -109,7 +109,7 @@ layer.circleColor = NSExpression(format: "mgl_step:from:stops:(mag, %@, %@)",
### Categorical
-Categorical interpolation mode took a stops dictionary. If the value for a specified feature attribute name matched one in that stops dictionary, the style value for that attribute value would be used. Categorical style functions can now be replaced with `MGL_MATCH()`.
+Categorical interpolation mode took a stops dictionary. If the value for a specified feature attribute name matched one in that stops dictionary, the style value for that attribute value would be used. Categorical style functions can now be replaced with `MGL_MATCH`.
`MGL_MATCH` takes an initial condition, which in this case is an attribute key. This is follow by possible matches for that key and the value to assign to the layer property if there is a match. The final argument can be a default style value that is to be used if none of the specified values match.
@@ -122,6 +122,17 @@ format: "MGL_MATCH(type, 'earthquake', %@, 'explosion', %@, 'quarry blast', %@,
NSColor.orange, NSColor.red, NSColor.yellow, defaultColor)
```
+If your use case does not require a default value, you can either apply a predicate to your layer prior to styling it, or use the format string `"valueForKeyPath:".
+
+```swift
+let stops : [String : NSColor] = ["earthquake" : NSColor.orange,
+ "explosion" : NSColor.red,
+ "quarry blast" : NSColor.yellow]
+layer.circleColor = NSExpression(
+format: "FUNCTION(%@, 'valueForKeyPath:', type)",
+stops)
+```
+
![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png)
### Identity
@@ -152,7 +163,8 @@ mapView.style?.addLayer(magnitudeLayer)
![cast a value](img/data-driven-styling/cast.png)
-## Constant Values
+### Constant Values
+
## Resources
* [USGS](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php)