### GeoJSON Source Example Source: https://docs.mapbox.com/style-spec/reference/sources An example of how to configure a GeoJSON source, including options for clustering and feature ID generation. ```json { "type": "geojson", "data": "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson", "cluster": true, "clusterMaxZoom": 14, "clusterRadius": 50, "clusterProperties": { "point_count": ["sum", 1], "point_count_abbreviated": ["number format", ["step", ["get", "point_count"], ["literal", ""], 100, "m", 10000, "k"] ] } } ``` -------------------------------- ### Circle Color based on Feature Temperature Source: https://docs.mapbox.com/style-spec/reference/expressions This example uses the `get` operator to access feature properties and compute color values for a circle. It demonstrates data-driven styling where a feature's `temperature` property influences its `circle-color`. ```json { "circle-color": [ "rgb", // red is higher when feature.properties.temperature is higher ["get", "temperature"], // green is always zero 0, // blue is higher when feature.properties.temperature is lower ["-", 100, ["get", "temperature"]] ] } ``` -------------------------------- ### Example Mapbox Style Layers Object Source: https://docs.mapbox.com/style-spec/reference/layers An example 'layers' object demonstrating a 'fill' type layer for water. This layer references a source and defines its visual style. ```json "layers": [ { "id": "water", "source": "mapbox-streets", "source-layer": "water", "type": "fill", "paint": { "fill-color": "#00ffff" } } ] ``` -------------------------------- ### PromoteId String Example Source: https://docs.mapbox.com/style-spec/reference/types Specifies a property name to be used as a feature ID for all features in a source. This is useful for feature state management. ```json { "promoteId": "some_property" } ``` -------------------------------- ### Import Style Example Source: https://docs.mapbox.com/style-spec/reference/imports-md Demonstrates how to import another style, providing an ID, URL, and configuration options. This is useful for adding basemaps or other pre-defined style components. ```json { "imports": [ { "id": "basemap", "url": "mapbox://styles/mapbox/standard", "config": { "lightPreset": "dusk", "showPointOfInterestLabels": false } } ] } ``` -------------------------------- ### Raster Color Mix Example Source: https://docs.mapbox.com/style-spec/reference/transition Specifies the combination of source RGB channels used to compute the raster value when raster-color is active. This example shows the default luminosity calculation. ```json [ 0.2126, 0.7152, 0.0722, 0 ] ``` -------------------------------- ### Add a model source to a map Source: https://docs.mapbox.com/style-spec/reference/sources This example shows how to add a 3D model source in GLTF format to the map. ```javascript map.addSource('my-model-source', { 'type': 'model', 'url': 'path/to/your/model.gltf' }); ``` -------------------------------- ### Global Transition Configuration Source: https://docs.mapbox.com/style-spec/reference/transition Defines default transition timing for all transitionable properties in a style. Set duration in milliseconds and delay before transition starts. ```json "transition": { "duration": 300, "delay": 0 } ``` -------------------------------- ### String Type Example Source: https://docs.mapbox.com/style-spec/reference/types Represents textual data. In Mapbox styles, strings are enclosed in quotes. ```json { "source": "mySource" } ``` -------------------------------- ### Sprite Index File with Optional Properties Source: https://docs.mapbox.com/style-spec/reference/sprite-md This example demonstrates the use of optional properties like 'content', 'stretchX', and 'stretchY' for advanced image fitting and stretching, particularly useful for elements like highway shields. ```json { "us-highway-shield": { ... "content": [14, 10, 40, 28], "stretchX": [[14, 22], [33, 40]], "stretchY": [[11, 14]] } } ``` -------------------------------- ### Example Mapbox Standard Style Schema Source: https://docs.mapbox.com/style-spec/reference/config This JSON object demonstrates a partial schema for the Mapbox Standard style, showing configuration options for 'showPointOfInterestLabels' and 'lightPreset'. Use this structure to define customizable aspects of a map style. ```json { "schema": { "showPointOfInterestLabels": { "default": true, "type": "boolean" }, "lightPreset": { "default": "noon", "values": [ "dawn", "noon", "dusk", "night" ] } } } ``` -------------------------------- ### Fog Configuration Example Source: https://docs.mapbox.com/style-spec/reference/fog This JSON object defines the global fog effect for a Mapbox style. It includes properties for color, range, and atmospheric blending. ```json "fog": { "range": [0.8, 8], "color": "#dc9f9f", "horizon-blend": 0.5, "high-color": "#245bde", "space-color": "#000000", "star-intensity": 0.15 } ``` -------------------------------- ### Define Layer with Appearances Source: https://docs.mapbox.com/style-spec/reference/appearances-md Example of a symbol layer with 'selected' and 'highlighted' appearances defined. These appearances change icon size, color, and text color based on feature state. ```json { "id": "some-layer", "type": "symbol", ... "appearances": [ { "name": "selected", "condition": ["feature-state", "select"], "properties": { "icon-image": ["image", "poi", {"params": {"fill": "red"}}], "icon-size": 1.3, "text-color": "#ff0000", "text-halo-color": "#c0caff", } }, { "name": "highlighted", "condition": ["feature-state", "highlighted"], "properties": { "icon-size": 2, "text-color": "#4264fb", "text-halo-color": "#c0caff", } } ] } ``` -------------------------------- ### Add an image source to a map Source: https://docs.mapbox.com/style-spec/reference/sources This example adds a georeferenced static image as a source to the map. It requires an image URL and its geographic coordinates. ```javascript map.addSource('my-image-source', { 'type': 'image', 'url': 'https://docs.mapbox.com/mapbox-gl-js/assets/poster.0.0.0.jpg', 'coordinates': [ [-74.0060, 40.7128], [-73.9380, 40.8000], [-73.8700, 40.7700], [-73.9380, 40.6400] ] }); ``` -------------------------------- ### Fog Range Example Source: https://docs.mapbox.com/style-spec/reference/fog This array defines the start and end distance range in which fog fades from transparent to opaque. Negative values are closer to the camera, positive values are farther away. ```json [ 0.5, 10 ] ``` -------------------------------- ### Sprite Index File Example Source: https://docs.mapbox.com/style-spec/reference/sprite-md The index file is a JSON object mapping image identifiers to their properties, including dimensions, location within the sprite, and pixel ratio. ```json { "poi": { "width": 32, "height": 32, "x": 0, "y": 0, "pixelRatio": 1 } } ``` -------------------------------- ### PromoteId Object Example Source: https://docs.mapbox.com/style-spec/reference/types Specifies a property name to be used as a feature ID for features within a specific source layer. Other layers will fallback to their original feature IDs. ```json { "promoteId: { "sourceLayer": "layer_name", "id": "some_property" } } ``` -------------------------------- ### Raster DEM Source Example Source: https://docs.mapbox.com/style-spec/reference/sources Defines a raster DEM source using a TileJSON URL. This is specifically for Mapbox Terrain-DEM. ```json "mapbox-terrain-dem-v1": { "type": "raster-dem", "url": "mapbox://mapbox.mapbox-terrain-dem-v1" } ``` -------------------------------- ### Set Rain Direction Source: https://docs.mapbox.com/style-spec/reference/rain-md Example of setting the main rain particle direction using azimuth and polar angles. Supports smooth-ramp interpolate expressions. ```json [ 0, 45 ] ``` -------------------------------- ### SVG Icon Metadata for Color Parameters Source: https://docs.mapbox.com/style-spec/reference/types Example of SVG metadata defining color parameters for image replacement. These parameters can be referenced in the 'params' object of an image expression. ```xml ... ``` -------------------------------- ### Validate Style JSON with gl-style-validate Source: https://docs.mapbox.com/style-spec/guides Use the `gl-style-validate` command-line tool to check Mapbox style JSON files against the specification. Ensure Node.js is installed to run this tool. ```bash gl-style-validate path/to/style.json ``` -------------------------------- ### Add a vector source to a map Source: https://docs.mapbox.com/style-spec/reference/sources This example demonstrates adding a vector tile source to a map. Vector sources are ideal for large vector datasets and are described using TileJSON or tile URL templates. ```javascript map.addSource('my-tiles', { 'type': 'vector', 'url': 'mapbox://mapbox.mapbox-streets-v8' }); ``` -------------------------------- ### Validate Style JSON with gl-style-validate Source: https://docs.mapbox.com/style-spec/guides-md Use the command-line tool to validate style JSON documents against the Mapbox style specification. Ensure Node.js is installed to use this tool. ```bash $ gl-style-validate path/to/style.json ``` -------------------------------- ### slice Source: https://docs.mapbox.com/style-spec/reference/expressions Returns an item from an array or a substring from a string, based on specified start and end indices. The range is inclusive of the start index but exclusive of the end index. ```APIDOC ## slice ### Description Returns an item from an array or a substring from a string from a specified start index, or between a start index and an end index if set. The return value is inclusive of the start index but not of the end index. ### Syntax ```text ["slice", input: InputType (array or string), index: number ]: OutputType (ItemType or string) ``` ```text ["slice", input: InputType (array or string), index: number, index: number ]: OutputType (ItemType or string) ``` ``` -------------------------------- ### Image Options with Parameters Source: https://docs.mapbox.com/style-spec/reference/types Configure image options for the 'image' expression, including optional parameters for color replacement and iconset selection. ```json "icon-image": [ "image", "oval", // ImageOptions object { "params": { "background": "#000000", "main": ["get", "main_color"] ... }, "iconset": { "id": "some-iconset" } } ] ``` -------------------------------- ### Configure a Video Source Source: https://docs.mapbox.com/style-spec/reference/sources Use a video source to display video content on the map. Provide URLs in multiple formats for cross-browser compatibility. The coordinates define the video's bounding box. ```json { "video": { "type": "video", "urls": [ "https://static-assets.mapbox.com/mapbox-gl-js/drone.mp4", "https://static-assets.mapbox.com/mapbox-gl-js/drone.webm" ], "coordinates": [ [-122.51596391201019, 37.56238816766053], [-122.51467645168304, 37.56410183312965], [-122.51309394836426, 37.563391708549425], [-122.51423120498657, 37.56161849366671] ] } } ``` -------------------------------- ### Number Type Example Source: https://docs.mapbox.com/style-spec/reference/types Represents a numerical value, such as an integer or floating-point number. It is written without quotes. ```json { "text-size": 24 } ``` -------------------------------- ### Transition Configuration Source: https://docs.mapbox.com/style-spec/reference/root Defines global transition timing for property changes, used as a default when no specific transition is set. ```json { "duration": 300, "delay": 0 } ``` -------------------------------- ### index-of Source: https://docs.mapbox.com/style-spec/reference/expressions Returns the first position of an item in an array or a substring in a string, or -1 if not found. An optional starting index can be provided. ```APIDOC ## index-of ### Description Returns the first position at which an item can be found in an array or a substring can be found in a string, or `-1` if the input cannot be found. Accepts an optional index from where to begin the search. ### Syntax ```text ["index-of", keyword: InputType (boolean, string, or number), input: InputType (array or string) ]: number ``` ```text ["index-of", keyword: InputType (boolean, string, or number), input: InputType (array or string), index: number ]: number ``` ``` -------------------------------- ### Optimize glTF Model with gltfpack Source: https://docs.mapbox.com/style-spec/guides/using-3d-models Use gltfpack to compress and optimize glTF models. The flags preserve nodes, materials, extras, and disable quantization for lossless optimization. ```shell $ gltfpack -i input.glb -o output.glb -kn -km -ke -noq ``` -------------------------------- ### 3D Model Source Configuration Source: https://docs.mapbox.com/style-spec/reference/types Configure a 'model' type source to include 3D models with optional orientation, material overrides, and custom feature properties. ```json { "sources" : { "3d-model-source": { "type": "model", "models": { "car-model-1": { "uri": "/assets/car1.glb", "orientation": [0, 45, 0], "materialOverrides": { "car_body_paint" : { // .... } } // ... }, "car-model-2": { "uri": "/assets/car2.glb", // ... } } } } } ``` -------------------------------- ### Set Enum Properties Source: https://docs.mapbox.com/style-spec/reference/types Enum properties accept one of a predefined set of string values. For example, 'line-cap' can be 'butt', 'round', or 'square'. ```json { "line-cap": "round" } ``` -------------------------------- ### is-supported-script Source: https://docs.mapbox.com/style-spec/reference/expressions Returns `true` if the input string is expected to render legibly, and `false` otherwise. ```APIDOC ## is-supported-script ### Description Returns `true` if the input string is expected to render legibly. Returns `false` if the input string contains sections that cannot be rendered without potential loss of meaning (e.g. Indic scripts that require complex text shaping, or right-to-left scripts if the the `mapbox-gl-rtl-text` plugin is not in use in Mapbox GL JS). ### Syntax ```text ["is-supported-script", string]: boolean ``` ``` -------------------------------- ### Featuresets Definition Source: https://docs.mapbox.com/style-spec/reference/root EXPERIMENTAL: Defines sets of features for querying and interaction. This example shows a 'poi' featureset with selectors referencing a 'poi' layer. ```json { "poi": { "selectors": [ { "layer": "poi", "properties": { "type": [ "get", "type" ], "name": [ "get", "name" ], "brand": "ABC" } } ] } } ``` -------------------------------- ### properties Source: https://docs.mapbox.com/style-spec/reference/expressions Returns the feature properties object. It may be more efficient to use `["get", "property_name"]` directly in some cases. ```APIDOC ## properties ### Description Returns the feature properties object. Note that in some cases, it may be more efficient to use `["get", "property_name"]` directly. ### Syntax ```text ["properties"]: object ``` | SDK Support | Mapbox GL JS | Mapbox GL JS | Mapbox GL JS | Mapbox GL JS | | --- | --- | --- | --- | --- | | basic functionality | >= 0.41.0 | >= 6.0.0 | >= 4.0.0 | >= 4.0.0 | ``` -------------------------------- ### let Source: https://docs.mapbox.com/style-spec/reference/expressions Binds expressions to named variables, which can then be referenced in the result expression using `["var", "variable_name"]`. ```APIDOC ## let ### Description Binds expressions to named variables, which can then be referenced in the result expression using ["var", "variable_name"]. ### Syntax ```text ["let", string (alphanumeric literal), any, string (alphanumeric literal), any, ..., OutputType ]: OutputType ``` ``` -------------------------------- ### Define 3D Model Source with Overrides Source: https://docs.mapbox.com/style-spec/guides/using-3d-models-md Configure a 'model' type source, specifying the model URI and lists of node and material names to be overridden in paint properties. ```json // ... "sources": { "3d-model-source": { "type": "model", "models": { "car": { "uri": "/mapbox-gl-js/assets/ego_car.glb", "position": [-74.0135, 40.7153], "orientation": [0, 0, 0], // List of material names to be overridden in paint properties. "materialOverrideNames": [ "body", "lights_brakes", ], // List of node names to be overridden in paint properties. "nodeOverrideNames": [ "doors_front-left", "doors_front-right", "hood", "trunk" ] } } } } // ... ``` -------------------------------- ### Model Material Override Example Source: https://docs.mapbox.com/style-spec/reference/types Use this structure to override properties of individual materials within a 3D model. The key is the material name from the GLTF model. ```json { "material_1_name": { "model-color" : "rgb(255, 255, 0)", "model-opacity" : 0.5 ... }, "material_2_name": { ... "model-emissive-strength": 0.4 } } ``` -------------------------------- ### get Source: https://docs.mapbox.com/style-spec/reference/expressions Retrieves a property value from the current feature's properties, or from another object if a second argument is provided. Returns `null` if the requested property is missing. ```APIDOC ## get ### Description Retrieves a property value from the current feature's properties, or from another object if a second argument is provided. Returns `null` if the requested property is missing. ### Syntax ```text ["get", string]: value ``` ```text ["get", string, object]: value ``` ``` -------------------------------- ### Configure a Model Source Source: https://docs.mapbox.com/style-spec/reference/sources A model source is used for displaying 3D models. It requires a type of 'model' and can optionally include properties like maxzoom, minzoom, models, and tiles or a url. ```json "gltf-models": { "type": "model", .... } ``` -------------------------------- ### Optimize glTF Models with gltfpack Source: https://docs.mapbox.com/style-spec/guides/using-3d-models-md Use `gltfpack` with specific flags to optimize glTF models while preserving nodes, materials, and metadata for Mapbox overrides. This ensures high geometric precision and intact hierarchies. ```bash $ gltfpack -i input.glb -o output.glb -kn -km -ke -noq ``` -------------------------------- ### config Source: https://docs.mapbox.com/style-spec/reference/expressions Retrieves the configuration value for the given option. Returns null if the requested option is missing. ```APIDOC ## config ### Description Retrieves the configuration value for the given option. Returns null if the requested option is missing. ### Syntax ```text ["config", string]: config ``` ```text ["config", string, string]: config ``` | SDK Support | Mapbox GL JS | Mapbox GL JS | Mapbox GL JS | Mapbox GL JS | | --- | --- | --- | --- | --- | | basic functionality | >= 3.0.0 | >= 11.0.0 | >= 11.0.0 | >= 11.0.0 | ``` -------------------------------- ### Model Node Override Example Source: https://docs.mapbox.com/style-spec/reference/types Use this structure to override the transform properties of a specific node within a 3D model. The key is the node name from the 3D model. ```json { "left_door": { "model-orientation": [0,0,-15] }, "trunk": { "model-orientation": [15,0,0] } } ``` -------------------------------- ### imports Source: https://docs.mapbox.com/style-spec/reference/root-md Allows importing other Mapbox styles into the current style. ```APIDOC ## imports ### Description Optional array of style imports. Imports other styles into this style. ### Type array of style imports ``` -------------------------------- ### Layer Definition Source: https://docs.mapbox.com/style-spec/reference/root An example of a single layer within a Mapbox style. Layers define how data from sources is visualized, including type, source, source-layer, and paint properties. ```json [ { "id": "water", "source": "mapbox-streets", "source-layer": "water", "type": "fill", "paint": { "fill-color": "#00ffff" } } ] ``` -------------------------------- ### Get Resolved Locale Source: https://docs.mapbox.com/style-spec/reference/expressions Use 'resolved-locale' to retrieve the IETF language tag of the locale used by a 'collator' object. Useful for identifying the system's default locale. ```json ["resolved-locale", {"locale": "en-US"}] ``` -------------------------------- ### version Source: https://docs.mapbox.com/style-spec/reference/root-md The version of the Mapbox Style Specification. ```APIDOC ## version ### Description Required enum. Style specification version number. Must be 8. ### Type enum ### Example ``` 8 ``` ``` -------------------------------- ### Define Vector Source with TileJSON Properties Source: https://docs.mapbox.com/style-spec/reference/sources Specify vector tile details like 'tiles', 'minzoom', and 'maxzoom' directly within the source definition. ```json "mapbox-streets": { "type": "vector", "tiles": [ "http://a.example.com/tiles/{z}/{x}/{y}.pbf", "http://b.example.com/tiles/{z}/{x}/{y}.pbf" ], "maxzoom": 14 } ``` -------------------------------- ### Define Fog Range Source: https://docs.mapbox.com/style-spec/reference/fog-md Specifies the start and end distance in map units where fog transitions from transparent to opaque. Negative values are closer to the camera, positive values farther away. ```json [ 0.5, 10 ] ``` -------------------------------- ### Define Raster Source with WMS Server URL Source: https://docs.mapbox.com/style-spec/reference/sources Configure a raster source using a WMS server URL. The URL must include a "{bbox-epsg-3857}" token for the bounding box parameter. ```json "wms-imagery": { "type": "raster", "tiles": [ "http://a.example.com/wms?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&width=256&height=256&layers=example" ], "tileSize": 256 } ``` -------------------------------- ### Configure Flat Lighting Source: https://docs.mapbox.com/style-spec/reference/light-md Use the 'light' property to configure flat lighting for extruded or terrain features. This property is ignored if a 3D 'lights' property is present. Prefer using the 'flat' light type in the 'lights' API if supported. ```json "light": { "anchor": "viewport", "color": "white", "intensity": 0.4 } ``` -------------------------------- ### Interpolate circle radius by zoom level Source: https://docs.mapbox.com/style-spec/reference/expressions This example uses the `interpolate` operator to define a linear relationship between zoom level and circle size. The circle radius is 1px at zoom 5 and 5px at zoom 10, interpolating linearly in between. ```json { "circle-radius": [ "interpolate", ["linear"], ["zoom"], 5, 1, 10, 5 ] } ``` -------------------------------- ### Basic Mapbox Style JSON Structure Source: https://docs.mapbox.com/style-spec/guides-md This JSON object defines a basic Mapbox style, including camera defaults, sprite and font URLs, data sources, and rendering layers. It serves as a foundational example for creating custom map styles. ```json { "name": "some-style", "version": 8, // default camera position "center": [ -74, 40.73 ], "zoom": 11.3, "bearing": 20.8, "pitch": 17.5, // sprites and fonts "sprite": "mapbox://sprites/mapbox/light-v11", "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", // spatial data to include, used one-to-many with layers "sources": { "some-vector-source": { "type": "vector", "url": "mapbox://mapbox.mapbox-streets-v8" }, "some-raster-source": { "type": "raster", "url": "mapbox://mapbox.satellite", "tileSize": 256 }, "some-geojson-source": { "type": "geojson", "data": "https://path-to-geojson-data" }, }, // layers define rendering the map, in order; used many-to-one with sources "layers": [ { "id": "some-layer", "type": "fill", "source": "some-vector-source", "source-layer": "some-source-layer", "layout": { "visibility": "visible" }, "paint": { "fill-color": "#888888", "fill-opacity": 0.5 } }, { "id": "another-layer", "type": "circle", "source": "some-geojson-source", "paint": { "circle-radius": 10, "circle-color": "#FF0000" } }, { "id": "some-raster-layer", "type": "raster", "source": "some-raster-source", "minzoom": 0, "maxzoom": 22, "paint": { "raster-opacity": 0.5 } } ] } ``` -------------------------------- ### Configure sky gradient center Source: https://docs.mapbox.com/style-spec/reference/layers Sets the position of the gradient center using [azimuthal, polar] angles in degrees. Requires `sky-type` to be "gradient". ```json { "type": "sky", "paint": { "sky-type": "gradient", "sky-gradient-center": [0, 0] } } ``` -------------------------------- ### var Source: https://docs.mapbox.com/style-spec/reference/expressions References a variable that was previously bound using the `let` expression. ```APIDOC ## var ### Description References variable bound using "let". ### Syntax ```text ["var", previously bound variable name]: the type of the bound expression ``` ``` -------------------------------- ### Add a video source to a map Source: https://docs.mapbox.com/style-spec/reference/sources This snippet demonstrates adding a georeferenced video as a source. It requires a video URL and geographic coordinates, but browser support may be limited. ```javascript map.addSource('my-video-source', { 'type': 'video', 'urls': [ 'https://docs.mapbox.com/mapbox-gl-js/assets/poster.0.0.0.jpg' ], 'coordinates': [ [-74.0060, 40.7128], [-73.9380, 40.8000], [-73.8700, 40.7700], [-73.9380, 40.6400] ] }); ```