# Sources

### setSource

Adds a source to the map's style.

```javascript
map.setSource(id, geoJson, cluster, maxZoom, radius)
```

#### Parameter

| Required Parameter | Description                                                           | Type   |
| ------------------ | --------------------------------------------------------------------- | ------ |
| id                 | The ID of the source to add. Must not conflict with existing sources. | String |
| geoJson            | A source containing GeoJSON.                                          | Object |

| Optional Parameter | Description                                    | Type    |
| ------------------ | ---------------------------------------------- | ------- |
| cluster            | Cluster enabled or disabled                    | Boolean |
| maxZoom            | Max zoom to cluster points on (defaults to 14) | Numeric |
| radius             | Radius of each cluster when clustering points  | Int     |

#### Example

```javascript
map.setSource('some id', {
    "type": "FeatureCollection",
    "features": [{
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Point",
                "coordinates": [ 126.896038, 37.482901]
            }
        }]
    },
    //If you want to use the cluster
    true, //cluster
    15,  // maxZoom to cluster
    50  // radius 
);
```

### getSource

Returns the source with the specified ID in the map's style.

#### &#x20;Parameter

| Required Parameter | Description                  | Type   |
| ------------------ | ---------------------------- | ------ |
| id                 | The ID of the source to get. | String |

#### Returns

Object : The style source with the specified ID or `undefined` if the ID corresponds to no existing sources.

#### Example

```javascript
const getSourceObj = map.getSource('some id');
```

### setData

Sets the GeoJSON data and re-renders the map.

```javascript
map.getSource('some id').setData(data);
```

#### Parameter

| Required Parameter | Description                                                                                         | Type             |
| ------------------ | --------------------------------------------------------------------------------------------------- | ---------------- |
| data               | A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files. | Object \| string |

#### Example

```javascript
map.getSource('some id').setData({
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "Point",
            "coordinates": [ 126.896038, 37.482901]
        }
    }]
});
```

### isSourceLoaded

Returns a Boolean indicating whether the source is loaded. Returns `true` if the source with the given ID in the map's style has no outstanding network requests, otherwise `false`.

```javascript
const sourceLoaded = map.isSourceLoaded('some id');
```

#### Parameter

| Required Parameter | Description                         | Type   |
| ------------------ | ----------------------------------- | ------ |
| id                 | The ID of the source to be checked. | String |

#### Returns

boolean : A Boolean indicating whether the source is loaded.

#### Example

```javascript
const sourceloaded = map.isSourceLoaded('some id');
```

### removeSource

Removes a source from the map's style.

#### Parameter

| Required Parameter | Description                     | Type   |
| ------------------ | ------------------------------- | ------ |
| id                 | The ID of the source to remove. | String |

#### Returns

Map : Returns itself to allow for method chaining.

#### Example

```javascript
map.removeSource('some id');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fatos-doc.fatos.biz/fatos-api/map/map-control/sources.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
