On this page

Class GeoJSONSourceMaptiler

A source containing GeoJSON. (See the Style Specification for detailed documentation of options.)

map.addSource('some id', {
    type: 'geojson',
    data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
});
map.addSource('some id', {
   type: 'geojson',
   data: {
       "type": "FeatureCollection",
       "features": [{
           "type": "Feature",
           "properties": {},
           "geometry": {
               "type": "Point",
               "coordinates": [
                   -76.53063297271729,
                   39.18174077994108
               ]
           }
       }]
   }
});
map.getSource('some id').setData({
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "properties": { "name": "Null Island" },
      "geometry": {
          "type": "Point",
          "coordinates": [ 0, 0 ]
      }
  }]
});

Hierarchy (View Summary)

Index

Constructors

Properties

actor: Actor
attribution: string

The attribution for the source.

id: string

The id for the source. Must not be used by any existing source.

isTileClipped: boolean

false if tiles can be drawn outside their boundaries, true if they cannot.

maxzoom: number

The maximum zoom level for the source.

minzoom: number

The minimum zoom level for the source.

reparseOverscaled: boolean

true if tiles should be sent back to the worker for each overzoomed zoom level, false if not.

tileSize: number

The tile size for the source.

type: "geojson"
workerOptions: GeoJSONWorkerOptions

Methods

  • Allows to abort a tile loading.

    Parameters

    • tile: Tile

      The tile to abort

    Returns Promise<void>

  • An ability to fire an event to all the listeners, see Evented

    Parameters

    • event: string | Event

      The event to fire

    • Optionalproperties: any

    Returns this

  • For clustered sources, fetches the zoom at which the given cluster expands.

    Parameters

    • clusterId: number

      The value of the cluster's cluster_id property.

    Returns Promise<number>

    a promise that is resolved with the zoom number

  • For clustered sources, fetches the original points that belong to the cluster (as an array of GeoJSON features).

    Parameters

    • clusterId: number

      The value of the cluster's cluster_id property.

    • limit: number

      The maximum number of features to return.

    • offset: number

      The number of features to skip (e.g. for pagination).

    Returns Promise<Feature<Geometry, GeoJsonProperties>[]>

    a promise that is resolved when the features are retrieved

    Retrieve cluster leaves on click

    map.on('click', 'clusters', (e) => {
      let features = map.queryRenderedFeatures(e.point, {
        layers: ['clusters']
      });
    
      let clusterId = features[0].properties.cluster_id;
      let pointCount = features[0].properties.point_count;
      let clusterSource = map.getSource('clusters');
    
      const features = await clusterSource.getClusterLeaves(clusterId, pointCount);
      // Print cluster leaves in the console
      console.log('Cluster leaves:', features);
    });
    
  • True if the source has transition, false otherwise.

    Returns boolean

  • Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.

    Parameters

    • type: string

      The event type

    Returns boolean

    true if there is at least one registered listener for specified event type, false otherwise

  • True if the source is loaded, false otherwise.

    Returns boolean

  • This method does the heavy lifting of loading a tile. In most cases it will defer the work to the relevant worker source.

    Parameters

    • tile: Tile

      The tile to load

    Returns Promise<void>

  • Removes a previously registered event listener.

    Parameters

    • type: string

      The event type to remove listeners for.

    • listener: Listener

      The listener function to remove.

    Returns this

  • Adds a listener to a specified event type.

    Parameters

    • type: string

      The event type to add a listen for.

    • listener: Listener

      The function to be called when the event is fired. The listener function is called with the data object passed to fire, extended with target and type properties.

    Returns Subscription

  • Adds a listener that will be called only once to a specified event type.

    The listener will be called first time the event fires after the listener is registered.

    Parameters

    • type: string

      The event type to listen for.

    • Optionallistener: Listener

      The function to be called when the event is fired the first time.

    Returns Promise<any> | GeoJSONSource

    this or a promise if a listener is not provided

  • This method is called when the source is removed from the map.

    Returns void

  • To disable/enable clustering on the source options

    Parameters

    Returns this

    map.getSource('some id').setClusterOptions({cluster: false});
    map.getSource('some id').setClusterOptions({cluster: false, clusterRadius: 50, clusterMaxZoom: 14});
    
  • Sets the GeoJSON data and re-renders the map.

    Parameters

    • data: string | GeoJSON<Geometry, GeoJsonProperties>

      A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.

    • waitForCompletion: true

      If true, the method will return a promise that resolves when set data is complete.

    Returns Promise<void>

  • Sets the GeoJSON data and re-renders the map.

    Parameters

    • data: string | GeoJSON<Geometry, GeoJsonProperties>

      A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.

    • OptionalwaitForCompletion: false

      If true, the method will return a promise that resolves when set data is complete.

    Returns this

  • Bubble all events fired by this instance of Evented to this parent instance of Evented.

    Parameters

    • Optionalparent: Evented | null
    • Optionaldata: any

    Returns this

  • Allows to unload a tile.

    Parameters

    • tile: Tile

      The tile to unload

    Returns Promise<void>

  • Updates the source's GeoJSON, and re-renders the map.

    For sources with lots of features, this method can be used to make updates more quickly.

    This approach requires unique IDs for every feature in the source. The IDs can either be specified on the feature, or by using the promoteId option to specify which property should be used as the ID.

    It is an error to call updateData on a source that did not have unique IDs for each of its features already.

    Updates are applied on a best-effort basis, updating an ID that does not exist will not result in an error.

    Parameters

    • diff: GeoJSONSourceDiff

      The changes that need to be applied.

    • waitForCompletion: true

      If true, the method will return a promise that resolves when the update is complete.

    Returns Promise<void>

  • Updates the source's GeoJSON, and re-renders the map.

    For sources with lots of features, this method can be used to make updates more quickly.

    This approach requires unique IDs for every feature in the source. The IDs can either be specified on the feature, or by using the promoteId option to specify which property should be used as the ID.

    It is an error to call updateData on a source that did not have unique IDs for each of its features already.

    Updates are applied on a best-effort basis, updating an ID that does not exist will not result in an error.

    Parameters

    • diff: GeoJSONSourceDiff

      The changes that need to be applied.

    • OptionalwaitForCompletion: false

      If true, the method will return a promise that resolves when the update is complete.

    Returns this

Was this helpful?
SDK JS
Reference
GeoJSONSource