Recognise the vector tile schema of a tileset from its TileJSON.
Reads only vector_layers: the source-layer ids, and the fields of the few ids two schemas share.
name, attribution and the like are not used — they describe who built a tileset, not what is in
it. Synchronous and free of I/O; for a URL, download the document with fetchTileJSON() first.
Knows Shortbread, OpenMapTiles, Protomaps and Mapbox Streets without importing any of their styles, so it costs the root bundle a small table rather than two schemas. Mapbox tiles and the land cover tileset are recognised only: the package has no builder for them. For the others, build the style from the matching subpath:
import { guessSchema, osm } from '@versatiles/style';
import { omt } from '@versatiles/style/omt';
const guess = guessSchema(tileJSON);
if (guess.type === 'vector' && guess.schema === 'openmaptiles') style = omt({ urls: { omt: tileJSON } });
A schema is recognised when it qualifies (at least half the tileset's source-layers are its, or at least eight are) and scores strictly higher than every other schema, or as high and the tileset has all of it. Never throws.
Everything both entry points expose.
index.ts(npm) adds the authoring helpers on top;browser.ts(the CDN bundle) does not — see the note in each.