### Go Implementation Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/README.md
Example demonstrating how to implement TileJSON producers in Go. This snippet is part of a practical guide for implementations.
```go
package main
import (
"fmt"
"github.com/mapbox/tilejson-go"
)
func main() {
// Example usage:
manifest := tilejson.TileJSON{
TileJSON: "3.0.0",
Name: "my-tileset",
Version: "1.0.0",
Description: "A sample tileset.",
Scheme: "xyz",
Tiles: []string{
"https://example.com/tiles/{z}/{x}/{y}.pbf",
},
}
valid, err := manifest.Validate()
if err != nil {
fmt.Println("Validation error:", err)
}
if valid {
fmt.Println("Manifest is valid.")
}
}
```
--------------------------------
### Node.js Implementation Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/README.md
Example demonstrating how to implement TileJSON producers in Node.js. This snippet is part of a practical guide for implementations.
```javascript
const tilejson = require('tilejson-spec');
// Example usage:
const manifest = {
"tilejson": "3.0.0",
"name": "my-tileset",
"version": "1.0.0",
"description": "A sample tileset.",
"scheme": "xyz",
"tiles": [
"https://example.com/tiles/{z}/{x}/{y}.pbf"
]
};
console.log(tilejson.validate(manifest)); // true
```
--------------------------------
### Python Implementation Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/README.md
Example demonstrating how to implement TileJSON producers in Python. This snippet is part of a practical guide for implementations.
```python
import tilejson
# Example usage:
manifest = {
"tilejson": "3.0.0",
"name": "my-tileset",
"version": "1.0.0",
"description": "A sample tileset.",
"scheme": "xyz",
"tiles": [
"https://example.com/tiles/{z}/{x}/{y}.pbf"
]
}
print(tilejson.validate(manifest)) # True
```
--------------------------------
### Example Tile URL Templates
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md
Provides examples of Tile URL templates, showing how zoom, column, and row are incorporated into the URL structure for different tile formats.
```string
https://tiles.example.com/data/{z}/{x}/{y}.mvt
https://tiles.example.com/data/{z}/{x}/{y}.png
```
--------------------------------
### Example Name Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Specifies a display name for the tileset. Implementations should not interpret this as HTML.
```json
{
"name": "OpenStreetMap Standard"
}
```
--------------------------------
### Raster Tileset Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md
Example for raster tile services, including optional fields like name, description, version, attribution, zoom levels, bounds, and center.
```json
{
"tilejson": "3.0.0",
"name": "Satellite Imagery",
"description": "Pan-sharpened satellite imagery with 15cm ground resolution",
"version": "1.2.0",
"attribution": "© Satellite Imagery Provider",
"tiles": [
"https://imagery.example.com/{z}/{x}/{y}.webp",
"https://imagery-backup.example.com/{z}/{x}/{y}.webp"
],
"minzoom": 0,
"maxzoom": 20,
"bounds": [-180, -85.051129, 180, 85.051129],
"center": [0, 0, 2],
"vector_layers": []
}
```
--------------------------------
### Example Grids Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/README.md
Specifies an array of interactivity endpoints for UTF-Grid. If empty, interactivity is not supported.
```JSON
{
"grids": [
"https://www.example.com/earthsea/1.0.0/{z}/{x}/{y}.grid.json"
]
}
```
--------------------------------
### Example HTML Attribution
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md
Provides an example of an HTML-formatted attribution string. This includes links to data sources and license information.
```html
© OpenStreetMap contributors, ODbL
```
--------------------------------
### TileJSON 2.0.0 Example Manifest
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/version-compatibility.md
An example of a TileJSON manifest file conforming to version 2.0.0, showcasing the 'template' field for interactivity.
```json
{
"tilejson": "2.0.0",
"name": "World Light",
"description": "A light color world map",
"version": "1.0.0",
"attribution": "© OSM contributors",
"scheme": "xyz",
"tiles": [
"http://example.com/{z}/{x}/{y}.png"
],
"template": "{{#__teaser__}}{{NAME}}{{/__teaser__}}",
"legend": "Red = high, Green = low",
"grids": [
"http://example.com/{z}/{x}/{y}.grid.json"
],
"minzoom": 0,
"maxzoom": 18,
"bounds": [-180, -85.05, 180, 85.05],
"center": [-98.573, 39.833, 4]
}
```
--------------------------------
### Example Template Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Provides a Mustache template for formatting grid interaction data, relevant only for legacy UTF-Grid interactivity.
```json
{
"template": "{{#__teaser__}}Name: {{name}}
Population: {{population}}{{/__teaser__}}"
}
```
--------------------------------
### Example TileJSON Version Data
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md
Illustrates a JSON object containing TileJSON and tileset version strings. This example shows how versions are represented in a TileJSON file.
```json
{
"tilejson": "3.0.0",
"version": "1.5.2"
}
```
--------------------------------
### TileJSON 3.0.0 Vector Tileset Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/version-compatibility.md
Example of a TileJSON 3.0.0 manifest for a vector tileset, including a populated `vector_layers` array with layer definitions.
```json
{
"tilejson": "3.0.0",
"tiles": ["http://example.com/{z}/{x}/{y}.pbf"],
"vector_layers": [
{
"id": "roads",
"description": "Road network",
"fields": {
"name": "Road name",
"class": "Road classification"
}
},
{
"id": "buildings",
"fields": {}
}
]
}
```
--------------------------------
### Example Min Zoom Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Sets the minimum zoom level at which tiles are available.
```json
{
"minzoom": 2
}
```
--------------------------------
### TileJSON 3.0.0 Raster Tileset Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/version-compatibility.md
Example of a TileJSON 3.0.0 manifest for a raster tileset, including an empty `vector_layers` array.
```json
{
"tilejson": "3.0.0",
"tiles": ["http://example.com/{z}/{x}/{y}.png"],
"vector_layers": []
}
```
--------------------------------
### Example Legend Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/README.md
Provides a string for a map legend, which can be treated as HTML or literal text.
```JSON
{
"legend": "Dangerous zones are red, safe zones are green"
}
```
--------------------------------
### Example Version Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Specifies the semantic version of the tileset data for cache invalidation. Follows major.minor.patch versioning semantics.
```json
{
"version": "2.1.0"
}
```
--------------------------------
### Example Center Array
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md
An example of a Center array, specifying the longitude, latitude, and zoom level for the map's default view.
```json
[-122.4, 37.8, 12]
```
--------------------------------
### Example Scheme Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Defines the tile coordinate scheme, either 'xyz' (default) or 'tms'. Assumes Global Mercator projection.
```json
{
"scheme": "tms"
}
```
--------------------------------
### Example Grids Configuration
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Specifies UTF-Grid interactivity endpoints for legacy interactive maps. Use GL feature state for modern interactivity.
```json
{
"grids": [
"https://www.example.com/{z}/{x}/{y}.grid.json"
]
}
```
--------------------------------
### Example Mustache Template
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md
An example of a Mustache template string used for formatting UTF-Grid interaction data. This is mostly deprecated.
```mustache
{{#__teaser__}}
Population: {{population}}
{{/__teaser__}} ``` -------------------------------- ### JSON Schema Validation in JavaScript/Node.js Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/INDEX.md Example of using Ajv to compile and validate a schema in JavaScript. Ensure Ajv is installed. ```javascript const Ajv = require('ajv'); const validate = new Ajv().compile(schema); ``` -------------------------------- ### Vector Tileset Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/INDEX.md A recommended TileJSON structure for vector tilesets. Includes tile URLs and vector layer definitions. ```json { "tilejson": "3.0.0", "name": "Tileset Name", "tiles": ["https://example.com/{z}/{x}/{y}.pbf"], "vector_layers": [ { "id": "layer-name", "fields": { "property": "Property description" } } ] } ``` -------------------------------- ### Example TileJSON Attribution Source: https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/README.md Provides an example of the 'attribution' property in TileJSON, used to display credit information to users. Implementations may interpret this as HTML or plain text. ```JSON { "attribution": "OSM contributors" } ``` -------------------------------- ### Example Bounds Array Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md An example of a Bounds array, specifying the minimum and maximum longitude and latitude for a geographic area. ```json [-122.4, 37.7, -122.3, 37.9] ``` -------------------------------- ### Complete Vector Tileset Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md A comprehensive TileJSON manifest for a vector tileset, including all optional fields and detailed definitions for vector layers and their fields. ```json { "tilejson": "3.0.0", "name": "OpenStreetMap Vector Tiles", "description": "Complete OpenStreetMap vector tiles with roads, buildings, water, and administrative boundaries.", "version": "2.5.3", "attribution": "© OpenStreetMap contributors, ODbL 1.0", "license": "https://opendatacommons.org/licenses/odbl/1-0/", "scheme": "xyz", "tiles": [ "https://tiles.example.com/data/v1/{z}/{x}/{y}.pbf", "https://tiles-backup.example.com/data/v1/{z}/{x}/{y}.pbf" ], "minzoom": 0, "maxzoom": 18, "fillzoom": 12, "bounds": [-180, -85.051129, 180, 85.051129], "center": [0, 20, 2], "vector_layers": [ { "id": "water", "description": "Water bodies including oceans, lakes, and rivers", "minzoom": 0, "maxzoom": 18, "fields": { "osm_id": "OpenStreetMap way ID", "name": "Water body name", "type": "body_of_water, riverbank, or canal", "intermittent": "Whether water body is intermittent (boolean)" } }, { "id": "landuse", "description": "Land use classifications", "minzoom": 2, "maxzoom": 18, "fields": { "class": "landcover, grass, wood, or other class", "name": "Named area (if applicable)" } }, { "id": "roads", "description": "Complete road network from highways to footpaths", "minzoom": 2, "maxzoom": 18, "fields": { "osm_id": "OpenStreetMap way ID", "name": "Road name or designation", "type": "motorway, trunk, primary, secondary, tertiary, residential, service, etc.", "class": "Simplified road classification", "lanes": "Number of traffic lanes (integer)", "maxspeed": "Speed limit in km/h (integer or null)", "oneway": "Direction of traffic flow (forward, backward, or null)", "bridge": "Bridge type if applicable", "tunnel": "Tunnel type if applicable", "surface": "pavement, paved_smooth, paved, compacted, dirt, gravel, ground, or null", "access": "Public accessibility restrictions" } }, { "id": "buildings", "description": "Building footprints with height information", "minzoom": 12, "maxzoom": 18, "fields": { "osm_id": "OpenStreetMap way ID", "name": "Building name if available", "type": "Building classification (house, apartment, commercial, etc.)", "height": "Height in meters (float or null)", "min_height": "Minimum height for setbacks (float or null)", "levels": "Number of floors (integer or null)", "min_level": "Minimum floor level" } }, { "id": "admin", "description": "Administrative boundaries (countries, states, districts)", "minzoom": 0, "maxzoom": 18, "fields": { "osm_id": "OpenStreetMap relation ID", "name": "Area name", "admin_level": "Administrative level (0-12, lower is higher level)", "wikipedia": "Wikipedia article reference", "wikidata": "Wikidata item ID", "iso_3166_1_alpha_2": "ISO 3166-1 alpha-2 country code (for countries)" } }, { "id": "places", "description": "Points of interest, cities, and landmarks", "minzoom": 0, "maxzoom": 18, "fields": { "osm_id": "OpenStreetMap node ID", "name": "Place or POI name", "class": "city, town, village, hamlet, island, mountain, etc.", "rank": "Importance ranking (lower = more important)", "population": "Population figure if available", "capital": "Whether place is a capital", "wikipedia": "Wikipedia article reference" } } ] } ``` -------------------------------- ### JSON Schema Validation in Python Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/INDEX.md Example of using the jsonschema library to validate an instance against a schema in Python. Ensure jsonschema is installed. ```python import jsonschema jsonschema.validate(instance, schema) ``` -------------------------------- ### VectorLayer Fields Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md Illustrates the structure of the 'fields' property, mapping attribute names to human-readable descriptions. ```json { "fields": { "name": "Street or place name", "type": "Classification (residential, commercial, industrial)", "height": "Building height in meters", "population": "Number of residents" } } ``` -------------------------------- ### Example Max Zoom Configuration Source: https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/README.md Sets the maximum zoom level for tile availability. Must be between 0 and 30. ```JSON { "maxzoom": 11 } ``` -------------------------------- ### Raster Tileset with Overlay GeoJSON Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md Raster tileset example that includes a 'data' field for overlaying GeoJSON data, specifying sources for both raster tiles and GeoJSON features. ```json { "tilejson": "3.0.0", "name": "Aeronautical Chart", "description": "FAA sectional aeronautical charts with restricted airspace", "version": "2024-01", "attribution": "FAA, Federal Aviation Administration", "tiles": [ "https://chart.example.com/sectional/{z}/{x}/{y}.png" ], "minzoom": 4, "maxzoom": 12, "bounds": [-130, 20, -65, 50], "center": [-95, 37, 4], "data": [ "https://data.example.com/restricted_airspace.geojson", "https://data.example.com/airports/{z}/{x}/{y}.geojson" ], "vector_layers": [] } ``` -------------------------------- ### Vector Tileset Manifest Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md A comprehensive TileJSON manifest for a vector tileset. Includes details on layers, fields, zoom levels, and attribution. ```json { "tilejson": "3.0.0", "name": "Streets", "description": "Complete street network with traffic signals and signage", "version": "1.5.2", "attribution": "© OpenStreetMap contributors", "scheme": "xyz", "tiles": [ "https://tiles.example.com/v1/streets/{z}/{x}/{y}.pbf" ], "minzoom": 0, "maxzoom": 18, "bounds": [-180, -85.051129, 180, 85.051129], "center": [-0.1276, 51.5074, 10], "vector_layers": [ { "id": "roads", "description": "Road network", "minzoom": 2, "maxzoom": 18, "fields": { "type": "Road type (motorway, trunk, primary, secondary, residential)", "name": "Road name or number", "lanes": "Number of lanes", "oneway": "Boolean indicating one-way traffic" } }, { "id": "buildings", "description": "Building footprints", "minzoom": 12, "maxzoom": 18, "fields": { "height": "Building height in meters", "type": "Building classification" } } ] } ``` -------------------------------- ### Example TileJSON Center Source: https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/README.md Shows an example of the 'center' property in TileJSON, defining the default longitude, latitude, and zoom level for map implementations. These values must be within the specified bounds and zoom range. ```JSON { "center": [ -76.275329586789, 39.153492567373, 8 ] } ``` -------------------------------- ### Tile URL Replacement Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/quick-reference.md Illustrates how URL template variables like {z}, {x}, and {y} are replaced with actual tile coordinates to form a complete tile request URL. ```text https://tiles.example.com/{z}/{x}/{y}.pbf → https://tiles.example.com/12/1234/5678.pbf ``` -------------------------------- ### Example Custom Properties JSON Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md An example JSON object demonstrating the use of custom properties in TileJSON. These can include URLs, contact information, or service level agreements. ```json { "custom_logo_url": "https://example.com/logo.png", "owner_contact": "tiles@example.com", "service_level_agreement": "99.9%", "preview_image": "https://example.com/preview.png" } ``` -------------------------------- ### Minimal Vector Tileset Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md The simplest valid vector tileset requires only the 'tilejson' version, 'tiles' array, and 'vector_layers' definition. ```json { "tilejson": "3.0.0", "tiles": ["https://example.com/{z}/{x}/{y}.pbf"], "vector_layers": [ { "id": "default", "fields": {} } ] } ``` -------------------------------- ### Raster Tileset Manifest Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md A TileJSON manifest for a raster tileset. Specifies image format, zoom levels, and bounding box. ```json { "tilejson": "3.0.0", "name": "Satellite Imagery", "description": "Pan-sharpened 15cm resolution satellite imagery", "version": "1.0.0", "attribution": "© Satellite Imagery Provider", "tiles": [ "https://imagery.example.com/{z}/{x}/{y}.webp" ], "minzoom": 0, "maxzoom": 20, "bounds": [-180, -85.051129, 180, 85.051129], "center": [0, 0, 2], "vector_layers": [] } ``` -------------------------------- ### Raster Tileset Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/INDEX.md A TileJSON structure for raster tilesets. Specifies tile URLs for raster images. ```json { "tilejson": "3.0.0", "name": "Tileset Name", "tiles": ["https://example.com/{z}/{x}/{y}.png"], "vector_layers": [] } ``` -------------------------------- ### Valid TileJSON Manifests Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md Examples of TileJSON manifests that conform to the specification. These cover minimal and complete vector and raster tile configurations. ```json [ { "name": "Minimal Vector", "manifest": { "tilejson": "3.0.0", "tiles": ["https://example.com/{z}/{x}/{y}.pbf"], "vector_layers": [] } }, { "name": "Complete Raster", "manifest": { "tilejson": "3.0.0", "name": "Satellite", "tiles": ["https://example.com/{z}/{x}/{y}.png"], "vector_layers": [] } }, { "name": "Full Vector", "manifest": { "tilejson": "3.0.0", "name": "Streets", "description": "Street network", "version": "1.0.0", "tiles": ["https://example.com/{z}/{x}/{y}.pbf"], "minzoom": 0, "maxzoom": 18, "bounds": [-180, -85, 180, 85], "center": [0, 0, 2], "vector_layers": [ { "id": "roads", "fields": {"name": "Road name"} } ] } } ] ``` -------------------------------- ### Example Max Zoom Configuration Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md Sets the maximum zoom level at which tiles are available. Clients may request higher zoom levels. ```json { "maxzoom": 18 } ``` -------------------------------- ### Multi-Scale Vector Tileset Example Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md A complex vector tileset demonstrating multi-scale capabilities, where different vector layers are defined with specific minzoom and maxzoom properties to control their visibility at various zoom levels. ```json { "tilejson": "3.0.0", "name": "Multi-Scale Basemap", "description": "Progressive detail levels from world view to street level", "version": "1.0.0", "attribution": "© Map Data Contributors", "tiles": ["https://tiles.example.com/{z}/{x}/{y}.pbf"], "minzoom": 0, "maxzoom": 20, "bounds": [-180, -85.051129, 180, 85.051129], "center": [0, 0, 1], "vector_layers": [ { "id": "oceans", "description": "Ocean bodies (visible at all zoom levels)", "minzoom": 0, "maxzoom": 20, "fields": { "name": "Body of water name" } }, { "id": "countries", "description": "Country boundaries (visible from z0)", "minzoom": 0, "maxzoom": 20, "fields": { "name": "Country name", "iso_a3": "ISO 3166-1 alpha-3 code" } }, { "id": "states", "description": "State/province boundaries (visible from z3)", "minzoom": 3, "maxzoom": 20, "fields": { "name": "State or province name", "country": "Parent country" } }, { "id": "counties", "description": "County/district boundaries (visible from z6)", "minzoom": 6, "maxzoom": 20, "fields": { "name": "County or district name" } }, { "id": "municipalities", "description": "City/municipality boundaries (visible from z10)", "minzoom": 10, "maxzoom": 20, "fields": { "name": "Municipality name", "population": "Population estimate" } }, { "id": "major_roads", "description": "Major roads (visible from z2)", "minzoom": 2, "maxzoom": 20, "fields": { "name": "Road name", "class": "motorway or trunk" } }, { "id": "secondary_roads", "description": "Secondary roads (visible from z6)", "minzoom": 6, "maxzoom": 20, "fields": { "name": "Road name", "class": "primary or secondary" } }, { "id": "streets", "description": "Local streets (visible from z12)", "minzoom": 12, "maxzoom": 20, "fields": { "name": "Street name", "class": "residential or service" } }, { "id": "buildings", "description": "Building footprints (visible from z13)", "minzoom": 13, "maxzoom": 20, "fields": { "height": "Building height in meters" } } ] } ``` -------------------------------- ### Attribution Best Practices in TileJSON Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/quick-reference.md Examples of how to format attribution strings in TileJSON, including simple text, HTML links, multiple attributions, and logos. ```javascript "attribution": "© OpenStreetMap contributors" ``` ```javascript "attribution": "© OpenStreetMap contributors" ``` ```javascript "attribution": "© OSM contributors | Imagery © Satellite Provider" ``` ```javascript "attribution": "
© Provider"
```
--------------------------------
### TileJSON 3.0.0 Center Validation Examples
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/version-compatibility.md
Demonstrates valid and invalid `center` configurations for TileJSON 3.0.0, considering bounds and zoom level constraints.
```json
// Valid - Center within bounds and zoom within range
{
"bounds": [-122.5, 37.7, -122.3, 37.9],
"minzoom": 0,
"maxzoom": 18,
"center": [-122.4, 37.8, 10]
}
```
```json
// Invalid - Center outside bounds
{
"bounds": [-122.5, 37.7, -122.3, 37.9],
"center": [-123.0, 37.8, 10]
}
```
```json
// Invalid - Center zoom outside minzoom/maxzoom
{
"minzoom": 5,
"maxzoom": 18,
"center": [-122.4, 37.8, 2]
}
```
--------------------------------
### WGS 84 Bounds Example
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/quick-reference.md
Represents the full web mercator extent for WGS 84 coordinate system.
```json
[-180, -85.051129, 180, 85.051129] // Full web mercator extent
```
--------------------------------
### Example TileJSON Bounds for a Single Point
Source: https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/README.md
Illustrates a specific case for the 'bounds' property where all coordinate values are identical, representing a single point geometry for the tileset.
```JSON
{
"bounds": [-122.34, 47.65, -122.34, 47.65]
}
```
--------------------------------
### Complete Vector Tileset Template
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/quick-reference.md
A comprehensive TileJSON manifest example including all common properties for a vector tileset. This serves as a template for defining tileset metadata, sources, and layer configurations.
```json
{
"tilejson": "3.0.0",
"name": "Example",
"description": "Description",
"version": "1.0.0",
"attribution": "© Attribution",
"scheme": "xyz",
"tiles": ["https://example.com/{z}/{x}/{y}.pbf"],
"minzoom": 0,
"maxzoom": 18,
"fillzoom": 12,
"bounds": [-180, -85.051129, 180, 85.051129],
"center": [0, 0, 2],
"vector_layers": [
{
"id": "layer-id",
"description": "Layer description",
"minzoom": 0,
"maxzoom": 18,
"fields": {
"property": "Property description"
}
}
]
}
```
--------------------------------
### Load and Fetch TileJSON (JavaScript)
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/quick-reference.md
Loads TileJSON data from a URL and provides a function to get a specific tile URL. Includes basic validation for the loaded manifest.
```javascript
async function loadTileJSON(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const manifest = await response.json();
// Validate
if (!manifest.tilejson || !manifest.tiles?.length || !manifest.vector_layers) {
throw new Error('Invalid TileJSON');
}
return manifest;
}
// Get a tile URL
function getTileURL(manifest, z, x, y) {
const template = manifest.tiles[Math.floor(Math.random() * manifest.tiles.length)];
return template.replace('{z}', z).replace('{x}', x).replace('{y}', y);
}
// Usage
const manifest = await loadTileJSON('https://example.com/data.json');
const url = getTileURL(manifest, 12, 1234, 5678);
```
--------------------------------
### Example Legend Content
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/tilejson-specification.md
Provides legend content for the tileset, which may be treated as HTML or literal text. Ensure content is sanitized to prevent XSS attacks.
```json
{
"legend": "Red zones indicate hazardous areas; green zones are safe"
}
```
--------------------------------
### Migrating TileJSON from 1.0.0 to 3.0.0
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/version-compatibility.md
This JavaScript example demonstrates the transformation of a TileJSON 1.0.0 object to a 3.0.0 compatible format. Key changes include renaming 'formatter' to 'template' and adding the 'vector_layers' property.
```javascript
// 1.0.0
{
"tilejson": "1.0.0",
"formatter": "function(options, data) { return data.name; }",
"maxzoom": 22,
"tiles": ["..."]
}
// 3.0.0
{
"tilejson": "3.0.0",
"template": "{{#__teaser__}}{{name}}{{/__teaser__}}",
"maxzoom": 22,
"tiles": ["..."],
"vector_layers": [
{
"id": "layer1",
"fields": {}
}
]
}
```
--------------------------------
### Custom Properties in TileJSON
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/examples.md
This example shows how to include implementation-specific custom properties within a TileJSON object. These properties can extend the standard specification with additional metadata relevant to the tile provider.
```json
{
"tilejson": "3.0.0",
"name": "Premium Basemap",
"description": "Professional cartography basemap with custom rendering hints",
"version": "3.1.0",
"attribution": "© Premium Map Services",
"tiles": ["https://premium-tiles.example.com/{z}/{x}/{y}.pbf"],
"minzoom": 0,
"maxzoom": 20,
"bounds": [-180, -85.051129, 180, 85.051129],
"center": [0, 0, 2],
"vector_layers": [
{
"id": "roads",
"fields": {
"name": "Road name",
"type": "Road type"
}
}
],
"custom_properties": {
"owner": "Example Maps Inc.",
"contact_email": "support@example.com",
"support_url": "https://support.example.com",
"documentation_url": "https://docs.example.com",
"api_key_required": true,
"rate_limit_requests_per_second": 100,
"rate_limit_daily_tiles": 5000000,
"billing_account": "PRO-12345",
"sla_uptime_percentage": 99.95,
"cache_ttl_seconds": 86400,
"update_frequency": "daily",
"attribution_requirements": {
"logo_url": "https://example.com/logo.png",
"logo_alt_text": "Example Maps",
"attribution_text": "© Example Maps",
"attribution_html_required": true
},
"rendering_hints": {
"tms_scheme": false,
"supports_retina": true,
"webp_supported": true,
"dpr_variants": [1, 2]
}
}
}
```
--------------------------------
### Serve TileJSON with Version-Specific Modifications
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/version-compatibility.md
Servers should adjust TileJSON responses based on the requested version, typically specified via a query parameter. This example demonstrates removing properties or converting formats to match older versions.
```javascript
app.get('/tilejson', (req, res) => {
const manifest = getTileJSONData();
const version = req.query.version || '3.0.0';
if (version === '2.2.0') {
delete manifest.fillzoom;
}
if (version === '2.0.0' || version === '1.0.0') {
delete manifest.data;
}
if (version === '1.0.0') {
manifest.formatter = manifest.template;
delete manifest.template;
}
res.json(manifest);
});
```
--------------------------------
### Example HTML Legend
Source: https://github.com/mapbox/tilejson-spec/blob/master/_autodocs/types.md
Shows an example of an HTML-formatted legend. This legend uses spans with inline styles and bullet points to describe different risk areas.
```html