summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorEric Wolfe <eric.r.wolfe@gmail.com>2017-03-20 18:28:54 -0700
committerEric Wolfe <eric.r.wolfe@gmail.com>2017-03-20 22:34:15 -0700
commite0fe42d8321d19a4a9cb46edac9fbdb035e70a0c (patch)
treeee798cce8a58269532247bd263e3d1fdfe6a7d6d /platform
parentaf475f0175abd2badb4df5229a750c1796e82ca4 (diff)
downloadqtlocation-mapboxgl-e0fe42d8321d19a4a9cb46edac9fbdb035e70a0c.tar.gz
[ios][macos] Update DDS guide
Clarifies linear and exponential interpolation, adds stops to each example for clarity, and other minor tweaks.
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/docs/guides/Data-Driven Styling.md.ejs89
-rw-r--r--platform/ios/docs/guides/Data-Driven Styling.md89
-rw-r--r--platform/ios/docs/img/data-driven-styling/exponential-function-1.pngbin0 -> 69991 bytes
-rw-r--r--platform/ios/docs/img/data-driven-styling/exponential-function.pngbin0 -> 70066 bytes
-rw-r--r--platform/macos/docs/guides/Data-Driven Styling.md89
5 files changed, 189 insertions, 78 deletions
diff --git a/platform/darwin/docs/guides/Data-Driven Styling.md.ejs b/platform/darwin/docs/guides/Data-Driven Styling.md.ejs
index ead073b1c5..820f71f594 100644
--- a/platform/darwin/docs/guides/Data-Driven Styling.md.ejs
+++ b/platform/darwin/docs/guides/Data-Driven Styling.md.ejs
@@ -12,7 +12,9 @@
# Data-Driven Styling
-Mapbox’s data-driven styling features allow you to use data properties to style your maps. You can style objects within the same layer differently based on their individual attributes. This enables you to style icons, routes, parks, and more based on feature attributes.
+Mapbox’s data-driven styling features allow you to use data properties to style your maps. You can style map features automatically based on their individual attributes.
+
+Vary POI icons, transit route line colors, city polygon opacity, and more based on any attribute in your data. Need to visualize hotel data by price? You can have your map’s point radii and colors change automatically with your data.
![available bikes](img/data-driven-styling/citibikes.png) ![subway lines](img/data-driven-styling/polylineExample.png)
@@ -23,8 +25,8 @@ This guide uses earthquake data from the [U.S. Geological Survey](https://earthq
There are three subclasses of `MGLStyleFunction`:
-* `MGLCameraStyleFunction` - For a style value that changes with zoom level. For example, you can make the radius of a circle to increase based on zoom level. In iOS SDK v3.4, this was a `MGLStyleFunction`.
-* `MGLSourceStyleFunction` - For a style value that changes with the attributes of a feature. You can adjust the radius of a circle based on the magnitude of an earthquake, for example.
+* `MGLCameraStyleFunction` - For a style value that changes with zoom level. For example, you can make the radius of a circle increase according to zoom level.
+* `MGLSourceStyleFunction` - For a style value that changes with the attributes of a feature. For example, you can adjust the radius of a circle based on the magnitude of an earthquake.
* `MGLCompositeStyleFunction` - For a style value that changes with both zoom level and attribute values. For example, you can add a circle layer where each circle has a radius based on both zoom level and the magnitude of an earthquake.
The documentation for individual style properties will note which style functions are enabled for that property.
@@ -33,41 +35,70 @@ The documentation for individual style properties will note which style function
Stops are key-value pairs that that determine a style value. With a `MGLCameraSourceFunction` stop, you can use a dictionary with a zoom level for a key and a `MGLStyleValue` for the value. For example, you can use a stops dictionary with zoom levels 0, 10, and 20 as keys, and yellow, orange, and red as the values. A `MGLSourceStyleFunction` uses the relevant attribute value as the key.
+```swift
+let stops = [0: MGLStyleValue(rawValue: UIColor.yellow),
+ 2.5: MGLStyleValue(rawValue: UIColor.orange),
+ 5: MGLStyleValue(rawValue: UIColor.red),
+ 7.5: MGLStyleValue(rawValue: UIColor.blue),
+ 10: MGLStyleValue(rawValue: UIColor.white)]
+```
+
## Interpolation Mode
The effect a key has on the style value is determined by the interpolation mode. There are four interpolation modes that can be used with a source style function: exponential, interval, categorical, and identity. You can also use exponential and interval interpolation modes with a camera style function.
-### Exponential (or Linear)
+### Linear
-`MGLInterpolationModelExponential` creates a linear or exponential effect based on the values. The key value is the starting point for interpolation, and the style value is based on where an attribute value falls between two keys. By default, `MGLInterpolationModeExponential` uses an interpolation base of 1. This causes a linear relationship between the style value and stop key.
+`MGLInterpolationModelExponential` interpolates linearly or exponentially between style function stop values. By default, the `MGLStyleFunction` options parameter `MGLStyleFunctionOptionInterpolationBase` equals `1`, which represents linear interpolation, and doesn’t need to be included in the options dictionary.
The stops dictionary below, for example, shows colors that continuously shift from yellow to orange to red to blue to white based on the attribute value.
``` 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 source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
- style.addSource(source)
-
- let stops = [0: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.yellow),
- 2.5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.orange),
- 5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.red),
- 7.5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.blue),
- 10: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.white)]
-
- let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
- layer.circleColor = MGLStyleValue(interpolationMode: .exponential,
- sourceStops: stops,
- attributeName: "mag",
- options: [.defaultValue: MGLStyleValue<<%- cocoaPrefix %>Color>(rawValue: .green)])
- layer.circleRadius = MGLStyleValue(rawValue: 10)
- style.insertLayer(layer, below: symbolLayer)
+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 source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
+style.addSource(source)
+
+let stops = [0: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.yellow),
+ 2.5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.orange),
+ 5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.red),
+ 7.5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.blue),
+ 10: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.white)]
+
+let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
+layer.circleColor = MGLStyleValue(interpolationMode: .exponential,
+ sourceStops: stops,
+ attributeName: "mag",
+ options: [.defaultValue: MGLStyleValue<<%- cocoaPrefix %>Color>(rawValue: .green)])
+layer.circleRadius = MGLStyleValue(rawValue: 10)
+style.insertLayer(layer, below: symbolLayer)
```
![exponential mode](img/data-driven-styling/exponential.png)
+### Exponential
+
+`MGLInterpolationModelExponential` combined with any `MGLStyleFunctionOptionInterpolationBase` greater than `0`, you can interpolate between values exponentially, create an accelerated ramp effect.
+
+Here’s a visualization from Mapbox Studio (see [Working with Mapbox Studio](working-with-mapbox-studio.html)) comparing interpolation base values of `1.5` and `0.5` based on zoom.
+
+<img src="img/data-driven-styling/exponential-function.png" height=344/>
+<img src="img/data-driven-styling/exponential-function-1.png" height=344/>
+
+The example below increases a layer’s `circleRadius` exponentially based on a map’s zoom level. The `MGLStyleFunctionOptionInterpolationBase` is `1.5`.
+
+```swift
+let stops = [12: MGLStyleValue(rawValue: 0.5),
+ 14: MGLStyleValue(rawValue: 2),
+ 18: MGLStyleValue(rawValue: 18)]
+
+layer.circleRadius = MGLStyleValue(interpolationMode: .exponential,
+ cameraStops: stops,
+ options: [.interpolationBase: 1.5])
+```
+
### Interval
`MGLInterpolationModeInterval` creates 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 style value assigned to that key.
@@ -75,6 +106,12 @@ The stops dictionary below, for example, shows colors that continuously shift fr
When we use the stops dictionary given above with an interval interpolation mode, 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
+let stops = [0: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.yellow),
+ 2.5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.orange),
+ 5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.red),
+ 7.5: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.blue),
+ 10: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.white)]
+
layer.circleColor = MGLStyleValue(interpolationMode: .interval,
sourceStops: stops,
attributeName: "mag",
@@ -105,7 +142,7 @@ layer.circleColor = MGLStyleValue(interpolationMode: .categorical,
### Identity
-`MGLInterpolationModeIdentity` uses the attribute’s value as the style value. For example, you can set the `circleRadius` to the earthquake’s magnitude. Since the attribute value itself will be used as the style value, `sourceStops` can be set to `nil`.
+`MGLInterpolationModeIdentity` uses the attribute’s value as the style value. For example, you can set the `circleRadius` to the earthquake’s magnitude. Since the attribute value itself will be used as the style value, `sourceStops` should be set to `nil`.
``` swift
layer.circleRadius = MGLStyleValue(interpolationMode: .identity,
diff --git a/platform/ios/docs/guides/Data-Driven Styling.md b/platform/ios/docs/guides/Data-Driven Styling.md
index 418c7bb4fc..0b685512b4 100644
--- a/platform/ios/docs/guides/Data-Driven Styling.md
+++ b/platform/ios/docs/guides/Data-Driven Styling.md
@@ -6,7 +6,9 @@
# Data-Driven Styling
-Mapbox’s data-driven styling features allow you to use data properties to style your maps. You can style objects within the same layer differently based on their individual attributes. This enables you to style icons, routes, parks, and more based on feature attributes.
+Mapbox’s data-driven styling features allow you to use data properties to style your maps. You can style map features automatically based on their individual attributes.
+
+Vary POI icons, transit route line colors, city polygon opacity, and more based on any attribute in your data. Need to visualize hotel data by price? You can have your map’s point radii and colors change automatically with your data.
![available bikes](img/data-driven-styling/citibikes.png) ![subway lines](img/data-driven-styling/polylineExample.png)
@@ -17,8 +19,8 @@ This guide uses earthquake data from the [U.S. Geological Survey](https://earthq
There are three subclasses of `MGLStyleFunction`:
-* `MGLCameraStyleFunction` - For a style value that changes with zoom level. For example, you can make the radius of a circle to increase based on zoom level. In iOS SDK v3.4, this was a `MGLStyleFunction`.
-* `MGLSourceStyleFunction` - For a style value that changes with the attributes of a feature. You can adjust the radius of a circle based on the magnitude of an earthquake, for example.
+* `MGLCameraStyleFunction` - For a style value that changes with zoom level. For example, you can make the radius of a circle increase according to zoom level.
+* `MGLSourceStyleFunction` - For a style value that changes with the attributes of a feature. For example, you can adjust the radius of a circle based on the magnitude of an earthquake.
* `MGLCompositeStyleFunction` - For a style value that changes with both zoom level and attribute values. For example, you can add a circle layer where each circle has a radius based on both zoom level and the magnitude of an earthquake.
The documentation for individual style properties will note which style functions are enabled for that property.
@@ -27,41 +29,70 @@ The documentation for individual style properties will note which style function
Stops are key-value pairs that that determine a style value. With a `MGLCameraSourceFunction` stop, you can use a dictionary with a zoom level for a key and a `MGLStyleValue` for the value. For example, you can use a stops dictionary with zoom levels 0, 10, and 20 as keys, and yellow, orange, and red as the values. A `MGLSourceStyleFunction` uses the relevant attribute value as the key.
+```swift
+let stops = [0: MGLStyleValue(rawValue: UIColor.yellow),
+ 2.5: MGLStyleValue(rawValue: UIColor.orange),
+ 5: MGLStyleValue(rawValue: UIColor.red),
+ 7.5: MGLStyleValue(rawValue: UIColor.blue),
+ 10: MGLStyleValue(rawValue: UIColor.white)]
+```
+
## Interpolation Mode
The effect a key has on the style value is determined by the interpolation mode. There are four interpolation modes that can be used with a source style function: exponential, interval, categorical, and identity. You can also use exponential and interval interpolation modes with a camera style function.
-### Exponential (or Linear)
+### Linear
-`MGLInterpolationModelExponential` creates a linear or exponential effect based on the values. The key value is the starting point for interpolation, and the style value is based on where an attribute value falls between two keys. By default, `MGLInterpolationModeExponential` uses an interpolation base of 1. This causes a linear relationship between the style value and stop key.
+`MGLInterpolationModelExponential` interpolates linearly or exponentially between style function stop values. By default, the `MGLStyleFunction` options parameter `MGLStyleFunctionOptionInterpolationBase` equals `1`, which represents linear interpolation, and doesn’t need to be included in the options dictionary.
The stops dictionary below, for example, shows colors that continuously shift from yellow to orange to red to blue to white based on the attribute value.
``` 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 source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
- style.addSource(source)
-
- let stops = [0: MGLStyleValue(rawValue: UIColor.yellow),
- 2.5: MGLStyleValue(rawValue: UIColor.orange),
- 5: MGLStyleValue(rawValue: UIColor.red),
- 7.5: MGLStyleValue(rawValue: UIColor.blue),
- 10: MGLStyleValue(rawValue: UIColor.white)]
-
- let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
- layer.circleColor = MGLStyleValue(interpolationMode: .exponential,
- sourceStops: stops,
- attributeName: "mag",
- options: [.defaultValue: MGLStyleValue<UIColor>(rawValue: .green)])
- layer.circleRadius = MGLStyleValue(rawValue: 10)
- style.insertLayer(layer, below: symbolLayer)
+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 source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
+style.addSource(source)
+
+let stops = [0: MGLStyleValue(rawValue: UIColor.yellow),
+ 2.5: MGLStyleValue(rawValue: UIColor.orange),
+ 5: MGLStyleValue(rawValue: UIColor.red),
+ 7.5: MGLStyleValue(rawValue: UIColor.blue),
+ 10: MGLStyleValue(rawValue: UIColor.white)]
+
+let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
+layer.circleColor = MGLStyleValue(interpolationMode: .exponential,
+ sourceStops: stops,
+ attributeName: "mag",
+ options: [.defaultValue: MGLStyleValue<UIColor>(rawValue: .green)])
+layer.circleRadius = MGLStyleValue(rawValue: 10)
+style.insertLayer(layer, below: symbolLayer)
```
![exponential mode](img/data-driven-styling/exponential.png)
+### Exponential
+
+`MGLInterpolationModelExponential` combined with any `MGLStyleFunctionOptionInterpolationBase` greater than `0`, you can interpolate between values exponentially, create an accelerated ramp effect.
+
+Here’s a visualization from Mapbox Studio (see [Working with Mapbox Studio](working-with-mapbox-studio.html)) comparing interpolation base values of `1.5` and `0.5` based on zoom.
+
+<img src="img/data-driven-styling/exponential-function.png" height=344/>
+<img src="img/data-driven-styling/exponential-function-1.png" height=344/>
+
+The example below increases a layer’s `circleRadius` exponentially based on a map’s zoom level. The `MGLStyleFunctionOptionInterpolationBase` is `1.5`.
+
+```swift
+let stops = [12: MGLStyleValue(rawValue: 0.5),
+ 14: MGLStyleValue(rawValue: 2),
+ 18: MGLStyleValue(rawValue: 18)]
+
+layer.circleRadius = MGLStyleValue(interpolationMode: .exponential,
+ cameraStops: stops,
+ options: [.interpolationBase: 1.5])
+```
+
### Interval
`MGLInterpolationModeInterval` creates 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 style value assigned to that key.
@@ -69,6 +100,12 @@ The stops dictionary below, for example, shows colors that continuously shift fr
When we use the stops dictionary given above with an interval interpolation mode, 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
+let stops = [0: MGLStyleValue(rawValue: UIColor.yellow),
+ 2.5: MGLStyleValue(rawValue: UIColor.orange),
+ 5: MGLStyleValue(rawValue: UIColor.red),
+ 7.5: MGLStyleValue(rawValue: UIColor.blue),
+ 10: MGLStyleValue(rawValue: UIColor.white)]
+
layer.circleColor = MGLStyleValue(interpolationMode: .interval,
sourceStops: stops,
attributeName: "mag",
@@ -99,7 +136,7 @@ layer.circleColor = MGLStyleValue(interpolationMode: .categorical,
### Identity
-`MGLInterpolationModeIdentity` uses the attribute’s value as the style value. For example, you can set the `circleRadius` to the earthquake’s magnitude. Since the attribute value itself will be used as the style value, `sourceStops` can be set to `nil`.
+`MGLInterpolationModeIdentity` uses the attribute’s value as the style value. For example, you can set the `circleRadius` to the earthquake’s magnitude. Since the attribute value itself will be used as the style value, `sourceStops` should be set to `nil`.
``` swift
layer.circleRadius = MGLStyleValue(interpolationMode: .identity,
diff --git a/platform/ios/docs/img/data-driven-styling/exponential-function-1.png b/platform/ios/docs/img/data-driven-styling/exponential-function-1.png
new file mode 100644
index 0000000000..6aa129a305
--- /dev/null
+++ b/platform/ios/docs/img/data-driven-styling/exponential-function-1.png
Binary files differ
diff --git a/platform/ios/docs/img/data-driven-styling/exponential-function.png b/platform/ios/docs/img/data-driven-styling/exponential-function.png
new file mode 100644
index 0000000000..c14969f0a8
--- /dev/null
+++ b/platform/ios/docs/img/data-driven-styling/exponential-function.png
Binary files differ
diff --git a/platform/macos/docs/guides/Data-Driven Styling.md b/platform/macos/docs/guides/Data-Driven Styling.md
index 8344de23c9..9e38e71318 100644
--- a/platform/macos/docs/guides/Data-Driven Styling.md
+++ b/platform/macos/docs/guides/Data-Driven Styling.md
@@ -6,7 +6,9 @@
# Data-Driven Styling
-Mapbox’s data-driven styling features allow you to use data properties to style your maps. You can style objects within the same layer differently based on their individual attributes. This enables you to style icons, routes, parks, and more based on feature attributes.
+Mapbox’s data-driven styling features allow you to use data properties to style your maps. You can style map features automatically based on their individual attributes.
+
+Vary POI icons, transit route line colors, city polygon opacity, and more based on any attribute in your data. Need to visualize hotel data by price? You can have your map’s point radii and colors change automatically with your data.
![available bikes](img/data-driven-styling/citibikes.png) ![subway lines](img/data-driven-styling/polylineExample.png)
@@ -17,8 +19,8 @@ This guide uses earthquake data from the [U.S. Geological Survey](https://earthq
There are three subclasses of `MGLStyleFunction`:
-* `MGLCameraStyleFunction` - For a style value that changes with zoom level. For example, you can make the radius of a circle to increase based on zoom level. In iOS SDK v3.4, this was a `MGLStyleFunction`.
-* `MGLSourceStyleFunction` - For a style value that changes with the attributes of a feature. You can adjust the radius of a circle based on the magnitude of an earthquake, for example.
+* `MGLCameraStyleFunction` - For a style value that changes with zoom level. For example, you can make the radius of a circle increase according to zoom level.
+* `MGLSourceStyleFunction` - For a style value that changes with the attributes of a feature. For example, you can adjust the radius of a circle based on the magnitude of an earthquake.
* `MGLCompositeStyleFunction` - For a style value that changes with both zoom level and attribute values. For example, you can add a circle layer where each circle has a radius based on both zoom level and the magnitude of an earthquake.
The documentation for individual style properties will note which style functions are enabled for that property.
@@ -27,41 +29,70 @@ The documentation for individual style properties will note which style function
Stops are key-value pairs that that determine a style value. With a `MGLCameraSourceFunction` stop, you can use a dictionary with a zoom level for a key and a `MGLStyleValue` for the value. For example, you can use a stops dictionary with zoom levels 0, 10, and 20 as keys, and yellow, orange, and red as the values. A `MGLSourceStyleFunction` uses the relevant attribute value as the key.
+```swift
+let stops = [0: MGLStyleValue(rawValue: UIColor.yellow),
+ 2.5: MGLStyleValue(rawValue: UIColor.orange),
+ 5: MGLStyleValue(rawValue: UIColor.red),
+ 7.5: MGLStyleValue(rawValue: UIColor.blue),
+ 10: MGLStyleValue(rawValue: UIColor.white)]
+```
+
## Interpolation Mode
The effect a key has on the style value is determined by the interpolation mode. There are four interpolation modes that can be used with a source style function: exponential, interval, categorical, and identity. You can also use exponential and interval interpolation modes with a camera style function.
-### Exponential (or Linear)
+### Linear
-`MGLInterpolationModelExponential` creates a linear or exponential effect based on the values. The key value is the starting point for interpolation, and the style value is based on where an attribute value falls between two keys. By default, `MGLInterpolationModeExponential` uses an interpolation base of 1. This causes a linear relationship between the style value and stop key.
+`MGLInterpolationModelExponential` interpolates linearly or exponentially between style function stop values. By default, the `MGLStyleFunction` options parameter `MGLStyleFunctionOptionInterpolationBase` equals `1`, which represents linear interpolation, and doesn’t need to be included in the options dictionary.
The stops dictionary below, for example, shows colors that continuously shift from yellow to orange to red to blue to white based on the attribute value.
``` 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 source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
- style.addSource(source)
-
- let stops = [0: MGLStyleValue(rawValue: NSColor.yellow),
- 2.5: MGLStyleValue(rawValue: NSColor.orange),
- 5: MGLStyleValue(rawValue: NSColor.red),
- 7.5: MGLStyleValue(rawValue: NSColor.blue),
- 10: MGLStyleValue(rawValue: NSColor.white)]
-
- let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
- layer.circleColor = MGLStyleValue(interpolationMode: .exponential,
- sourceStops: stops,
- attributeName: "mag",
- options: [.defaultValue: MGLStyleValue<NSColor>(rawValue: .green)])
- layer.circleRadius = MGLStyleValue(rawValue: 10)
- style.insertLayer(layer, below: symbolLayer)
+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 source = MGLShapeSource(identifier: "earthquakes", url: url, options: nil)
+style.addSource(source)
+
+let stops = [0: MGLStyleValue(rawValue: NSColor.yellow),
+ 2.5: MGLStyleValue(rawValue: NSColor.orange),
+ 5: MGLStyleValue(rawValue: NSColor.red),
+ 7.5: MGLStyleValue(rawValue: NSColor.blue),
+ 10: MGLStyleValue(rawValue: NSColor.white)]
+
+let layer = MGLCircleStyleLayer(identifier: "circles", source: source)
+layer.circleColor = MGLStyleValue(interpolationMode: .exponential,
+ sourceStops: stops,
+ attributeName: "mag",
+ options: [.defaultValue: MGLStyleValue<NSColor>(rawValue: .green)])
+layer.circleRadius = MGLStyleValue(rawValue: 10)
+style.insertLayer(layer, below: symbolLayer)
```
![exponential mode](img/data-driven-styling/exponential.png)
+### Exponential
+
+`MGLInterpolationModelExponential` combined with any `MGLStyleFunctionOptionInterpolationBase` greater than `0`, you can interpolate between values exponentially, create an accelerated ramp effect.
+
+Here’s a visualization from Mapbox Studio (see [Working with Mapbox Studio](working-with-mapbox-studio.html)) comparing interpolation base values of `1.5` and `0.5` based on zoom.
+
+<img src="img/data-driven-styling/exponential-function.png" height=344/>
+<img src="img/data-driven-styling/exponential-function-1.png" height=344/>
+
+The example below increases a layer’s `circleRadius` exponentially based on a map’s zoom level. The `MGLStyleFunctionOptionInterpolationBase` is `1.5`.
+
+```swift
+let stops = [12: MGLStyleValue(rawValue: 0.5),
+ 14: MGLStyleValue(rawValue: 2),
+ 18: MGLStyleValue(rawValue: 18)]
+
+layer.circleRadius = MGLStyleValue(interpolationMode: .exponential,
+ cameraStops: stops,
+ options: [.interpolationBase: 1.5])
+```
+
### Interval
`MGLInterpolationModeInterval` creates 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 style value assigned to that key.
@@ -69,6 +100,12 @@ The stops dictionary below, for example, shows colors that continuously shift fr
When we use the stops dictionary given above with an interval interpolation mode, 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
+let stops = [0: MGLStyleValue(rawValue: NSColor.yellow),
+ 2.5: MGLStyleValue(rawValue: NSColor.orange),
+ 5: MGLStyleValue(rawValue: NSColor.red),
+ 7.5: MGLStyleValue(rawValue: NSColor.blue),
+ 10: MGLStyleValue(rawValue: NSColor.white)]
+
layer.circleColor = MGLStyleValue(interpolationMode: .interval,
sourceStops: stops,
attributeName: "mag",
@@ -99,7 +136,7 @@ layer.circleColor = MGLStyleValue(interpolationMode: .categorical,
### Identity
-`MGLInterpolationModeIdentity` uses the attribute’s value as the style value. For example, you can set the `circleRadius` to the earthquake’s magnitude. Since the attribute value itself will be used as the style value, `sourceStops` can be set to `nil`.
+`MGLInterpolationModeIdentity` uses the attribute’s value as the style value. For example, you can set the `circleRadius` to the earthquake’s magnitude. Since the attribute value itself will be used as the style value, `sourceStops` should be set to `nil`.
``` swift
layer.circleRadius = MGLStyleValue(interpolationMode: .identity,