styled-map-package 2.2.1 → 3.0.0
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/bin/smp-download.js +3 -3
- package/bin/smp-mbtiles.js +1 -1
- package/bin/smp-view.js +2 -2
- package/dist/download.cjs +101 -0
- package/dist/download.d.cts +65 -0
- package/dist/{lib/download.d.ts → download.d.ts} +22 -6
- package/dist/download.js +77 -0
- package/dist/from-mbtiles.cjs +91 -0
- package/dist/from-mbtiles.d.cts +17 -0
- package/dist/from-mbtiles.d.ts +17 -0
- package/dist/from-mbtiles.js +57 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +18 -0
- package/dist/reader-watch.cjs +135 -0
- package/dist/reader-watch.d.cts +24 -0
- package/dist/reader-watch.d.ts +24 -0
- package/dist/reader-watch.js +101 -0
- package/dist/reader.cjs +167 -0
- package/dist/reader.d.cts +62 -0
- package/dist/{lib/reader.d.ts → reader.d.ts} +16 -5
- package/dist/reader.js +138 -0
- package/dist/reporters.cjs +122 -0
- package/dist/reporters.d.cts +10 -0
- package/dist/{lib/reporters.d.ts → reporters.d.ts} +5 -2
- package/dist/reporters.js +88 -0
- package/dist/server.cjs +79 -0
- package/dist/server.d.cts +37 -0
- package/dist/server.d.ts +37 -0
- package/dist/server.js +45 -0
- package/dist/style-downloader.cjs +312 -0
- package/dist/style-downloader.d.cts +120 -0
- package/dist/{lib/style-downloader.d.ts → style-downloader.d.ts} +23 -13
- package/dist/style-downloader.js +288 -0
- package/dist/tile-downloader.cjs +158 -0
- package/dist/tile-downloader.d.cts +84 -0
- package/dist/{lib/tile-downloader.d.ts → tile-downloader.d.ts} +22 -10
- package/dist/tile-downloader.js +126 -0
- package/dist/{lib/writer.d.ts → types-B4Xn1F9K.d.cts} +74 -14
- package/dist/types-B4Xn1F9K.d.ts +189 -0
- package/dist/utils/errors.cjs +41 -0
- package/dist/utils/errors.d.cts +18 -0
- package/dist/{lib/utils → utils}/errors.d.ts +4 -2
- package/dist/utils/errors.js +16 -0
- package/dist/utils/fetch.cjs +96 -0
- package/dist/utils/fetch.d.cts +51 -0
- package/dist/{lib/utils → utils}/fetch.d.ts +10 -4
- package/dist/utils/fetch.js +62 -0
- package/dist/utils/file-formats.cjs +98 -0
- package/dist/utils/file-formats.d.cts +35 -0
- package/dist/{lib/utils → utils}/file-formats.d.ts +13 -3
- package/dist/utils/file-formats.js +62 -0
- package/dist/utils/geo.cjs +84 -0
- package/dist/utils/geo.d.cts +46 -0
- package/dist/{lib/utils → utils}/geo.d.ts +8 -6
- package/dist/utils/geo.js +56 -0
- package/dist/utils/mapbox.cjs +121 -0
- package/dist/utils/mapbox.d.cts +43 -0
- package/dist/utils/mapbox.d.ts +43 -0
- package/dist/utils/mapbox.js +91 -0
- package/dist/utils/misc.cjs +39 -0
- package/{lib/utils/misc.js → dist/utils/misc.d.cts} +5 -9
- package/dist/{lib/utils → utils}/misc.d.ts +5 -3
- package/dist/utils/misc.js +13 -0
- package/dist/utils/streams.cjs +130 -0
- package/dist/utils/streams.d.cts +73 -0
- package/dist/{lib/utils → utils}/streams.d.ts +14 -10
- package/dist/utils/streams.js +103 -0
- package/dist/utils/style.cjs +126 -0
- package/dist/utils/style.d.cts +69 -0
- package/dist/{lib/utils → utils}/style.d.ts +19 -9
- package/dist/utils/style.js +98 -0
- package/dist/utils/templates.cjs +114 -0
- package/dist/utils/templates.d.cts +78 -0
- package/dist/{lib/utils → utils}/templates.d.ts +24 -14
- package/dist/utils/templates.js +79 -0
- package/dist/writer.cjs +401 -0
- package/dist/writer.d.cts +7 -0
- package/dist/writer.d.ts +7 -0
- package/dist/writer.js +374 -0
- package/package.json +87 -33
- package/dist/lib/from-mbtiles.d.ts +0 -13
- package/dist/lib/index.d.ts +0 -10
- package/dist/lib/reader-watch.d.ts +0 -13
- package/dist/lib/server.d.ts +0 -15
- package/dist/lib/types.d.ts +0 -64
- package/dist/lib/utils/mapbox.d.ts +0 -41
- package/lib/download.js +0 -114
- package/lib/from-mbtiles.js +0 -83
- package/lib/index.js +0 -11
- package/lib/reader-watch.js +0 -133
- package/lib/reader.js +0 -165
- package/lib/reporters.js +0 -92
- package/lib/server.js +0 -81
- package/lib/style-downloader.js +0 -363
- package/lib/tile-downloader.js +0 -188
- package/lib/types.ts +0 -104
- package/lib/utils/errors.js +0 -24
- package/lib/utils/fetch.js +0 -100
- package/lib/utils/file-formats.js +0 -85
- package/lib/utils/geo.js +0 -87
- package/lib/utils/mapbox.js +0 -155
- package/lib/utils/streams.js +0 -165
- package/lib/utils/style.js +0 -174
- package/lib/utils/templates.js +0 -136
- package/lib/writer.js +0 -478
package/bin/smp-download.js
CHANGED
|
@@ -4,9 +4,9 @@ import { input, number } from '@inquirer/prompts'
|
|
|
4
4
|
import fs from 'fs'
|
|
5
5
|
import { pipeline } from 'stream/promises'
|
|
6
6
|
|
|
7
|
-
import download from '../
|
|
8
|
-
import { ttyReporter } from '../
|
|
9
|
-
import { isMapboxURL, API_URL as MAPBOX_API_URL } from '../
|
|
7
|
+
import { download } from '../dist/download.js'
|
|
8
|
+
import { ttyReporter } from '../dist/reporters.js'
|
|
9
|
+
import { isMapboxURL, API_URL as MAPBOX_API_URL } from '../dist/utils/mapbox.js'
|
|
10
10
|
|
|
11
11
|
const program = new Command()
|
|
12
12
|
|
package/bin/smp-mbtiles.js
CHANGED
package/bin/smp-view.js
CHANGED
|
@@ -6,7 +6,7 @@ import openApp from 'open'
|
|
|
6
6
|
|
|
7
7
|
import path from 'node:path'
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import { createServer } from '../dist/server.js'
|
|
10
10
|
|
|
11
11
|
const program = new Command()
|
|
12
12
|
|
|
@@ -45,7 +45,7 @@ function serve({ port = 3000, filepath }) {
|
|
|
45
45
|
return reply.sendFile('index.html')
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
server.register(
|
|
48
|
+
server.register(createServer, {
|
|
49
49
|
filepath: path.relative(process.cwd(), filepath),
|
|
50
50
|
prefix: '/map',
|
|
51
51
|
})
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var download_exports = {};
|
|
20
|
+
__export(download_exports, {
|
|
21
|
+
download: () => download
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(download_exports);
|
|
24
|
+
var import_readable_stream = require("readable-stream");
|
|
25
|
+
var import_promises = require("stream/promises");
|
|
26
|
+
var import_style_downloader = require('./style-downloader.cjs');
|
|
27
|
+
var import_writer = require('./writer.cjs');
|
|
28
|
+
function download({ bbox, maxzoom, styleUrl, onprogress, accessToken }) {
|
|
29
|
+
const downloader = new import_style_downloader.StyleDownloader(styleUrl, {
|
|
30
|
+
concurrency: 24,
|
|
31
|
+
mapboxAccessToken: accessToken
|
|
32
|
+
});
|
|
33
|
+
let start = Date.now();
|
|
34
|
+
let progress = {
|
|
35
|
+
tiles: { downloaded: 0, totalBytes: 0, total: 0, skipped: 0, done: false },
|
|
36
|
+
style: { done: false },
|
|
37
|
+
sprites: { downloaded: 0, done: false },
|
|
38
|
+
glyphs: { downloaded: 0, total: 0, totalBytes: 0, done: false },
|
|
39
|
+
output: { totalBytes: 0, done: false },
|
|
40
|
+
elapsedMs: 0
|
|
41
|
+
};
|
|
42
|
+
const sizeCounter = new import_readable_stream.Transform({
|
|
43
|
+
transform(chunk, encoding, cb) {
|
|
44
|
+
handleProgress({
|
|
45
|
+
output: {
|
|
46
|
+
totalBytes: progress.output.totalBytes + chunk.length,
|
|
47
|
+
done: false
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
cb(null, chunk);
|
|
51
|
+
},
|
|
52
|
+
final(cb) {
|
|
53
|
+
handleProgress({ output: { ...progress.output, done: true } });
|
|
54
|
+
cb();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
function handleProgress(update) {
|
|
58
|
+
progress = { ...progress, ...update, elapsedMs: Date.now() - start };
|
|
59
|
+
onprogress?.(progress);
|
|
60
|
+
}
|
|
61
|
+
;
|
|
62
|
+
(async () => {
|
|
63
|
+
const style = await downloader.getStyle();
|
|
64
|
+
const writer = new import_writer.Writer(style);
|
|
65
|
+
handleProgress({ style: { done: true } });
|
|
66
|
+
writer.outputStream.pipe(sizeCounter);
|
|
67
|
+
writer.on("error", (err) => sizeCounter.destroy(err));
|
|
68
|
+
try {
|
|
69
|
+
for await (const spriteInfo of downloader.getSprites()) {
|
|
70
|
+
await writer.addSprite(spriteInfo);
|
|
71
|
+
handleProgress({
|
|
72
|
+
sprites: { downloaded: progress.sprites.downloaded + 1, done: false }
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
handleProgress({ sprites: { ...progress.sprites, done: true } });
|
|
76
|
+
const tiles = downloader.getTiles({
|
|
77
|
+
bounds: bbox,
|
|
78
|
+
maxzoom,
|
|
79
|
+
onprogress: (tileStats) => handleProgress({ tiles: { ...tileStats, done: false } })
|
|
80
|
+
});
|
|
81
|
+
await (0, import_promises.pipeline)(tiles, writer.createTileWriteStream({ concurrency: 24 }));
|
|
82
|
+
handleProgress({ tiles: { ...progress.tiles, done: true } });
|
|
83
|
+
const glyphs = downloader.getGlyphs({
|
|
84
|
+
onprogress: (glyphStats) => handleProgress({ glyphs: { ...glyphStats, done: false } })
|
|
85
|
+
});
|
|
86
|
+
await (0, import_promises.pipeline)(glyphs, writer.createGlyphWriteStream());
|
|
87
|
+
handleProgress({ glyphs: { ...progress.glyphs, done: true } });
|
|
88
|
+
writer.finish();
|
|
89
|
+
} catch (err) {
|
|
90
|
+
writer.outputStream.destroy(
|
|
91
|
+
/** @type {Error} */
|
|
92
|
+
err
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
return sizeCounter;
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
download
|
|
101
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GlyphDownloadStats } from './style-downloader.cjs';
|
|
2
|
+
import { TileDownloadStats } from './tile-downloader.cjs';
|
|
3
|
+
import { D as DownloadStream } from './types-B4Xn1F9K.cjs';
|
|
4
|
+
import { BBox } from './utils/geo.cjs';
|
|
5
|
+
import 'ky';
|
|
6
|
+
import 'stream';
|
|
7
|
+
import '@maplibre/maplibre-gl-style-spec';
|
|
8
|
+
import './utils/fetch.cjs';
|
|
9
|
+
import './utils/streams.cjs';
|
|
10
|
+
import 'readable-stream';
|
|
11
|
+
import 'geojson';
|
|
12
|
+
import 'type-fest';
|
|
13
|
+
import 'events';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} DownloadProgress
|
|
17
|
+
* @property {import('./tile-downloader.js').TileDownloadStats & { done: boolean }} tiles
|
|
18
|
+
* @property {{ done: boolean }} style
|
|
19
|
+
* @property {{ downloaded: number, done: boolean }} sprites
|
|
20
|
+
* @property {import('./style-downloader.js').GlyphDownloadStats & { done: boolean }} glyphs
|
|
21
|
+
* @property {{ totalBytes: number, done: boolean }} output
|
|
22
|
+
* @property {number} elapsedMs
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Download a map style and its resources for a given bounding box and max zoom
|
|
26
|
+
* level. Returns a readable stream of a "styled map package", a zip file
|
|
27
|
+
* containing all the resources needed to serve the style offline.
|
|
28
|
+
*
|
|
29
|
+
* @param {object} opts
|
|
30
|
+
* @param {import("./utils/geo.js").BBox} opts.bbox Bounding box to download tiles for
|
|
31
|
+
* @param {number} opts.maxzoom Max zoom level to download tiles for
|
|
32
|
+
* @param {string} opts.styleUrl URL of the style to download
|
|
33
|
+
* @param { (progress: DownloadProgress) => void } [opts.onprogress] Optional callback for reporting progress
|
|
34
|
+
* @param {string} [opts.accessToken]
|
|
35
|
+
* @returns {import('./types.js').DownloadStream} Readable stream of the output styled map file
|
|
36
|
+
*/
|
|
37
|
+
declare function download({ bbox, maxzoom, styleUrl, onprogress, accessToken }: {
|
|
38
|
+
bbox: BBox;
|
|
39
|
+
maxzoom: number;
|
|
40
|
+
styleUrl: string;
|
|
41
|
+
onprogress?: ((progress: DownloadProgress) => void) | undefined;
|
|
42
|
+
accessToken?: string | undefined;
|
|
43
|
+
}): DownloadStream;
|
|
44
|
+
type DownloadProgress = {
|
|
45
|
+
tiles: TileDownloadStats & {
|
|
46
|
+
done: boolean;
|
|
47
|
+
};
|
|
48
|
+
style: {
|
|
49
|
+
done: boolean;
|
|
50
|
+
};
|
|
51
|
+
sprites: {
|
|
52
|
+
downloaded: number;
|
|
53
|
+
done: boolean;
|
|
54
|
+
};
|
|
55
|
+
glyphs: GlyphDownloadStats & {
|
|
56
|
+
done: boolean;
|
|
57
|
+
};
|
|
58
|
+
output: {
|
|
59
|
+
totalBytes: number;
|
|
60
|
+
done: boolean;
|
|
61
|
+
};
|
|
62
|
+
elapsedMs: number;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { type DownloadProgress, download };
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import { GlyphDownloadStats } from './style-downloader.js';
|
|
2
|
+
import { TileDownloadStats } from './tile-downloader.js';
|
|
3
|
+
import { D as DownloadStream } from './types-B4Xn1F9K.js';
|
|
4
|
+
import { BBox } from './utils/geo.js';
|
|
5
|
+
import 'ky';
|
|
6
|
+
import 'stream';
|
|
7
|
+
import '@maplibre/maplibre-gl-style-spec';
|
|
8
|
+
import './utils/fetch.js';
|
|
9
|
+
import './utils/streams.js';
|
|
10
|
+
import 'readable-stream';
|
|
11
|
+
import 'geojson';
|
|
12
|
+
import 'type-fest';
|
|
13
|
+
import 'events';
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* @typedef {object} DownloadProgress
|
|
3
17
|
* @property {import('./tile-downloader.js').TileDownloadStats & { done: boolean }} tiles
|
|
@@ -20,15 +34,15 @@
|
|
|
20
34
|
* @param {string} [opts.accessToken]
|
|
21
35
|
* @returns {import('./types.js').DownloadStream} Readable stream of the output styled map file
|
|
22
36
|
*/
|
|
23
|
-
|
|
24
|
-
bbox:
|
|
37
|
+
declare function download({ bbox, maxzoom, styleUrl, onprogress, accessToken }: {
|
|
38
|
+
bbox: BBox;
|
|
25
39
|
maxzoom: number;
|
|
26
40
|
styleUrl: string;
|
|
27
41
|
onprogress?: ((progress: DownloadProgress) => void) | undefined;
|
|
28
42
|
accessToken?: string | undefined;
|
|
29
|
-
}):
|
|
30
|
-
|
|
31
|
-
tiles:
|
|
43
|
+
}): DownloadStream;
|
|
44
|
+
type DownloadProgress = {
|
|
45
|
+
tiles: TileDownloadStats & {
|
|
32
46
|
done: boolean;
|
|
33
47
|
};
|
|
34
48
|
style: {
|
|
@@ -38,7 +52,7 @@ export type DownloadProgress = {
|
|
|
38
52
|
downloaded: number;
|
|
39
53
|
done: boolean;
|
|
40
54
|
};
|
|
41
|
-
glyphs:
|
|
55
|
+
glyphs: GlyphDownloadStats & {
|
|
42
56
|
done: boolean;
|
|
43
57
|
};
|
|
44
58
|
output: {
|
|
@@ -47,3 +61,5 @@ export type DownloadProgress = {
|
|
|
47
61
|
};
|
|
48
62
|
elapsedMs: number;
|
|
49
63
|
};
|
|
64
|
+
|
|
65
|
+
export { type DownloadProgress, download };
|
package/dist/download.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Transform } from "readable-stream";
|
|
2
|
+
import { pipeline } from "stream/promises";
|
|
3
|
+
import { StyleDownloader } from "./style-downloader.js";
|
|
4
|
+
import { Writer } from "./writer.js";
|
|
5
|
+
function download({ bbox, maxzoom, styleUrl, onprogress, accessToken }) {
|
|
6
|
+
const downloader = new StyleDownloader(styleUrl, {
|
|
7
|
+
concurrency: 24,
|
|
8
|
+
mapboxAccessToken: accessToken
|
|
9
|
+
});
|
|
10
|
+
let start = Date.now();
|
|
11
|
+
let progress = {
|
|
12
|
+
tiles: { downloaded: 0, totalBytes: 0, total: 0, skipped: 0, done: false },
|
|
13
|
+
style: { done: false },
|
|
14
|
+
sprites: { downloaded: 0, done: false },
|
|
15
|
+
glyphs: { downloaded: 0, total: 0, totalBytes: 0, done: false },
|
|
16
|
+
output: { totalBytes: 0, done: false },
|
|
17
|
+
elapsedMs: 0
|
|
18
|
+
};
|
|
19
|
+
const sizeCounter = new Transform({
|
|
20
|
+
transform(chunk, encoding, cb) {
|
|
21
|
+
handleProgress({
|
|
22
|
+
output: {
|
|
23
|
+
totalBytes: progress.output.totalBytes + chunk.length,
|
|
24
|
+
done: false
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
cb(null, chunk);
|
|
28
|
+
},
|
|
29
|
+
final(cb) {
|
|
30
|
+
handleProgress({ output: { ...progress.output, done: true } });
|
|
31
|
+
cb();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
function handleProgress(update) {
|
|
35
|
+
progress = { ...progress, ...update, elapsedMs: Date.now() - start };
|
|
36
|
+
onprogress?.(progress);
|
|
37
|
+
}
|
|
38
|
+
;
|
|
39
|
+
(async () => {
|
|
40
|
+
const style = await downloader.getStyle();
|
|
41
|
+
const writer = new Writer(style);
|
|
42
|
+
handleProgress({ style: { done: true } });
|
|
43
|
+
writer.outputStream.pipe(sizeCounter);
|
|
44
|
+
writer.on("error", (err) => sizeCounter.destroy(err));
|
|
45
|
+
try {
|
|
46
|
+
for await (const spriteInfo of downloader.getSprites()) {
|
|
47
|
+
await writer.addSprite(spriteInfo);
|
|
48
|
+
handleProgress({
|
|
49
|
+
sprites: { downloaded: progress.sprites.downloaded + 1, done: false }
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
handleProgress({ sprites: { ...progress.sprites, done: true } });
|
|
53
|
+
const tiles = downloader.getTiles({
|
|
54
|
+
bounds: bbox,
|
|
55
|
+
maxzoom,
|
|
56
|
+
onprogress: (tileStats) => handleProgress({ tiles: { ...tileStats, done: false } })
|
|
57
|
+
});
|
|
58
|
+
await pipeline(tiles, writer.createTileWriteStream({ concurrency: 24 }));
|
|
59
|
+
handleProgress({ tiles: { ...progress.tiles, done: true } });
|
|
60
|
+
const glyphs = downloader.getGlyphs({
|
|
61
|
+
onprogress: (glyphStats) => handleProgress({ glyphs: { ...glyphStats, done: false } })
|
|
62
|
+
});
|
|
63
|
+
await pipeline(glyphs, writer.createGlyphWriteStream());
|
|
64
|
+
handleProgress({ glyphs: { ...progress.glyphs, done: true } });
|
|
65
|
+
writer.finish();
|
|
66
|
+
} catch (err) {
|
|
67
|
+
writer.outputStream.destroy(
|
|
68
|
+
/** @type {Error} */
|
|
69
|
+
err
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
return sizeCounter;
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
download
|
|
77
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var from_mbtiles_exports = {};
|
|
30
|
+
__export(from_mbtiles_exports, {
|
|
31
|
+
fromMBTiles: () => fromMBTiles
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(from_mbtiles_exports);
|
|
34
|
+
var import_mbtiles_reader = require("mbtiles-reader");
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
+
var import_node_stream = require("node:stream");
|
|
37
|
+
var import_node_stream2 = require("node:stream");
|
|
38
|
+
var import_promises = require("node:stream/promises");
|
|
39
|
+
var import_writer = require('./writer.cjs');
|
|
40
|
+
const SOURCE_ID = "mbtiles-source";
|
|
41
|
+
function fromMBTiles(mbtilesPath, outputPath) {
|
|
42
|
+
const reader = new import_mbtiles_reader.MBTiles(mbtilesPath);
|
|
43
|
+
if (reader.metadata.format === "pbf") {
|
|
44
|
+
throw new Error("Vector MBTiles are not yet supported");
|
|
45
|
+
}
|
|
46
|
+
const style = {
|
|
47
|
+
version: 8,
|
|
48
|
+
name: reader.metadata.name,
|
|
49
|
+
sources: {
|
|
50
|
+
[SOURCE_ID]: {
|
|
51
|
+
...reader.metadata,
|
|
52
|
+
type: "raster"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
layers: [
|
|
56
|
+
{
|
|
57
|
+
id: "background",
|
|
58
|
+
type: "background",
|
|
59
|
+
paint: {
|
|
60
|
+
"background-color": "white"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "raster",
|
|
65
|
+
type: "raster",
|
|
66
|
+
source: SOURCE_ID,
|
|
67
|
+
paint: {
|
|
68
|
+
"raster-opacity": 1
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
const writer = new import_writer.Writer(style);
|
|
74
|
+
const returnValue = outputPath ? (0, import_promises.pipeline)(writer.outputStream, import_node_fs.default.createWriteStream(outputPath)) : writer.outputStream;
|
|
75
|
+
const tileWriteStream = writer.createTileWriteStream();
|
|
76
|
+
const transform = new import_node_stream.Transform({
|
|
77
|
+
objectMode: true,
|
|
78
|
+
transform({ z, x, y, data, format }, encoding, callback) {
|
|
79
|
+
callback(null, [data, { z, x, y, format, sourceId: SOURCE_ID }]);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
(0, import_node_stream2.pipeline)(reader, transform, tileWriteStream, (err) => {
|
|
83
|
+
if (err) return writer.outputStream.destroy(err);
|
|
84
|
+
writer.finish();
|
|
85
|
+
});
|
|
86
|
+
return returnValue;
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
fromMBTiles
|
|
91
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @overload
|
|
5
|
+
* @param {string} mbtilesPath
|
|
6
|
+
* @returns {import('stream').Readable}
|
|
7
|
+
*/
|
|
8
|
+
declare function fromMBTiles(mbtilesPath: string): stream.Readable;
|
|
9
|
+
/**
|
|
10
|
+
* @overload
|
|
11
|
+
* @param {string} mbtilesPath
|
|
12
|
+
* @param {string} outputPath
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
declare function fromMBTiles(mbtilesPath: string, outputPath: string): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { fromMBTiles };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @overload
|
|
5
|
+
* @param {string} mbtilesPath
|
|
6
|
+
* @returns {import('stream').Readable}
|
|
7
|
+
*/
|
|
8
|
+
declare function fromMBTiles(mbtilesPath: string): stream.Readable;
|
|
9
|
+
/**
|
|
10
|
+
* @overload
|
|
11
|
+
* @param {string} mbtilesPath
|
|
12
|
+
* @param {string} outputPath
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
declare function fromMBTiles(mbtilesPath: string, outputPath: string): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { fromMBTiles };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MBTiles } from "mbtiles-reader";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { Transform } from "node:stream";
|
|
4
|
+
import { pipeline } from "node:stream";
|
|
5
|
+
import { pipeline as pipelinePromise } from "node:stream/promises";
|
|
6
|
+
import { Writer } from "./writer.js";
|
|
7
|
+
const SOURCE_ID = "mbtiles-source";
|
|
8
|
+
function fromMBTiles(mbtilesPath, outputPath) {
|
|
9
|
+
const reader = new MBTiles(mbtilesPath);
|
|
10
|
+
if (reader.metadata.format === "pbf") {
|
|
11
|
+
throw new Error("Vector MBTiles are not yet supported");
|
|
12
|
+
}
|
|
13
|
+
const style = {
|
|
14
|
+
version: 8,
|
|
15
|
+
name: reader.metadata.name,
|
|
16
|
+
sources: {
|
|
17
|
+
[SOURCE_ID]: {
|
|
18
|
+
...reader.metadata,
|
|
19
|
+
type: "raster"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
layers: [
|
|
23
|
+
{
|
|
24
|
+
id: "background",
|
|
25
|
+
type: "background",
|
|
26
|
+
paint: {
|
|
27
|
+
"background-color": "white"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "raster",
|
|
32
|
+
type: "raster",
|
|
33
|
+
source: SOURCE_ID,
|
|
34
|
+
paint: {
|
|
35
|
+
"raster-opacity": 1
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
const writer = new Writer(style);
|
|
41
|
+
const returnValue = outputPath ? pipelinePromise(writer.outputStream, fs.createWriteStream(outputPath)) : writer.outputStream;
|
|
42
|
+
const tileWriteStream = writer.createTileWriteStream();
|
|
43
|
+
const transform = new Transform({
|
|
44
|
+
objectMode: true,
|
|
45
|
+
transform({ z, x, y, data, format }, encoding, callback) {
|
|
46
|
+
callback(null, [data, { z, x, y, format, sourceId: SOURCE_ID }]);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
pipeline(reader, transform, tileWriteStream, (err) => {
|
|
50
|
+
if (err) return writer.outputStream.destroy(err);
|
|
51
|
+
writer.finish();
|
|
52
|
+
});
|
|
53
|
+
return returnValue;
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
fromMBTiles
|
|
57
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
Reader: () => import_reader.Reader,
|
|
22
|
+
ReaderWatch: () => import_reader_watch.ReaderWatch,
|
|
23
|
+
StyleDownloader: () => import_style_downloader.StyleDownloader,
|
|
24
|
+
Writer: () => import_writer.Writer,
|
|
25
|
+
createServer: () => import_server.createServer,
|
|
26
|
+
download: () => import_download.download,
|
|
27
|
+
downloadTiles: () => import_tile_downloader.downloadTiles,
|
|
28
|
+
fromMBTiles: () => import_from_mbtiles.fromMBTiles
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_reader = require('./reader.cjs');
|
|
32
|
+
var import_reader_watch = require('./reader-watch.cjs');
|
|
33
|
+
var import_writer = require('./writer.cjs');
|
|
34
|
+
var import_server = require('./server.cjs');
|
|
35
|
+
var import_style_downloader = require('./style-downloader.cjs');
|
|
36
|
+
var import_tile_downloader = require('./tile-downloader.cjs');
|
|
37
|
+
var import_download = require('./download.cjs');
|
|
38
|
+
var import_from_mbtiles = require('./from-mbtiles.cjs');
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
Reader,
|
|
42
|
+
ReaderWatch,
|
|
43
|
+
StyleDownloader,
|
|
44
|
+
Writer,
|
|
45
|
+
createServer,
|
|
46
|
+
download,
|
|
47
|
+
downloadTiles,
|
|
48
|
+
fromMBTiles
|
|
49
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { S as SMPSource$1, a as SMPStyle$1 } from './types-B4Xn1F9K.cjs';
|
|
2
|
+
export { W as Writer } from './types-B4Xn1F9K.cjs';
|
|
3
|
+
export { Reader } from './reader.cjs';
|
|
4
|
+
export { ReaderWatch } from './reader-watch.cjs';
|
|
5
|
+
export { createServer } from './server.cjs';
|
|
6
|
+
export { StyleDownloader } from './style-downloader.cjs';
|
|
7
|
+
export { downloadTiles } from './tile-downloader.cjs';
|
|
8
|
+
export { download } from './download.cjs';
|
|
9
|
+
export { fromMBTiles } from './from-mbtiles.cjs';
|
|
10
|
+
import '@maplibre/maplibre-gl-style-spec';
|
|
11
|
+
import 'geojson';
|
|
12
|
+
import 'stream';
|
|
13
|
+
import 'type-fest';
|
|
14
|
+
import 'readable-stream';
|
|
15
|
+
import 'events';
|
|
16
|
+
import 'yauzl-promise';
|
|
17
|
+
import 'http';
|
|
18
|
+
import 'fastify';
|
|
19
|
+
import 'ky';
|
|
20
|
+
import './utils/geo.cjs';
|
|
21
|
+
import './utils/fetch.cjs';
|
|
22
|
+
import './utils/streams.cjs';
|
|
23
|
+
|
|
24
|
+
type SMPSource = SMPSource$1;
|
|
25
|
+
type SMPStyle = SMPStyle$1;
|
|
26
|
+
|
|
27
|
+
export type { SMPSource, SMPStyle };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { S as SMPSource$1, a as SMPStyle$1 } from './types-B4Xn1F9K.js';
|
|
2
|
+
export { W as Writer } from './types-B4Xn1F9K.js';
|
|
3
|
+
export { Reader } from './reader.js';
|
|
4
|
+
export { ReaderWatch } from './reader-watch.js';
|
|
5
|
+
export { createServer } from './server.js';
|
|
6
|
+
export { StyleDownloader } from './style-downloader.js';
|
|
7
|
+
export { downloadTiles } from './tile-downloader.js';
|
|
8
|
+
export { download } from './download.js';
|
|
9
|
+
export { fromMBTiles } from './from-mbtiles.js';
|
|
10
|
+
import '@maplibre/maplibre-gl-style-spec';
|
|
11
|
+
import 'geojson';
|
|
12
|
+
import 'stream';
|
|
13
|
+
import 'type-fest';
|
|
14
|
+
import 'readable-stream';
|
|
15
|
+
import 'events';
|
|
16
|
+
import 'yauzl-promise';
|
|
17
|
+
import 'http';
|
|
18
|
+
import 'fastify';
|
|
19
|
+
import 'ky';
|
|
20
|
+
import './utils/geo.js';
|
|
21
|
+
import './utils/fetch.js';
|
|
22
|
+
import './utils/streams.js';
|
|
23
|
+
|
|
24
|
+
type SMPSource = SMPSource$1;
|
|
25
|
+
type SMPStyle = SMPStyle$1;
|
|
26
|
+
|
|
27
|
+
export type { SMPSource, SMPStyle };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Reader } from "./reader.js";
|
|
2
|
+
import { ReaderWatch } from "./reader-watch.js";
|
|
3
|
+
import { Writer } from "./writer.js";
|
|
4
|
+
import { createServer } from "./server.js";
|
|
5
|
+
import { StyleDownloader } from "./style-downloader.js";
|
|
6
|
+
import { downloadTiles } from "./tile-downloader.js";
|
|
7
|
+
import { download } from "./download.js";
|
|
8
|
+
import { fromMBTiles } from "./from-mbtiles.js";
|
|
9
|
+
export {
|
|
10
|
+
Reader,
|
|
11
|
+
ReaderWatch,
|
|
12
|
+
StyleDownloader,
|
|
13
|
+
Writer,
|
|
14
|
+
createServer,
|
|
15
|
+
download,
|
|
16
|
+
downloadTiles,
|
|
17
|
+
fromMBTiles
|
|
18
|
+
};
|