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

Commit

Permalink
[ios, macos] switched darwin dds file to ejs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkiley committed Mar 14, 2017
1 parent ceabb7d commit cd8ca4e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 75 deletions.
1 change: 1 addition & 0 deletions Data-Driven Styling.md.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wat
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ To do - JK:
-%>
<!--
This file is generated.
Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.
Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code`.
-->

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

![available bikes](img/data-driven-styling/citibikes.png)

_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`

Expand All @@ -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.

Expand All @@ -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<UIColor>(interpolationMode: .exponential,
layer.circleColor = MGLStyleValue<<%- cocoaPrefix %>Color>(interpolationMode: .exponential,
sourceStops: stops,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<UIColor>(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<UIColor>(interpolationMode: .interval,
layer.circleColor = MGLStyleValue<<%- cocoaPrefix %>Color>(interpolationMode: .interval,
sourceStops: stops,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<UIColor>(rawValue: .green)])
options: [.defaultValue: MGLStyleValue<<%- cocoaPrefix %>Color>(rawValue: .green)])
```

![interval mode](img/data-driven-styling/interval.png)
<!-- Clarify difference between interval and categorical -->
#####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<UIColor>(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<NSNumber>(interpolationMode: .identity,
sourceStops: nil,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<NSNumber>(rawValue: 0)])
sourceStops: nil,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<NSNumber>(rawValue: 0)])

```

Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
33 changes: 17 additions & 16 deletions platform/ios/docs/guides/Data-Driven Styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ To do - JK:

<!--
This file is generated.
Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.
Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code`.
-->

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

![available bikes](img/data-driven-styling/citibikes.png)

_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`

Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -85,9 +85,10 @@ layer.circleColor = MGLStyleValue<UIColor>(interpolationMode: .interval,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<UIColor>(rawValue: .green)])
```

![interval mode](img/data-driven-styling/interval.png)
<!-- Clarify difference between interval and categorical -->
#####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.

Expand All @@ -99,23 +100,23 @@ let categoricalStops = ["earthquake" : MGLStyleValue(rawValue: UIColor.orange),
"quarry blast": MGLStyleValue(rawValue: UIColor.yellow)]

layer.circleColor = MGLStyleValue<UIColor>(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<NSNumber>(interpolationMode: .identity,
sourceStops: nil,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<NSNumber>(rawValue: 0)])
sourceStops: nil,
attributeName: "mag",
options: [.defaultValue: MGLStyleValue<NSNumber>(rawValue: 0)])

```

Expand Down
1 change: 1 addition & 0 deletions platform/ios/jazzy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit cd8ca4e

Please sign in to comment.