Select platform: [Android](https://developers.google.com/maps/documentation/android-sdk/dds-datasets/add-dataset-to-map.md.txt "View this page for the Android platform docs.") [iOS](https://developers.google.com/maps/documentation/ios-sdk/dds-datasets/add-dataset-to-map.md.txt "View this page for the iOS platform docs.") [JavaScript](https://developers.google.com/maps/documentation/javascript/dds-datasets/add-dataset-to-map.md.txt "View this page for the JavaScript platform docs.")

<br />

This page shows you how to add a dataset to a map, and apply styling.

![Apply styling to a dataset feature.](https://developers.google.com/static/maps/documentation/ios-sdk/images/style-feature.png)

## Prerequisites

Before proceeding, you should have a map ID and map style, and a dataset ID.

- [Create a map ID and map style](https://developers.google.com/maps/documentation/ios-sdk/dds-datasets/start.md.txt#create_a_map_id)
- [Create and upload a dataset](https://developers.google.com/maps/documentation/ios-sdk/dds-datasets/create-dataset.md.txt)

  > [!NOTE]
  > **Note:** You need the ID of your dataset to initialize your app.

## Associate a dataset ID with a map style

To style the features of a dataset, you apply a style function to the
*dataset feature layer* of a map. The dataset feature layer is created when you
*associate a dataset with a map style*.

> [!WARNING]
> **Experimental:** This feature can only be set for light map styles. When you link a light map style that has this feature enabled to a [map
> ID](https://developers.google.com/maps/documentation/ios-sdk/map-ids/mapid-over), the enabled layers are also available for the dark map style.

Take the following steps to associate your dataset with the map style you're
using:

1. In the Google Cloud console, [go to the **Datasets** page](https://console.cloud.google.com/google/maps-apis/datasets).
2. Click the name of the dataset. The **Dataset details** page appears.
3. Click the **Preview** tab.
4. In the **Associated map styles** section, click **ADD MAP STYLE** .  
   ![The Associated map styles section with a plus button that says ADD MAP STYLE to the right.](https://developers.google.com/static/maps/documentation/javascript/dds-datasets/images/add_map_style_cloud_console.png)
5. Click the checkbox(es) for the Map Style(s) to associate and then click **SAVE**.

> [!CAUTION]
> **Caution:** Rendering multiple datasets on a map can affect performance depending on the size and number of datasets.

## Apply styles to the dataset

To style a feature of the dataset layer, use a styling closure that accepts a
[`GMSDatasetFeature`](https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSDatasetFeature.md.txt) and returns a [`GMSFeatureStyle`](https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureStyle.md.txt) to define style
attributes. Then set the style property to a styling closure, which contains
styling logic.

The styling closure is required to be deterministic and return consistent
results when it is applied. If any styling specifications of any feature are
changed, the style must be applied again.

### Set stroke, fill, and point radius

When styling a feature in the style factory function, you can set the:

- **Stroke color and opacity** of the border as defined by the `UIColor`
  class. The default value is transparent (`UIColor.clearColor`).

- **Stroke width** of the border in screen pixels. The default value is 2.

- **Fill color and opacity** as defined by the `UIColor` class. The default
  value is transparent (`UIColor.clearColor`).

- **Point radius** of a point feature between 0 and 128 pixels.

> [!NOTE]
> **Note:** If you want a feature to be invisible, return `nil` from the style function for that feature.

### Use simple style rules

The simplest way to style features is to define constant style attributes such
as color, opacity, and line width. Apply feature style options directly to a
dataset feature layer, or use them in conjunction with custom styling.

### Swift

```swift
let options = GMSMapViewOptions()
options.mapID = GMSMapID(identifier: "YOUR_MAP_ID")
options.camera = GMSCameraPosition(latitude: 40.7, longitude: -74.0, zoom: 12)
let mapView = GMSMapView(options: options)

let layer = mapView.datasetFeatureLayer(of: "YOUR_DATASET_ID")

// Define a style with green fill and stroke.
// Apply the style to all features in the dataset.
layer.style = { feature in
    let style = MutableFeatureStyle()
    style.fillColor = .green.withAlphaComponent(0.1)
    style.strokeColor = .green
    style.strokeWidth = 2.0
    return style
}
```

### Objective-C

```objective-c
GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
options.camera = [GMSCameraPosition cameraWithLatitude:40.7 longitude:-74.0 zoom:12];
options.mapID = [GMSMapID mapIDWithIdentifier:@"MAP_ID"];
GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options];

GMSDatasetFeatureLayer *layer = [mapView datasetFeatureLayerOfDatasetID:@"YOUR_DATASET_ID"];

// Define a style with green fill and stroke.
// Apply the style to all features in the dataset.
layer.style = ^(GMSDatasetFeature *feature) {
    GMSMutableFeatureStyle *style = [GMSMutableFeatureStyle style];
    style.fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.1];
    style.strokeColor = [UIColor greenColor];
    style.strokeWidth = 2.0;
    return style;
};
```

### Use declarative style rules

You can set style rules declaratively based on an attribute of the feature,
and apply them across your entire dataset. You can return `nil` from your
feature style function, for example if you want a subset of features to remain
invisible.

For example, use the
[`GMSDatasetFeature.datasetAttributes`](https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSDatasetFeature.md.txt#datasetattributes)
to return the value of a dataset attribute for a feature. You can then customize
styling of the feature based on its attributes.

This example determines the value of the "highlightColor" attribute of each
feature of a dataset to control the styling:

### Swift

```swift
layer.style = { feature in
    var attributeColor: String = feature.datasetAttributes["highlightColor"]
    // Conditionalize styling based on the value of the "highlightColor" attribute.
    ...
}
```

### Objective-C

```objective-c
// Apply the style to a single dataset feature.
layer.style = ^(GMSDatasetFeature *feature) {
    NSString *attributeColor = feature.datasetAttributes[@"highlightColor"];
    // Conditionalize styling based on the value of the "highlightColor" attribute.
    ...
};
```

## Remove styling from a layer

To remove styling from a layer, set the `style` to `null`:

### Swift

```swift
layer.style = nil
```

### Objective-C

```objective-c
layer.style = nil;
```

You can also return `nil` from your feature style function, for example if you
want a subset of features to remain invisible.