# Add vector style

This API call has been replaced. See [this page](https://docs.ellipsis-drive.com/developers/api-v3/path-vector/styles/add-style) to find the new documentation.

| **Description** | Adds a style to a vector layer. |
| --------------- | ------------------------------- |
| **Endpoint**    | `/path/{pathId}/vector/style`   |
| **Method**      | POST                            |

### Access Level Rules

| **Access Level** | edit+ |
| ---------------- | ----- |

### Processing Units

| **Processing units** | 2 |
| -------------------- | - |

### Parameters

<table><thead><tr><th>Name</th><th width="366">Description</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td><code>pathId</code></td><td>The id of the vector layer.</td><td>true</td><td></td></tr><tr><td><code>name</code></td><td>The name of the new style.</td><td>true</td><td></td></tr><tr><td><code>default</code></td><td>Boolean whether the style should be the default style.</td><td>true</td><td></td></tr><tr><td><code>method</code></td><td>The method of the style.<br>Must be one of "rules", "transitionPoints", "'random", "singleColor" or "fromColorProperty".</td><td>true</td><td></td></tr><tr><td><code>parameters</code></td><td>A JSON containing the parameters of the style. Below table defines the style parameters, whose content differs between methods.</td><td>true</td><td></td></tr></tbody></table>

#### Sample requests for different methods

{% tabs %}
{% tab title="Single Color" %}

```json
//Assings the same color to all vectors
{
    "name": "Vector Style",
    "dashedLine": null,
    "method": "singleColor",
    "popupProperty":"propertyToDisplayAsTextLabel",
    "parameters": {
        "alpha": 0.5,
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        },
        "color": "#c75b1c",
        "pattern":null,
        "icon":null,
        "borderColor": "#934314"        
        }
}
```

{% endtab %}

{% tab title="Rules" %}

```json
//Evaluates logical rules and assigns the color of the first ruele that evaluates true.
{
    "name": "Vector Style",
    "dashedLine": null,
    "method": "transitionPoints",
    "popupProperty":"propertyToDisplayAsTextLabel",
    "parameters": {
        "property": "fid",
        "alpha": 0.5,
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        },
        "continuous": true,
       "rules":[
       {"property":"property1","operator":">","value":0,"color":"#06661f", "pattern":null,"icon":null},
       {"property":"property3","operator":">","value":5,"color":"#c4f0f4", "pattern":null,"icon":null},
       {"property":"property1","operator":">","value":8,"color":"#000000", "pattern":null,"icon":null}
       ],
        "borderColor": "#060200",
        "defaultColor": "#c75b1c",
        "defaultPattern": null,
        "defaultIcon": null        
    }
}
```

{% endtab %}

{% tab title="Random" %}

```json
//Assigns a color to all vectors based on hashing a particular property
{
    "name": "Vector Style",
    "dashedLine": null,
    "method": "random",
    "popupProperty":"propertyToDisplayAsTextLabel",
    "parameters": {
        "alpha": 0.5,
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        },
        "property": "iso_a2",
        "borderColor": "#934314",
        "defaultColor": "#c75b1c",
    }
}
```

{% endtab %}

{% tab title="Transition Points" %}

```json
//Assings colors based on the bin in which the value of a property resides.
//In case continuous=true the colors fade continously.
{
    "name": "Vector Style",
    "dashedLine": null,
    "method": "transitionPoints",
    "popupProperty":"propertyToDisplayAsTextLabel",
    "parameters": {
        "property": "fid",
        "alpha": 0.5,
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        },
        "continuous": true,
        "transitionPoints": [
            {
                "value": 1,
                "color": "#2A5C84",
                "pattern": null,
                "icon":null
            },
            {
                "value": 1524.25,
                "color": "#74AE56"
                "pattern": null,
                "icon":null
            },
            {
                "value": 3047.5,
                "color": "#FFE733"
                "pattern": null,
                "icon":null
            },
            {
                "value": 4570.75,
                "color": "#FF8C01"
                "pattern": null,
                "icon":null
            },
            {
                "value": 6094,
                "color": "#ED2938"
                "pattern": null,
                "icon":null
            }
        ],
        "borderColor": "#060200",
        "defaultColor": "#c75b1c",
        "defaultPattern": null,
        "defaultIcon": null        
    }
}
```

{% endtab %}

{% tab title="Inherit from color property" %}

```json
//Colors a vector based on the hex color that is assigned to the property named 'color' of the vector.
//If the vector in question has no property named 'color' the default color will be used.
{
    "name": "Vector Style",
    "dashedLine": null,
    "method": "fromColorProperty",
    "popupProperty":"propertyToDisplayAsTextLabel",
    "parameters": {
        "defaultColor": "#c75b1c",
        "defaultPattern": null,
        "defaultIcon": null,
        "alpha": 0.5,
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        }
    }
}
```

{% endtab %}

{% tab title="classToColor" %}

```json
//Assigns a specific color to a vector based on the particular value the a chosen property property has for this vector.
{
    "method": "classToColor",
    "popupProperty":"propertyToDisplayAsTextLabel",
    "dashedLine": null,
    "name": "maps vectors to a color based on the value of a certain property",
    "parameters": {
        "alpha": 1,
        "defaultColor": "#c75b1c",
        "defaultPattern": null,
        "defaultIcon": null,
        "property": "myProperty",
        "colorMapping": 
            [
                {"value":"myPropertyValue1", "color": "#2A5C84", "pattern": null, "icon":null},
                {"value":"myPropertyValue2", "color":"#FFE733", "pattern": null, "icon":null},
                {"value":"myPropertyValue3", "color": "#FF8C01", "pattern": null, "icon":null},
                {"value":"myPropertyValue4", "color":"#ED2938", "pattern": null, "icon":null},
            ],
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        }            
    }
}
```

{% endtab %}

{% tab title="Formula" %}

```json
//Allows you to perform algebra on the properties of a vector and assign the resulting  value to a color.
{
    "name": "Vector Style",
    "dashedLine": null,
    "popupProperty":"propertyToDisplayAsTextLabel",
    "method": "formula",
    "parameters": {
        "properties": ["fid"],
        "formula": "5 * property1 ^ 2",
        "defaultColor": "#c75b1c",
        "defaultPattern": null,
        "defaultIcon": null,
        "alpha": 0.5,
        "width": 2,
        "radius": {
            "method": "constant",
            "parameters": {
                "value": 7
            }
        },
        "continuous": true,
        "transitionPoints": [
            {
                "value": 1,
                "color": "#2A5C84",
                "pattern": null,
                "icon": null,
            },
            {
                "value": 1524.25,
                "color": "#74AE56",
                "pattern": null,
                "icon": null,
            },
            {
                "value": 3047.5,
                "color": "#FFE733",
                "pattern": null,
                "icon": null,
            },
            {
                "value": 4570.75,
                "color": "#FF8C01",
                "pattern": null,
                "icon": null,
            },
            {
                "value": 6094,
                "color": "#ED2938",
                "pattern": null,
                "icon": null,
            }
        ],
        "borderColor": "#060200"
    }
}
```

{% endtab %}
{% endtabs %}

The circle radius can be made dependent on the property of a vector using the method "onProperty" this dependency can be made linear or logarithmic.

Example:

```
radius = {"method":"onProperty","parameters":{"property":"propertyToUse","bias":0,"weight":1,"logarithmic":false}}
```

If **dashedLine** is not null lines will become dashed lines. In this case dashedLine should be an array with two floats. The first float indicates the length of the open spaces the second the length of the dashes.

Example:

```
dashedLine=[1,3]
```

A **pattern** must be an object with:

* type: One of solid, diagonal, horizontal or vertical
* width: a float between 1 and 50
* backgroundColor: a hex color, optional.

Example:

```
pattern = {"type":"diagonal", "width": 2, "backgroundColor":"#934314"}
```

Alternatively the **pattern** can be an object of **type** **drive**. In this case you need to include a pathId of a png that is stored on the Drive.

Example:

```
pattern = {"type":"drive", "pathId":"4d695990-ace7-434e-b703-e1d5ae006800"}
```

In this case the png will be used as pattern.&#x20;

An **icon** must be an object with

* name: the name of the icon as a string. &#x20;

All valid inputs for name can be listed with

```
GET /image/listIcons
```

Example:

```
icon = {"name":"dog"}
```

Alternatively the **icon** can be an object of **type** **drive**. In this case you need to include a pathId of a png that is stored on the Drive.

Example:

```
pattern = {"type":"drive", "pathId":"4d695990-ace7-434e-b703-e1d5ae006800"}
```

In this case the png will be used as icon.

#### RECOMMENDED READING

{% content-ref url="../../working-with-vector-data/vector-styling-methods" %}
[vector-styling-methods](https://docs.ellipsis-drive.com/working-with-vector-data/vector-styling-methods)
{% endcontent-ref %}
