Overview
ShapeSource is a map content source that supplies vector shapes to be shown on the map. The shape may be a URL or a GeoJSON object. This is the most commonly used source for displaying custom GeoJSON data.Import
Basic Usage
Using External GeoJSON URL
Clustering Points
Props
A string that uniquely identifies the source.Default:
Mapbox.StyleSource.DefaultSourceIDThe id refers to an existing source in the style. Does not create a new source.
An HTTP(S) URL, absolute file URL, or local file URL relative to the current application’s resource bundle.
shape
GeoJSON.GeometryCollection | GeoJSON.Feature | GeoJSON.FeatureCollection | GeoJSON.Geometry | ShapeAnimatorInterface
The contents of the source. A shape can represent a GeoJSON geometry, a feature, or a feature collection.
Enables clustering on the source for point shapes.
Specifies the radius of each cluster if clustering is enabled. A value of 512 produces a radius equal to the width of a tile.Default:
50Specifies the maximum zoom level at which to cluster points if clustering is enabled. Defaults to one zoom level less than the value of
maxZoomLevel so that, at the maximum zoom level, the shapes are not clustered.Specifies custom properties on the generated clusters if clustering is enabled, aggregating values from clustered points.Has the form
{ "property_name": [operator, map_expression]}, where:operatoris a custom reduce expression that references a special["accumulated"]valuemap_expressionproduces the value of a single point
{ "sum": [["+", ["accumulated"], ["get", "sum"]], ["get", "scalerank"]] }Note: Mapbox GL v8 implementation onlySpecifies the maximum zoom level at which to create vector tiles. A greater value produces greater detail at high zoom levels.Default:
18Specifies the size of the tile buffer on each side. 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.Default:
128Specifies the Douglas-Peucker simplification tolerance. A greater value produces simpler geometries and improves performance.Default:
0.375Whether to calculate line distance metrics. This is required for line layers that specify
lineGradient values.Default: falseSource press listener, gets called when a user presses one of the children layers only if that layer has a higher z-index than another source layers.The event object contains:
features- Array of GeoJSON features that were pressedcoordinates- The geographic coordinates of the presspoint- The screen point of the press
Overrides the default touch hitbox (44x44 pixels) for the source layers.
width- Width of hitbox in pixelsheight- Height of hitbox in pixels
Child layer components that will use this source.
Methods
Access these methods using a ref:getClusterExpansionZoom
Returns the zoom level needed to expand the cluster.feature(string | GeoJSON.Feature) - The feature cluster to expand
Promise<number> - The zoom level needed to expand the cluster
getClusterLeaves
Returns the FeatureCollection from the cluster.feature(number | GeoJSON.Feature) - The feature cluster to expandlimit(number) - The number of points to returnoffset(number) - The amount of points to skip (for pagination)
Promise<GeoJSON.FeatureCollection> - The feature collection
getClusterChildren
Returns the FeatureCollection from the cluster (on the next zoom level).feature(number | GeoJSON.Feature) - The feature cluster to expand
Promise<GeoJSON.FeatureCollection> - The feature collection
Related Components
- VectorSource - For tiled vector data
- CircleLayer - Common layer for point data
- LineLayer - Common layer for line data
- FillLayer - Common layer for polygon data