diff --git a/Data-Driven Styling.md.ejs b/Data-Driven Styling.md.ejs new file mode 100644 index 00000000000..3be92177f75 --- /dev/null +++ b/Data-Driven Styling.md.ejs @@ -0,0 +1 @@ +wat diff --git a/platform/darwin/docs/guides/Data-Driven Styling.md b/platform/darwin/docs/guides/Data-Driven Styling.md.ejs similarity index 77% rename from platform/darwin/docs/guides/Data-Driven Styling.md rename to platform/darwin/docs/guides/Data-Driven Styling.md.ejs index d7543054865..2d570ce42d0 100644 --- a/platform/darwin/docs/guides/Data-Driven Styling.md +++ b/platform/darwin/docs/guides/Data-Driven Styling.md.ejs @@ -18,10 +18,10 @@ To do - JK: -%> -##Data-Driven Styling +# 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 attributes. @@ -29,8 +29,8 @@ Mapbox’s data-driven styling features allow you to use data properties to styl _Insert cool overview of things you can do! Try to include polylines & polygons_ -### How to use Data-Driven Styling -This guide uses earthquake data from the [U.S. Geological Survey](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) to style a map based on attributes. For more information about how to work with GeoJSON data in our iOS SDK, please see our [working with GeoJSON data](https://www.mapbox.com/ios-sdk/api/3.5.0-beta.1/working-with-geojson-data.html) guide. +## How to use Data-Driven Styling +This guide uses earthquake data from the [U.S. Geological Survey](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) to style a map based on attributes. For more information about how to work with GeoJSON data in our iOS SDK, please see our [working with GeoJSON data](working-with-geojson-data.html) guide. `MGLStyleFunction` @@ -42,15 +42,15 @@ There are three subclasses of `MGLStyleFunction`: The documentation for individual style properties will note which style functions are enabled for that property. -####Stops +### Stops 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. -####`MGLInterpolationMode` +### 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 +#### Exponential `MGLInterpolationModelExponential` creates a linear effect based on the values. The key value is the base for interpolation, and the style value is based on where an attribute value falls between two keys. @@ -64,66 +64,67 @@ The stops dictionary below, for example, shows colors that continuously shift fr 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 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, + layer.circleColor = MGLStyleValue<<%- cocoaPrefix %>Color>(interpolationMode: .exponential, sourceStops: stops, attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: .green)]) + 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) -#####Interval +#### Interval `MGLInterpolationModeInterval` creates a range using the keys 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. 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 -layer.circleColor = MGLStyleValue(interpolationMode: .interval, +layer.circleColor = MGLStyleValue<<%- cocoaPrefix %>Color>(interpolationMode: .interval, sourceStops: stops, attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: .green)]) + options: [.defaultValue: MGLStyleValue<<%- cocoaPrefix %>Color>(rawValue: .green)]) ``` + ![interval mode](img/data-driven-styling/interval.png) -#####Categorical +#### Categorical Returns the output value that is equal to the stop for the function input. We’re going to use a different stops dictionary than we did for the previous two modes. 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 green to catch any events that do not fall into any of those categories. ``` swift -let categoricalStops = ["earthquake" : MGLStyleValue(rawValue: UIColor.orange), - "explosion" : MGLStyleValue(rawValue: UIColor.red), - "quarry blast": MGLStyleValue(rawValue: UIColor.yellow)] +let categoricalStops = ["earthquake" : MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.orange), + "explosion" : MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.red), + "quarry blast": MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.yellow)] -layer.circleColor = MGLStyleValue(interpolationMode: .categorical, - sourceStops: categoricalStops, - attributeName: "type", - options: [.defaultValue: MGLStyleValue(rawValue: UIColor.blue)]) +layer.circleColor = MGLStyleValue<<%- cocoaPrefix %>Color>(interpolationMode: .categorical, + sourceStops: categoricalStops, + attributeName: "type", + options: [.defaultValue: MGLStyleValue(rawValue: <%- cocoaPrefix %>Color.blue)]) ``` ![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png) -#####Identity +#### 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`. ``` swift layer.circleRadius = MGLStyleFunction(interpolationMode: .identity, - sourceStops: nil, - attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: 0)]) + sourceStops: nil, + attributeName: "mag", + options: [.defaultValue: MGLStyleValue(rawValue: 0)]) ``` diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index f7a0a933c95..79d486eb6ba 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -528,7 +528,7 @@ const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h. const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true}); const guideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/For Style Authors.md.ejs', 'utf8'), { strict: true }); -const ddsGuideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Data-Driven Styling.md', 'utf8'), { strict: true }); +const ddsGuideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Data-Driven Styling.md.ejs', 'utf8'), { strict: true }); const layers = _(spec.layer.type.values).map((value, layerType) => { const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => { diff --git a/platform/ios/docs/guides/Data-Driven Styling.md b/platform/ios/docs/guides/Data-Driven Styling.md index 953133badd2..57d0b6568ed 100644 --- a/platform/ios/docs/guides/Data-Driven Styling.md +++ b/platform/ios/docs/guides/Data-Driven Styling.md @@ -10,10 +10,10 @@ To do - JK: -##Data-Driven Styling +# 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 attributes. @@ -21,8 +21,8 @@ Mapbox’s data-driven styling features allow you to use data properties to styl _Insert cool overview of things you can do! Try to include polylines & polygons_ -### How to use Data-Driven Styling -This guide uses earthquake data from the [U.S. Geological Survey](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) to style a map based on attributes. For more information about how to work with GeoJSON data in our iOS SDK, please see our [working with GeoJSON data](https://www.mapbox.com/ios-sdk/api/3.5.0-beta.1/working-with-geojson-data.html) guide. +## How to use Data-Driven Styling +This guide uses earthquake data from the [U.S. Geological Survey](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) to style a map based on attributes. For more information about how to work with GeoJSON data in our iOS SDK, please see our [working with GeoJSON data](working-with-geojson-data.html) guide. `MGLStyleFunction` @@ -34,15 +34,15 @@ There are three subclasses of `MGLStyleFunction`: The documentation for individual style properties will note which style functions are enabled for that property. -####Stops +### Stops 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. -####`MGLInterpolationMode` +### 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 +#### Exponential `MGLInterpolationModelExponential` creates a linear effect based on the values. The key value is the base for interpolation, and the style value is based on where an attribute value falls between two keys. @@ -73,7 +73,7 @@ The stops dictionary below, for example, shows colors that continuously shift fr ![exponential mode](img/data-driven-styling/exponential.png) -#####Interval +#### Interval `MGLInterpolationModeInterval` creates a range using the keys 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. @@ -85,9 +85,10 @@ layer.circleColor = MGLStyleValue(interpolationMode: .interval, attributeName: "mag", options: [.defaultValue: MGLStyleValue(rawValue: .green)]) ``` + ![interval mode](img/data-driven-styling/interval.png) -#####Categorical +#### Categorical Returns the output value that is equal to the stop for the function input. We’re going to use a different stops dictionary than we did for the previous two modes. @@ -99,23 +100,23 @@ let categoricalStops = ["earthquake" : MGLStyleValue(rawValue: UIColor.orange), "quarry blast": MGLStyleValue(rawValue: UIColor.yellow)] layer.circleColor = MGLStyleValue(interpolationMode: .categorical, - sourceStops: categoricalStops, - attributeName: "type", - options: [.defaultValue: MGLStyleValue(rawValue: UIColor.blue)]) + sourceStops: categoricalStops, + attributeName: "type", + options: [.defaultValue: MGLStyleValue(rawValue: UIColor.blue)]) ``` ![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png) -#####Identity +#### 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`. ``` swift layer.circleRadius = MGLStyleFunction(interpolationMode: .identity, - sourceStops: nil, - attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: 0)]) + sourceStops: nil, + attributeName: "mag", + options: [.defaultValue: MGLStyleValue(rawValue: 0)]) ``` diff --git a/platform/ios/jazzy.yml b/platform/ios/jazzy.yml index 9a119db31e7..5d39e276b66 100644 --- a/platform/ios/jazzy.yml +++ b/platform/ios/jazzy.yml @@ -19,6 +19,7 @@ custom_categories: children: - Adding Points to a Map - Runtime Styling + - Data-Driven Styling - Working with Mapbox Studio - Working with GeoJSON Data - For Style Authors diff --git a/platform/macos/docs/guides/Data-Driven Styling.md b/platform/macos/docs/guides/Data-Driven Styling.md index 953133badd2..54c6ca68d93 100644 --- a/platform/macos/docs/guides/Data-Driven Styling.md +++ b/platform/macos/docs/guides/Data-Driven Styling.md @@ -10,10 +10,10 @@ To do - JK: -##Data-Driven Styling +# 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 attributes. @@ -21,8 +21,8 @@ Mapbox’s data-driven styling features allow you to use data properties to styl _Insert cool overview of things you can do! Try to include polylines & polygons_ -### How to use Data-Driven Styling -This guide uses earthquake data from the [U.S. Geological Survey](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) to style a map based on attributes. For more information about how to work with GeoJSON data in our iOS SDK, please see our [working with GeoJSON data](https://www.mapbox.com/ios-sdk/api/3.5.0-beta.1/working-with-geojson-data.html) guide. +## How to use Data-Driven Styling +This guide uses earthquake data from the [U.S. Geological Survey](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) to style a map based on attributes. For more information about how to work with GeoJSON data in our iOS SDK, please see our [working with GeoJSON data](working-with-geojson-data.html) guide. `MGLStyleFunction` @@ -34,15 +34,15 @@ There are three subclasses of `MGLStyleFunction`: The documentation for individual style properties will note which style functions are enabled for that property. -####Stops +### Stops 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. -####`MGLInterpolationMode` +### 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 +#### Exponential `MGLInterpolationModelExponential` creates a linear effect based on the values. The key value is the base for interpolation, and the style value is based on where an attribute value falls between two keys. @@ -56,66 +56,67 @@ The stops dictionary below, for example, shows colors that continuously shift fr 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 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, + layer.circleColor = MGLStyleValue(interpolationMode: .exponential, sourceStops: stops, attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: .green)]) + options: [.defaultValue: MGLStyleValue(rawValue: .green)]) layer.circleRadius = MGLStyleValue(rawValue: 10) style.insertLayer(layer, below: symbolLayer) ``` ![exponential mode](img/data-driven-styling/exponential.png) -#####Interval +#### Interval `MGLInterpolationModeInterval` creates a range using the keys 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. 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 -layer.circleColor = MGLStyleValue(interpolationMode: .interval, +layer.circleColor = MGLStyleValue(interpolationMode: .interval, sourceStops: stops, attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: .green)]) + options: [.defaultValue: MGLStyleValue(rawValue: .green)]) ``` + ![interval mode](img/data-driven-styling/interval.png) -#####Categorical +#### Categorical Returns the output value that is equal to the stop for the function input. We’re going to use a different stops dictionary than we did for the previous two modes. 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 green to catch any events that do not fall into any of those categories. ``` swift -let categoricalStops = ["earthquake" : MGLStyleValue(rawValue: UIColor.orange), - "explosion" : MGLStyleValue(rawValue: UIColor.red), - "quarry blast": MGLStyleValue(rawValue: UIColor.yellow)] +let categoricalStops = ["earthquake" : MGLStyleValue(rawValue: NSColor.orange), + "explosion" : MGLStyleValue(rawValue: NSColor.red), + "quarry blast": MGLStyleValue(rawValue: NSColor.yellow)] -layer.circleColor = MGLStyleValue(interpolationMode: .categorical, - sourceStops: categoricalStops, - attributeName: "type", - options: [.defaultValue: MGLStyleValue(rawValue: UIColor.blue)]) +layer.circleColor = MGLStyleValue(interpolationMode: .categorical, + sourceStops: categoricalStops, + attributeName: "type", + options: [.defaultValue: MGLStyleValue(rawValue: NSColor.blue)]) ``` ![categorical mode](img/data-driven-styling/categorical1.png) ![categorical mode](img/data-driven-styling/categorical2.png) -#####Identity +#### 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`. ``` swift layer.circleRadius = MGLStyleFunction(interpolationMode: .identity, - sourceStops: nil, - attributeName: "mag", - options: [.defaultValue: MGLStyleValue(rawValue: 0)]) + sourceStops: nil, + attributeName: "mag", + options: [.defaultValue: MGLStyleValue(rawValue: 0)]) ``` diff --git a/platform/macos/jazzy.yml b/platform/macos/jazzy.yml index 3d74fbc652e..93231197186 100644 --- a/platform/macos/jazzy.yml +++ b/platform/macos/jazzy.yml @@ -19,6 +19,7 @@ custom_categories: children: - Working with GeoJSON Data - For Style Authors + - Data-Driven Styling - Info.plist Keys - name: Maps children: