styled-map-package 5.0.0-pre.2 → 5.0.0-pre.4
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 +31 -10
- package/bin/smp-download.js +30 -14
- package/bin/smp-validate.js +54 -0
- package/bin/smp-view.js +16 -5
- package/bin/smp.js +1 -0
- package/lib/commands/download.js +5 -1
- package/lib/commands/view.js +11 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -25,12 +25,14 @@ 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 |
|
|
34
36
|
|
|
35
37
|
When run interactively, missing options are prompted for.
|
|
36
38
|
|
|
@@ -44,10 +46,13 @@ smp view demotiles.smp --open
|
|
|
44
46
|
|
|
45
47
|
**Options:**
|
|
46
48
|
|
|
47
|
-
| Option | Description
|
|
48
|
-
| --------------------- |
|
|
49
|
-
| `-o, --open` | Open in the default web browser
|
|
50
|
-
| `-p, --port <number>` | Port to serve on (default: 3000)
|
|
49
|
+
| Option | Description |
|
|
50
|
+
| --------------------- | ----------------------------------------------------------------- |
|
|
51
|
+
| `-o, --open` | Open in the default web browser |
|
|
52
|
+
| `-p, --port <number>` | Port to serve on (default: 3000) |
|
|
53
|
+
| `-f, --fallback` | Serve empty tiles and glyphs for missing resources instead of 404 |
|
|
54
|
+
|
|
55
|
+
The `--fallback` flag is useful for previewing SMP files that don't contain every tile or glyph range referenced by the style. 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`.
|
|
51
56
|
|
|
52
57
|
### `smp mbtiles`
|
|
53
58
|
|
|
@@ -65,6 +70,22 @@ smp mbtiles tiles.mbtiles --output map.smp
|
|
|
65
70
|
| --------------------- | ------------------------------------------------ |
|
|
66
71
|
| `-o, --output <file>` | Output `.smp` file (writes to stdout if omitted) |
|
|
67
72
|
|
|
73
|
+
### `smp validate`
|
|
74
|
+
|
|
75
|
+
Validate a `.smp` file against the [SMP specification](../../spec/1.0/).
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
smp validate map.smp
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Reports errors (spec MUST violations) and warnings (SHOULD/RECOMMENDED), each annotated with a severity level:
|
|
82
|
+
|
|
83
|
+
- **fatal** — the file cannot be opened by the reader
|
|
84
|
+
- **rendering** — the map opens but content will be visibly broken (missing tiles, glyphs, sprites)
|
|
85
|
+
- **spec** — non-compliance that doesn't affect practical use
|
|
86
|
+
|
|
87
|
+
Exits with code 0 if valid, 1 if errors are found.
|
|
88
|
+
|
|
68
89
|
## License
|
|
69
90
|
|
|
70
91
|
MIT
|
package/bin/smp-download.js
CHANGED
|
@@ -33,20 +33,36 @@ 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
|
+
)
|
|
36
44
|
.argument('[styleUrl]', 'URL to style to download', parseUrl)
|
|
37
|
-
.action(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
.action(
|
|
46
|
+
async (
|
|
47
|
+
styleUrl,
|
|
48
|
+
{ bbox, zoom, output, token, skipLocalGlyphs, dedupe },
|
|
49
|
+
) => {
|
|
50
|
+
await runDownload(
|
|
51
|
+
{ styleUrl, bbox, zoom, output, token, skipLocalGlyphs, dedupe },
|
|
52
|
+
{
|
|
53
|
+
download,
|
|
54
|
+
prompt: { input, number },
|
|
55
|
+
createOutputStream: (output) =>
|
|
56
|
+
output
|
|
57
|
+
? Writable.toWeb(fs.createWriteStream(output))
|
|
58
|
+
: Writable.toWeb(process.stdout),
|
|
59
|
+
reporter: ttyReporter,
|
|
60
|
+
isMapboxURL,
|
|
61
|
+
mapboxApiUrl: MAPBOX_API_URL,
|
|
62
|
+
isTTY: !!process.stdout.isTTY,
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
},
|
|
66
|
+
)
|
|
51
67
|
|
|
52
68
|
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
|
+
'-f, --fallback',
|
|
24
|
+
'serve empty tiles and glyphs for missing resources instead of 404',
|
|
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
|
-
{
|
|
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)
|
package/lib/commands/download.js
CHANGED
|
@@ -57,6 +57,8 @@ 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
|
|
60
62
|
*/
|
|
61
63
|
|
|
62
64
|
/**
|
|
@@ -75,7 +77,7 @@ export function parseUrl(url) {
|
|
|
75
77
|
* @param {DownloadDeps} deps
|
|
76
78
|
*/
|
|
77
79
|
export async function runDownload(
|
|
78
|
-
{ styleUrl, bbox, zoom, output, token },
|
|
80
|
+
{ styleUrl, bbox, zoom, output, token, skipLocalGlyphs, dedupe },
|
|
79
81
|
deps,
|
|
80
82
|
) {
|
|
81
83
|
const { download, prompt, isMapboxURL, mapboxApiUrl, isTTY } = deps
|
|
@@ -177,6 +179,8 @@ export async function runDownload(
|
|
|
177
179
|
styleUrl,
|
|
178
180
|
onprogress: (/** @type {any} */ p) => reporter.write(p),
|
|
179
181
|
accessToken: token,
|
|
182
|
+
skipLocalGlyphs,
|
|
183
|
+
dedupe,
|
|
180
184
|
})
|
|
181
185
|
const outputStream = deps.createOutputStream(output)
|
|
182
186
|
await readStream.pipeTo(
|
package/lib/commands/view.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @property {number} port
|
|
4
4
|
* @property {string} filepath
|
|
5
5
|
* @property {boolean} [open]
|
|
6
|
+
* @property {boolean} [fallback]
|
|
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,17 @@
|
|
|
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
|
|
|
26
29
|
const reader = new Reader(filepath)
|
|
27
|
-
const smpServer = createServer({
|
|
30
|
+
const smpServer = createServer({
|
|
31
|
+
base: '/map',
|
|
32
|
+
...(fallback && {
|
|
33
|
+
fallbackTile: deps.emptyTileFallback,
|
|
34
|
+
fallbackGlyph: deps.emptyGlyphFallback,
|
|
35
|
+
}),
|
|
36
|
+
})
|
|
28
37
|
|
|
29
38
|
/** @param {Request} request */
|
|
30
39
|
const handler = async (request) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "styled-map-package",
|
|
3
|
-
"version": "5.0.0-pre.
|
|
3
|
+
"version": "5.0.0-pre.4",
|
|
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.
|
|
21
|
+
"styled-map-package-api": "^5.0.0-pre.4",
|
|
22
|
+
"smp-noto-glyphs": "^1.0.0-pre.0",
|
|
22
23
|
"@inquirer/prompts": "^6.0.1",
|
|
23
24
|
"@whatwg-node/server": "^0.10.17",
|
|
24
25
|
"chalk": "^5.4.1",
|