styled-map-package 5.0.0-pre.3 → 5.0.0-pre.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,15 +25,23 @@ smp download https://demotiles.maplibre.org/style.json \
25
25
 
26
26
  **Options:**
27
27
 
28
- | Option | Description |
29
- | ---------------------- | ------------------------------------------------ |
30
- | `-o, --output <file>` | Output file (writes to stdout if omitted) |
31
- | `-b, --bbox <w,s,e,n>` | Bounding box (west, south, east, north) |
32
- | `-z, --zoom <number>` | Max zoom level (0-22) |
33
- | `-t, --token <token>` | Mapbox access token (required for Mapbox styles) |
28
+ | Option | Description |
29
+ | ---------------------- | ---------------------------------------------------------------------- |
30
+ | `-o, --output <file>` | Output file (writes to stdout if omitted) |
31
+ | `-b, --bbox <w,s,e,n>` | Bounding box (west, south, east, north) |
32
+ | `-z, --zoom <number>` | Max zoom level (0-22) |
33
+ | `-t, --token <token>` | Mapbox access token (required for Mapbox styles) |
34
+ | `-d, --dedupe` | Deduplicate tiles with identical content to reduce file size |
35
+ | `--skip-local-glyphs` | Skip CJK/Hangul/Kana glyph ranges rendered locally by MapLibre GL |
36
+ | `--buffer-tiles` | Download an extra tile ring around the bbox at each zoom below maxzoom |
34
37
 
35
38
  When run interactively, missing options are prompted for.
36
39
 
40
+ The `--buffer-tiles` flag downloads one extra tile ring around the bbox at every
41
+ zoom level below maxzoom, so the map is not clipped at the edges of the
42
+ downloaded area when zooming out. The buffer is not added at maxzoom. `smp view`
43
+ automatically renders these buffer tiles.
44
+
37
45
  ### `smp view`
38
46
 
39
47
  Preview a `.smp` file in a web browser.
@@ -44,10 +52,15 @@ smp view demotiles.smp --open
44
52
 
45
53
  **Options:**
46
54
 
47
- | Option | Description |
48
- | --------------------- | -------------------------------- |
49
- | `-o, --open` | Open in the default web browser |
50
- | `-p, --port <number>` | Port to serve on (default: 3000) |
55
+ | Option | Description |
56
+ | --------------------- | -------------------------------------------------------------------------- |
57
+ | `-o, --open` | Open in the default web browser |
58
+ | `-p, --port <number>` | Port to serve on (default: 3000) |
59
+ | `--no-fallback` | Return 404 for missing tiles and glyphs instead of serving empty fallbacks |
60
+
61
+ By default the viewer serves empty tiles and Noto Sans glyphs for any resource not present in the file, so incomplete packages (those covering a partial area or zoom range) preview without 404 errors. Missing vector tiles are served as empty MVTs, missing raster tiles as transparent pixels. Missing glyph ranges are served using bundled [Noto Sans](https://fonts.google.com/noto/specimen/Noto+Sans) glyphs (via [GoNotoKurrent](https://github.com/satbyy/go-noto-universal), covering 80+ scripts including Latin, Cyrillic, Greek, Arabic, Hebrew, Devanagari, Thai, and more). CJK and Hangul ranges are not bundled since MapLibre renders these client-side via `localIdeographFontFamily`. Pass `--no-fallback` to return 404s instead.
62
+
63
+ For packages downloaded with buffer tiles (recorded as `smp:bufferTiles` in the style metadata), the viewer also widens each source's `bounds` so the lower-zoom buffer tiles that extend beyond the data area are rendered rather than clipped. Combined with the empty-tile fallback, panning beyond the downloaded area shows blank tiles instead of console errors.
51
64
 
52
65
  ### `smp mbtiles`
53
66
 
@@ -65,6 +78,22 @@ smp mbtiles tiles.mbtiles --output map.smp
65
78
  | --------------------- | ------------------------------------------------ |
66
79
  | `-o, --output <file>` | Output `.smp` file (writes to stdout if omitted) |
67
80
 
81
+ ### `smp validate`
82
+
83
+ Validate a `.smp` file against the [SMP specification](../../spec/1.0/).
84
+
85
+ ```sh
86
+ smp validate map.smp
87
+ ```
88
+
89
+ Reports errors (spec MUST violations) and warnings (SHOULD/RECOMMENDED), each annotated with a severity level:
90
+
91
+ - **fatal** — the file cannot be opened by the reader
92
+ - **rendering** — the map opens but content will be visibly broken (missing tiles, glyphs, sprites)
93
+ - **spec** — non-compliance that doesn't affect practical use
94
+
95
+ Exits with code 0 if valid, 1 if errors are found.
96
+
68
97
  ## License
69
98
 
70
99
  MIT
@@ -33,20 +33,49 @@ program
33
33
  '-t, --token <token>',
34
34
  'Mapbox access token (necessary for Mapbox styles)',
35
35
  )
36
+ .option(
37
+ '--skip-local-glyphs',
38
+ 'Skip CJK/Hangul/Kana glyph ranges rendered locally by MapLibre GL',
39
+ )
40
+ .option(
41
+ '-d, --dedupe',
42
+ 'deduplicate tiles with identical content to reduce file size',
43
+ )
44
+ .option(
45
+ '--buffer-tiles',
46
+ 'download an extra tile ring around the bbox at each zoom level below maxzoom, so the map is not clipped at the edges when zooming out',
47
+ )
36
48
  .argument('[styleUrl]', 'URL to style to download', parseUrl)
37
- .action(async (styleUrl, { bbox, zoom, output, token }) => {
38
- await runDownload({ styleUrl, bbox, zoom, output, token }, {
39
- download,
40
- prompt: { input, number },
41
- createOutputStream: (output) =>
42
- output
43
- ? Writable.toWeb(fs.createWriteStream(output))
44
- : Writable.toWeb(process.stdout),
45
- reporter: ttyReporter,
46
- isMapboxURL,
47
- mapboxApiUrl: MAPBOX_API_URL,
48
- isTTY: !!process.stdout.isTTY,
49
- })
50
- })
49
+ .action(
50
+ async (
51
+ styleUrl,
52
+ { bbox, zoom, output, token, skipLocalGlyphs, dedupe, bufferTiles },
53
+ ) => {
54
+ await runDownload(
55
+ {
56
+ styleUrl,
57
+ bbox,
58
+ zoom,
59
+ output,
60
+ token,
61
+ skipLocalGlyphs,
62
+ dedupe,
63
+ bufferTiles,
64
+ },
65
+ {
66
+ download,
67
+ prompt: { input, number },
68
+ createOutputStream: (output) =>
69
+ output
70
+ ? Writable.toWeb(fs.createWriteStream(output))
71
+ : Writable.toWeb(process.stdout),
72
+ reporter: ttyReporter,
73
+ isMapboxURL,
74
+ mapboxApiUrl: MAPBOX_API_URL,
75
+ isTTY: !!process.stdout.isTTY,
76
+ },
77
+ )
78
+ },
79
+ )
51
80
 
52
81
  program.parseAsync(process.argv)
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk'
3
+ import { Command } from 'commander'
4
+ import logSymbols from 'log-symbols'
5
+ import { validate } from 'styled-map-package-api/validator'
6
+
7
+ const program = new Command()
8
+
9
+ program
10
+ .description('Validate a styled map package file')
11
+ .argument('<file>', 'path to .smp file to validate')
12
+ .action(async (filepath) => {
13
+ const result = await validate(filepath)
14
+
15
+ if (result.valid) {
16
+ console.log(logSymbols.success, chalk.green('Valid SMP file'))
17
+ } else if (result.usable) {
18
+ console.log(
19
+ logSymbols.warning,
20
+ chalk.yellow('SMP file has issues but is usable'),
21
+ )
22
+ } else {
23
+ console.log(logSymbols.error, chalk.red('Invalid SMP file (unusable)'))
24
+ }
25
+
26
+ /** @param {typeof result.issues[number]} issue */
27
+ const formatIssue = (issue) => {
28
+ const path = issue.path ? chalk.dim(`[${issue.path}] `) : ''
29
+ const sev =
30
+ issue.severity !== 'spec' ? chalk.dim(` (${issue.severity})`) : ''
31
+ return `${path}${issue.message}${sev}`
32
+ }
33
+
34
+ const issueErrors = result.issues.filter((i) => i.kind === 'error')
35
+ const issueWarnings = result.issues.filter((i) => i.kind === 'warning')
36
+
37
+ if (issueErrors.length) {
38
+ console.log('\nErrors:')
39
+ for (const issue of issueErrors) {
40
+ console.log(` ${logSymbols.error} ${formatIssue(issue)}`)
41
+ }
42
+ }
43
+
44
+ if (issueWarnings.length) {
45
+ console.log('\nWarnings:')
46
+ for (const issue of issueWarnings) {
47
+ console.log(` ${logSymbols.warning} ${formatIssue(issue)}`)
48
+ }
49
+ }
50
+
51
+ process.exit(result.valid ? 0 : 1)
52
+ })
53
+
54
+ program.parseAsync(process.argv)
package/bin/smp-view.js CHANGED
@@ -3,6 +3,8 @@ import { createServerAdapter } from '@whatwg-node/server'
3
3
  import { Command } from 'commander'
4
4
  import http from 'http'
5
5
  import openApp from 'open'
6
+ import { notoGlyphFallback } from 'smp-noto-glyphs'
7
+ import { emptyTileFallback } from 'styled-map-package-api/fallbacks'
6
8
  import { Reader } from 'styled-map-package-api/reader'
7
9
  import { createServer } from 'styled-map-package-api/server'
8
10
 
@@ -17,21 +19,30 @@ program
17
19
  .description('Preview a styled map package in a web browser')
18
20
  .option('-o, --open', 'open in the default web browser')
19
21
  .option('-p, --port <number>', 'port to serve on', (v) => parseInt(v), 3000)
22
+ .option(
23
+ '--no-fallback',
24
+ 'return 404 for missing tiles and glyphs instead of serving empty fallbacks',
25
+ )
20
26
  .argument('<file>', 'file to serve')
21
- .action(async (filepath, { open, port }) => {
27
+ .action(async (filepath, { open, port, fallback }) => {
22
28
  await runView(
23
- { port, filepath: path.relative(process.cwd(), filepath), open },
29
+ {
30
+ port,
31
+ filepath: path.relative(process.cwd(), filepath),
32
+ open,
33
+ fallback,
34
+ },
24
35
  {
25
36
  Reader,
26
37
  createServer,
38
+ emptyTileFallback,
39
+ emptyGlyphFallback: notoGlyphFallback,
27
40
  openApp,
28
41
  log: (msg) => console.log(msg),
29
42
  readViewerHtml: (filepath) => fsPromises.readFile(filepath),
30
43
  listen: (port, handler) =>
31
44
  new Promise((resolve, reject) => {
32
- const server = http.createServer(
33
- createServerAdapter(handler),
34
- )
45
+ const server = http.createServer(createServerAdapter(handler))
35
46
  server.listen(port, '127.0.0.1', () => {
36
47
  const address = server.address()
37
48
  if (typeof address === 'string') {
package/bin/smp.js CHANGED
@@ -8,5 +8,6 @@ program
8
8
  .command('download', 'Download a map style to a styled map package file')
9
9
  .command('view', 'Preview a styled map package in a web browser')
10
10
  .command('mbtiles', 'Convert a MBTiles file to a styled map package file')
11
+ .command('validate', 'Validate a styled map package file')
11
12
 
12
13
  program.parse(process.argv)
@@ -57,6 +57,9 @@ export function parseUrl(url) {
57
57
  * @property {number | undefined} zoom
58
58
  * @property {string | undefined} output
59
59
  * @property {string | undefined} token
60
+ * @property {boolean | undefined} skipLocalGlyphs
61
+ * @property {boolean | undefined} dedupe
62
+ * @property {boolean | undefined} bufferTiles When set, download one extra tile ring around the bbox at each zoom level below maxzoom.
60
63
  */
61
64
 
62
65
  /**
@@ -75,7 +78,7 @@ export function parseUrl(url) {
75
78
  * @param {DownloadDeps} deps
76
79
  */
77
80
  export async function runDownload(
78
- { styleUrl, bbox, zoom, output, token },
81
+ { styleUrl, bbox, zoom, output, token, skipLocalGlyphs, dedupe, bufferTiles },
79
82
  deps,
80
83
  ) {
81
84
  const { download, prompt, isMapboxURL, mapboxApiUrl, isTTY } = deps
@@ -176,7 +179,11 @@ export async function runDownload(
176
179
  maxzoom: zoom,
177
180
  styleUrl,
178
181
  onprogress: (/** @type {any} */ p) => reporter.write(p),
179
- accessToken: token,
182
+ mapboxAccessToken: token,
183
+ skipLocalGlyphs,
184
+ dedupe,
185
+ // `--buffer-tiles` is a boolean flag on the CLI; map it to a one-tile ring.
186
+ bufferTiles: bufferTiles ? 1 : 0,
180
187
  })
181
188
  const outputStream = deps.createOutputStream(output)
182
189
  await readStream.pipeTo(
@@ -3,6 +3,7 @@
3
3
  * @property {number} port
4
4
  * @property {string} filepath
5
5
  * @property {boolean} [open]
6
+ * @property {boolean} [fallback] Serve empty tiles and fallback glyphs for missing resources. Defaults to `true`; pass `false` to return 404s instead.
6
7
  */
7
8
 
8
9
  /**
@@ -13,6 +14,8 @@
13
14
  * @property {(url: string) => Promise<void>} openApp
14
15
  * @property {(url: string) => void} log
15
16
  * @property {(url: string) => Promise<Uint8Array>} readViewerHtml
17
+ * @property {(tileId: any, sourceInfo: any) => Response} [emptyTileFallback]
18
+ * @property {(fontstack: string, range: string) => Response} [emptyGlyphFallback]
16
19
  */
17
20
 
18
21
  /**
@@ -20,11 +23,23 @@
20
23
  * @param {ViewDeps} deps
21
24
  * @returns {Promise<string>} The address the server is listening on
22
25
  */
23
- export async function runView({ port, filepath, open }, deps) {
26
+ export async function runView({ port, filepath, open, fallback }, deps) {
24
27
  const { Reader, createServer, openApp, log, readViewerHtml } = deps
25
28
 
29
+ // Fallback is on by default; pass `fallback: false` to disable it. Pass the
30
+ // handlers explicitly (null to disable) rather than relying on the server's
31
+ // own defaults, since the CLI uses Noto glyphs rather than empty ones.
32
+ const useFallback = fallback !== false
33
+
26
34
  const reader = new Reader(filepath)
27
- const smpServer = createServer({ base: '/map' })
35
+ const smpServer = createServer({
36
+ base: '/map',
37
+ // Render buffer tiles that lie outside the data bounds for packages written
38
+ // with `smp:bufferTiles`. No-op for packages without that metadata.
39
+ expandBounds: true,
40
+ fallbackTile: useFallback ? deps.emptyTileFallback : null,
41
+ fallbackGlyph: useFallback ? deps.emptyGlyphFallback : null,
42
+ })
28
43
 
29
44
  /** @param {Request} request */
30
45
  const handler = async (request) => {
@@ -32,6 +32,7 @@
32
32
  const map = new maplibregl.Map({
33
33
  container: 'map',
34
34
  style: 'map/style.json',
35
+ attributionControl: { compact: true },
35
36
  })
36
37
 
37
38
  map.on('error', (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-map-package",
3
- "version": "5.0.0-pre.3",
3
+ "version": "5.0.0-pre.5",
4
4
  "description": "CLI for creating, viewing, and converting Styled Map Package (.smp) files",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,8 @@
18
18
  "keywords": [],
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "styled-map-package-api": "^5.0.0-pre.3",
21
+ "styled-map-package-api": "^5.0.0-pre.5",
22
+ "smp-noto-glyphs": "^1.0.0-pre.1",
22
23
  "@inquirer/prompts": "^6.0.1",
23
24
  "@whatwg-node/server": "^0.10.17",
24
25
  "chalk": "^5.4.1",