---
title: "MTGeoJSONSource | Mobile sdk | Mobile sdk ios | Ios"
description: "A geojson source."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# MTGeoJSONSource

```
public class MTGeoJSONSource : MTSource, @unchecked Sendable, Codable
```

A geojson source.

-   `[identifier](#/s:11MapTilerSDK15MTGeoJSONSourceC10identifierSSvp)`
    
    Unique id of the source.
    
    #### Declaration
    
    Swift
    
    ```
    public var identifier: String
    ```
    
-   `[url](#/s:11MapTilerSDK15MTGeoJSONSourceC3url10Foundation3URLVSgvp)`
    
    URL pointing to the geojson resource.
    
    #### Declaration
    
    Swift
    
    ```
    public var url: URL?
    ```
    
-   `[jsonString](#/s:11MapTilerSDK15MTGeoJSONSourceC10jsonStringSSSgvp)`
    
    GeoJSON String.
    
    GeoJSON string parses coordinates as Longitude, Latitude pairs, in that order.
    
    #### Declaration
    
    Swift
    
    ```
    public var jsonString: String?
    ```
    
-   `[type](#/s:11MapTilerSDK15MTGeoJSONSourceC4typeAA12MTSourceTypeOvp)`
    
    Type of the source.
    
    #### Declaration
    
    Swift
    
    ```
    public private(set) var type: MTSourceType { get }
    ```
    
-   `[attribution](#/s:11MapTilerSDK15MTGeoJSONSourceC11attributionSSSgvp)`
    
    Attribution to be displayed when the map is shown to a user.
    
    #### Declaration
    
    Swift
    
    ```
    public var attribution: String?
    ```
    
-   `[buffer](#/s:11MapTilerSDK15MTGeoJSONSourceC6bufferSiSgvp)`
    
    Size of the tile buffer on each side.
    
    Optional number between 0 and 512 inclusive. A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself. Larger values produce fewer rendering artifacts near tile edges and slower performance.
    
    Note
    
    Defaults to 128.
    
    #### Declaration
    
    Swift
    
    ```
    public var buffer: Int?
    ```
    
-   `[isCluster](#/s:11MapTilerSDK15MTGeoJSONSourceC9isClusterSbvp)`
    
    If the data is a collection of point features, sets the points by radius into groups.
    
    Note
    
    Defaults to false.
    
    #### Declaration
    
    Swift
    
    ```
    public var isCluster: Bool
    ```
    
-   `[clusterMaxZoom](#/s:11MapTilerSDK15MTGeoJSONSourceC14clusterMaxZoomSdSgvp)`
    
    Max zoom on which to cluster points if clustering is enabled.
    
    Defaults to one zoom less than maxzoom (so that last zoom features are not clustered).
    
    #### Declaration
    
    Swift
    
    ```
    public var clusterMaxZoom: Double?
    ```
    
-   `[clusterRadius](#/s:11MapTilerSDK15MTGeoJSONSourceC13clusterRadiusSdSgvp)`
    
    Radius of each cluster if clustering is enabled.
    
    A value of 512 indicates a radius equal to the width of a tile.
    
    Note
    
    Defaults to 50.
    
    #### Declaration
    
    Swift
    
    ```
    public var clusterRadius: Double?
    ```
    
-   `[maxZoom](#/s:11MapTilerSDK15MTGeoJSONSourceC7maxZoomSdSgvp)`
    
    Maximum zoom level at which to create vector tiles.
    
    Higher value means greater detail at high zoom levels.
    
    Note
    
    Defaults to 18.
    
    #### Declaration
    
    Swift
    
    ```
    public var maxZoom: Double?
    ```
    
-   `[tolerance](#/s:11MapTilerSDK15MTGeoJSONSourceC9toleranceSdSgvp)`
    
    Douglas-Peucker simplification tolerance.
    
    Higher value means simpler geometries and faster performance.
    
    Note
    
    Defaults to 0.375
    
    #### Declaration
    
    Swift
    
    ```
    public var tolerance: Double?
    ```
    
-   `[lineMetrics](#/s:11MapTilerSDK15MTGeoJSONSourceC11lineMetricsSbSgvp)`
    
    Specifices whether to calculate line distance metrics
    
    #### Declaration
    
    Swift
    
    ```
    public var lineMetrics: Bool?
    ```
    
-   `[init(identifier:url:)](#/s:11MapTilerSDK15MTGeoJSONSourceC10identifier3urlACSS_10Foundation3URLVtcfc)`
    
    Initializes the source with unique id and url to TileJSON resource.
    
    #### Declaration
    
    Swift
    
    ```
    public init(identifier: String, url: URL)
    ```
    
-   `[init(identifier:jsonString:)](#/s:11MapTilerSDK15MTGeoJSONSourceC10identifier10jsonStringACSS_SStcfc)`
    
    Initializes the source with unique id and GeoJSON string.
    
    GeoJSON string parses coordinates as Longitude, Latitude pairs, in that order.
    
    #### Declaration
    
    Swift
    
    ```
    public init(identifier: String, jsonString: String)
    ```
    
-   `[init(identifier:url:attribution:buffer:isCluster:clusterMaxZoom:clusterRadius:maxZoom:tolerance:lineMetrics:)](#/s:11MapTilerSDK15MTGeoJSONSourceC10identifier3url11attribution6buffer9isCluster14clusterMaxZoom0L6Radius03maxN09tolerance11lineMetricsACSS_10Foundation3URLVSgSSSgSiSgSbSdSgA3TSbSgtcfc)`
    
    Initializes the source with all the options.
    
    #### Declaration
    
    Swift
    
    ```
    public init(
        identifier: String,
        url: URL? = nil,
        attribution: String? = nil,
        buffer: Int? = 128,
        isCluster: Bool = false,
        clusterMaxZoom: Double? = nil,
        clusterRadius: Double? = 50,
        maxZoom: Double? = 18,
        tolerance: Double? = 0.375,
        lineMetrics: Bool? = false
    )
    ```
    
-   `[init(from:)](#/s:11MapTilerSDK15MTGeoJSONSourceC4fromACs7Decoder_p_tKcfc)`
    
    Initializes the source from the decoder.
    
    #### Declaration
    
    Swift
    
    ```
    public required init(from decoder: any Decoder) throws
    ```
    
-   `[encode(to:)](#/s:SE6encode2toys7Encoder_p_tKF)`
    
    #### Declaration
    
    Swift
    
    ```
    public func encode(to encoder: Encoder) throws
    ```
    
-   `[setData(data:in:completionHandler:)](#/s:11MapTilerSDK15MTGeoJSONSourceC7setData4data2in17completionHandlery10Foundation3URLV_AA9MTMapViewCys6ResultOyytAA7MTErrorOGcSgtF)`
    
    Sets the data of the source.
    
    Used for updating the source data.
    
    #### Declaration
    
    Swift
    
    ```
    @available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
    @MainActor
    public func setData(data: URL, in mapView: MTMapView, completionHandler: ((Result<Void, MTError>) -> Void)? = nil)
    ```
    
    #### Parameters
    
    <table class="graybox"><tbody><tr><td><code><em>data</em></code></td><td><div><p>url to GeoJSON resource.</p></div></td></tr><tr><td><code><em>mapView</em></code></td><td><div><p>MTMapView which holds the source.</p></div></td></tr><tr><td><code><em>completionHandler</em></code></td><td><div><p>A handler block to execute when function finishes.</p></div></td></tr></tbody></table>
    
-   `[setData(data:in:)](#/s:11MapTilerSDK15MTGeoJSONSourceC7setData4data2iny10Foundation3URLV_AA9MTMapViewCtYaF)` Asynchronous
    
    Sets the data of the source.
    
    Used for updating the source data.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func setData(data: URL, in mapView: MTMapView) async
    ```
    
    #### Parameters
    
    <table class="graybox"><tbody><tr><td><code><em>data</em></code></td><td><div><p>url to GeoJSON resource.</p></div></td></tr><tr><td><code><em>mapView</em></code></td><td><div><p>MTMapView which holds the source.</p></div></td></tr></tbody></table>
    
-   `[addToMap(_:)](#/s:11MapTilerSDK15MTGeoJSONSourceC05addToA0yyAA9MTMapViewCF)`
    
    Adds source to map DSL style.
    
    Prefer `[addSource(_:)](https://docs.maptiler.com/mobile-sdk/ios/api/Classes/MTStyle/#/s:11MapTilerSDK7MTStyleC9addSourceyyAA8MTSource_pYaKF)` on MTMapView instead.
    
    #### Declaration
    
    Swift
    
    ```
    public func addToMap(_ mapView: MTMapView)
    ```
