For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Class GeoJSONSourceMLGL
Hierarchy (View Summary)
- Evented<SourceEventType>
- GeoJSONSourceMLGL
Implements
Index
Constructors
Properties
Methods
Constructors
constructor
- new GeoJSONSourceMLGL(
id: string,
options: GeoJSONSourceOptions,
dispatcher: Dispatcher,
eventedParent: Evented,
): GeoJSONSourceMLGLParameters
- id: string
- options: GeoJSONSourceOptions
- dispatcher: Dispatcher
- eventedParent: Evented
Returns GeoJSONSourceMLGL
Properties
actorPromise
attribution
The attribution for the source.
id
The id for the source. Must not be used by any existing source.
isTileClipped
false if tiles can be drawn outside their boundaries, true if they cannot.
map
maxzoom
The maximum zoom level for the source.
minzoom
The minimum zoom level for the source.
promoteId
reparseOverscaled
true if tiles should be sent back to the worker for each overzoomed zoom level, false if not.
tileSize
The tile size for the source.
type
workerOptions
Methods
abortTile
fire
Calls every listener registered for the event's type.
Parameters
- event: ErrorEvent | MapSourceDataEvent
Returns this
Compatibility with the (type: string, properties: Object) signature from previous versions. See https://github.com/mapbox/mapbox-gl-js/issues/6522, https://github.com/mapbox/mapbox-gl-draw/issues/766
Parameters
- type: keyof SourceEventType
Optionalproperties: object
Returns this
getBounds
Allows getting the source's boundaries. If there's a problem with the source's data, it will return an empty LngLatBounds.
Returns Promise<LngLatBounds>
a promise which resolves to the source's boundaries
getClusterChildren
For clustered sources, fetches the children of the given cluster on the next zoom level (as an array of GeoJSON features).
Parameters
- clusterId: number
The value of the cluster's
cluster_idproperty.
Returns Promise<Feature<Geometry, GeoJsonProperties>[]>
a promise that is resolved when the features are retrieved
- clusterId: number
getClusterExpansionZoom
For clustered sources, fetches the zoom at which the given cluster expands.
Parameters
- clusterId: number
The value of the cluster's
cluster_idproperty.
Returns Promise<number>
a promise that is resolved with the zoom number
- clusterId: number
getClusterLeaves
- getClusterLeaves(
clusterId: number,
limit: number,
offset: number,
): Promise<Feature<Geometry, GeoJsonProperties>[]>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_idproperty. - 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
Example
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); }); - clusterId: number
getClusterOptions
Gets the cluster options currently configured on the source. The returned values mirror the options accepted by
setClusterOptions.Returns GetClusterOptions
the source's current cluster options
getData
Allows to get the source's actual GeoJSON data.
Returns Promise<GeoJSON<Geometry, GeoJsonProperties>>
a promise which resolves to the source's actual GeoJSON data
hasTransition
True if the source has transition, false otherwise.
Returns boolean
listens
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
Parameters
- type: keyof SourceEventType
The event type
Returns boolean
trueif there is at least one registered listener for specified event type,falseotherwise- type: keyof SourceEventType
load
Returns Promise<void>
loaded
True if the source is loaded, false otherwise.
Returns boolean
loadTile
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>
- tile: Tile
off
- off<T extends keyof SourceEventType>(
type: T,
listener: (event: SourceEventType[T]) => void,
): thisRemoves a previously registered event listener.
Type Parameters
- T extends keyof SourceEventType
Parameters
- type: T
The event type to remove listeners for.
- listener: (event: SourceEventType[T]) => void
The listener function to remove.
Returns this
on
- on<T extends keyof SourceEventType>(
type: T,
listener: (event: SourceEventType[T]) => void,
): SubscriptionAdds a listener to a specified event type.
Type Parameters
- T extends keyof SourceEventType
Parameters
- type: T
The event type to add a listen for.
- listener: (event: SourceEventType[T]) => void
The function to be called when the event is fired. The listener function is called with the data object passed to
fire, extended withtargetandtypeproperties.
Returns Subscription
onAdd
This method is called when the source is added to the map.
Parameters
- map: MapMLGL
The map instance
Returns void
- map: MapMLGL
once
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.
Type Parameters
- T extends keyof SourceEventType
Parameters
- type: T
The event type to listen for.
Returns Promise<SourceEventType[T]>
a promise that resolves with the event
- once<T extends keyof SourceEventType>(
type: T,
listener: (event: SourceEventType[T]) => void,
): thisAdds 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.
Type Parameters
- T extends keyof SourceEventType
Parameters
- type: T
The event type to listen for.
- listener: (event: SourceEventType[T]) => void
The function to be called when the event is fired the first time.
Returns this
thiswhen a listener is provided
onRemove
This method is called when the source is removed from the map.
Returns void
serialize
Returns GeoJSONSourceSpecification
A plain (stringifiable) JS object representing the current state of the source. Creating a source using the returned object as the
optionsshould result in a Source that is equivalent to this one.
setClusterOptions
To disable/enable clustering on the source options
Parameters
- options: SetClusterOptions
The options to set
Returns Promise<void>
- options: SetClusterOptions
setData
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.
Returns Promise<void>
- data: string | GeoJSON<Geometry, GeoJsonProperties>
setEventedParent
- setEventedParent(
parent?: Evented<EventTypeMap> | null,
data?: EventedParentData | (() => EventedParentData),
): thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
Optionalparent: Evented<EventTypeMap> | nullOptionaldata: EventedParentData | (() => EventedParentData)
Returns this
shouldReloadTile
Determine whether a tile should be reloaded based on a set of options associated with a MapSourceDataChangedEvent.
Parameters
- tile: Tile
- __namedParameters: GeoJSONSourceShouldReloadTileOptions
Returns boolean
unloadTile
updateData
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.
Returns Promise<void>
- diff: GeoJSONSourceDiff
A source containing GeoJSON. (See the Style Specification for detailed documentation of options.)
GeoJSON is tiled internally for rendering. Features exposed from rendered tiles and related events come from vector-tile data, so GeoJSON foreign members that cannot be represented by the vector-tile format are not preserved there. Keep that data separately, or map it to supported feature properties, if you need it after tiling.
Example
Example
Example
See