map-gl-offline 0.5.6 → 0.7.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/README.md +90 -443
- package/dist/index.d.ts +18 -8
- package/dist/index.esm.js +2955 -2657
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2967 -2656
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2967 -2656
- package/dist/index.umd.js.map +1 -1
- package/dist/managers/offlineMapManager/index.d.ts +3 -57
- package/dist/managers/offlineMapManager/regionManagement.d.ts +3 -2
- package/dist/managers/offlineMapManager/resourceManagement.d.ts +8 -4
- package/dist/services/modelService.d.ts +57 -0
- package/dist/services/regionService.d.ts +30 -2
- package/dist/services/resourceService.d.ts +15 -5
- package/dist/storage/indexedDbManager.d.ts +18 -15
- package/dist/style.css +1 -1
- package/dist/types/database.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/model.d.ts +62 -0
- package/dist/types/region.d.ts +59 -0
- package/dist/types/style.d.ts +11 -2
- package/dist/types/tile.d.ts +15 -0
- package/dist/ui/managers/downloadManager.d.ts +1 -6
- package/dist/ui/offlineManagerControl.d.ts +0 -11
- package/dist/utils/constants.d.ts +3 -2
- package/dist/utils/styleUtils.d.ts +8 -0
- package/package.json +1 -1
package/dist/types/database.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { FontEntry } from './font';
|
|
|
5
5
|
import type { TileEntry } from './tile';
|
|
6
6
|
import type { SpriteEntry } from './sprite';
|
|
7
7
|
import type { GlyphEntry } from './glyph';
|
|
8
|
+
import type { ModelEntry } from './model';
|
|
8
9
|
export interface OfflineMapDB extends DBSchema {
|
|
9
10
|
/**
|
|
10
11
|
* @deprecated Regions are now stored inside styles.regions[] array.
|
|
@@ -35,4 +36,12 @@ export interface OfflineMapDB extends DBSchema {
|
|
|
35
36
|
key: string;
|
|
36
37
|
value: FontEntry;
|
|
37
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* 3D model files (.glb) referenced by `style.models` entries. Used by
|
|
41
|
+
* Mapbox Standard for tree / wind-turbine model layers.
|
|
42
|
+
*/
|
|
43
|
+
models: {
|
|
44
|
+
key: string;
|
|
45
|
+
value: ModelEntry;
|
|
46
|
+
};
|
|
38
47
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DownloadProgress } from './progress';
|
|
2
|
+
/**
|
|
3
|
+
* 3D model asset (e.g. a tree or turbine .glb) stored in IndexedDB.
|
|
4
|
+
*
|
|
5
|
+
* Mapbox Standard references 32 models via the top-level `style.models`
|
|
6
|
+
* dictionary (`{ "maple1-lod1": "mapbox://models/mapbox/maple1-v4-lod1.glb" }`).
|
|
7
|
+
* Layers of type `model` then pick one by name at render time.
|
|
8
|
+
*/
|
|
9
|
+
export interface ModelEntry {
|
|
10
|
+
/** Storage key: `{styleId}::model::{modelName}`. */
|
|
11
|
+
key: string;
|
|
12
|
+
/** Model binary (.glb / .gltf) as ArrayBuffer. */
|
|
13
|
+
data: ArrayBuffer;
|
|
14
|
+
/** HTTP Content-Type (usually `model/gltf-binary`). */
|
|
15
|
+
contentType: string;
|
|
16
|
+
/** Byte length. */
|
|
17
|
+
size: number;
|
|
18
|
+
/** URL the model was downloaded from. */
|
|
19
|
+
url: string;
|
|
20
|
+
/** Style this model belongs to. */
|
|
21
|
+
styleId: string;
|
|
22
|
+
/** Model name (the key in `style.models`). */
|
|
23
|
+
modelName: string;
|
|
24
|
+
/** Last-Modified or download timestamp (ms since epoch). */
|
|
25
|
+
lastModified: number;
|
|
26
|
+
/** ISO 8601 download timestamp. */
|
|
27
|
+
downloadedAt: string;
|
|
28
|
+
/** Optional expiry from HTTP Cache-Control. */
|
|
29
|
+
expires?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Options for `downloadModels`. */
|
|
32
|
+
export interface ModelDownloadOptions {
|
|
33
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
34
|
+
batchSize?: number;
|
|
35
|
+
maxRetries?: number;
|
|
36
|
+
skipExisting?: boolean;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Result of a model download batch. */
|
|
40
|
+
export interface ModelDownloadResult {
|
|
41
|
+
totalModels: number;
|
|
42
|
+
downloadedModels: number;
|
|
43
|
+
skippedModels: number;
|
|
44
|
+
failedModels: number;
|
|
45
|
+
totalSize: number;
|
|
46
|
+
errors: Array<{
|
|
47
|
+
url: string;
|
|
48
|
+
error: string;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
/** Aggregate stats across stored models. */
|
|
52
|
+
export interface EnhancedModelStats {
|
|
53
|
+
count: number;
|
|
54
|
+
totalSize: number;
|
|
55
|
+
averageSize: number;
|
|
56
|
+
models: Array<{
|
|
57
|
+
name: string;
|
|
58
|
+
size: number;
|
|
59
|
+
lastModified?: number;
|
|
60
|
+
}>;
|
|
61
|
+
modelsByStyle: Record<string, number>;
|
|
62
|
+
}
|
package/dist/types/region.d.ts
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
import type { StyleProvider } from './style';
|
|
2
|
+
import type { TileDownloadOptions, TileDownloadResult } from './tile';
|
|
3
|
+
import type { SpriteDownloadResult } from './sprite';
|
|
4
|
+
import type { GlyphDownloadResult } from './glyph';
|
|
5
|
+
import type { ModelDownloadResult } from './model';
|
|
6
|
+
import type { StyleDownloadResult } from './style';
|
|
7
|
+
/**
|
|
8
|
+
* Phase of a region download pipeline, reported via `DownloadRegionOptions.onProgress`.
|
|
9
|
+
*/
|
|
10
|
+
export type DownloadRegionPhase = 'style' | 'sprites' | 'glyphs' | 'models' | 'tiles' | 'metadata';
|
|
11
|
+
/**
|
|
12
|
+
* Progress update emitted by `OfflineMapManager.downloadRegion`.
|
|
13
|
+
*/
|
|
14
|
+
export interface DownloadRegionProgress {
|
|
15
|
+
phase: DownloadRegionPhase;
|
|
16
|
+
completed: number;
|
|
17
|
+
total: number;
|
|
18
|
+
percentage: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for the programmatic `downloadRegion` pipeline.
|
|
23
|
+
*/
|
|
24
|
+
export interface DownloadRegionOptions {
|
|
25
|
+
/** Called with per-phase progress during style → sprites → glyphs → tiles → metadata. */
|
|
26
|
+
onProgress?: (progress: DownloadRegionProgress) => void;
|
|
27
|
+
/** Style provider hint when the style needs to be fetched. Defaults to 'auto'. */
|
|
28
|
+
provider?: StyleProvider;
|
|
29
|
+
/** Mapbox access token; required when the style or sources use mapbox:// URLs. */
|
|
30
|
+
accessToken?: string;
|
|
31
|
+
/** Skip glyph download entirely. Default: false. */
|
|
32
|
+
skipGlyphs?: boolean;
|
|
33
|
+
/** Skip sprite download entirely. Default: false. */
|
|
34
|
+
skipSprites?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Skip 3D model download. Default: false. Models (e.g. Mapbox Standard
|
|
37
|
+
* trees / wind turbines) are declared via `style.models` and live at
|
|
38
|
+
* `mapbox://models/…` URLs that only Mapbox serves. Skip for styles that
|
|
39
|
+
* don't use model layers, or to reduce storage footprint at the cost of
|
|
40
|
+
* missing tree/turbine rendering.
|
|
41
|
+
*/
|
|
42
|
+
skipModels?: boolean;
|
|
43
|
+
/** Override Unicode glyph ranges fetched per font. Defaults to `GLYPH_CONFIG.COMPREHENSIVE_RANGES`. */
|
|
44
|
+
glyphRanges?: string[];
|
|
45
|
+
/** Extra options forwarded to the tile download step. */
|
|
46
|
+
tileOptions?: TileDownloadOptions;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Result of a full `downloadRegion` pipeline.
|
|
50
|
+
*/
|
|
51
|
+
export interface DownloadRegionResult {
|
|
52
|
+
regionId: string;
|
|
53
|
+
styleId: string;
|
|
54
|
+
styleResult?: StyleDownloadResult;
|
|
55
|
+
spriteResults: SpriteDownloadResult[];
|
|
56
|
+
glyphResult?: GlyphDownloadResult;
|
|
57
|
+
modelResult?: ModelDownloadResult;
|
|
58
|
+
tileResult: TileDownloadResult;
|
|
59
|
+
}
|
|
1
60
|
/**
|
|
2
61
|
* Stored region with metadata
|
|
3
62
|
* Extends OfflineRegionOptions with database-specific fields
|
package/dist/types/style.d.ts
CHANGED
|
@@ -19,8 +19,17 @@ export interface BaseStyle {
|
|
|
19
19
|
data?: BaseStyle;
|
|
20
20
|
config?: Record<string, unknown>;
|
|
21
21
|
}>;
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* 3D model declarations used by `model` layers (Mapbox Standard trees /
|
|
24
|
+
* wind turbines). Two shapes are accepted in the wild:
|
|
25
|
+
*
|
|
26
|
+
* - Mapbox Standard format — values are plain URI strings:
|
|
27
|
+
* `{ "maple1-lod1": "mapbox://models/mapbox/maple1-v4-lod1.glb" }`
|
|
28
|
+
* - Older / generic format — values wrap the URI in an object:
|
|
29
|
+
* `{ "name": { "uri": "mapbox://..." } }`
|
|
30
|
+
*/
|
|
31
|
+
models?: Record<string, string | {
|
|
32
|
+
uri?: string;
|
|
24
33
|
[key: string]: unknown;
|
|
25
34
|
}>;
|
|
26
35
|
[key: string]: unknown;
|
package/dist/types/tile.d.ts
CHANGED
|
@@ -65,6 +65,21 @@ export interface TileDownloadOptions {
|
|
|
65
65
|
bandwidthLimit?: number;
|
|
66
66
|
/** Check storage quota before download (default: true) */
|
|
67
67
|
storageQuotaCheck?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Before committing to download a source's full tile plan, probe one
|
|
70
|
+
* representative tile. If that probe returns 404, the source is treated
|
|
71
|
+
* as sparse-for-this-region and skipped entirely. This adapts to the
|
|
72
|
+
* region (some cities have indoor/landmark/3D-building data, others
|
|
73
|
+
* don't) without requiring a static skip list.
|
|
74
|
+
*
|
|
75
|
+
* One probe HTTP request is added per source. The probe itself may
|
|
76
|
+
* 404 (visible in the Network tab), but downstream we then avoid
|
|
77
|
+
* dozens of follow-up 404s.
|
|
78
|
+
*
|
|
79
|
+
* Default: `true`. Set `false` to download every source regardless
|
|
80
|
+
* (old behavior — noisier, but guaranteed-complete).
|
|
81
|
+
*/
|
|
82
|
+
probeSourcesBeforeDownload?: boolean;
|
|
68
83
|
}
|
|
69
84
|
/**
|
|
70
85
|
* Result of a tile download operation
|
|
@@ -74,7 +74,7 @@ export interface DownloadProgress {
|
|
|
74
74
|
/** Human-readable description of current activity */
|
|
75
75
|
currentResource: string;
|
|
76
76
|
/** Current download phase */
|
|
77
|
-
phase?: 'style' | 'sprites' | 'glyphs' | 'tiles';
|
|
77
|
+
phase?: 'style' | 'sprites' | 'glyphs' | 'models' | 'tiles';
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Configuration options for the DownloadManager.
|
|
@@ -172,11 +172,6 @@ export declare class DownloadManager {
|
|
|
172
172
|
* @internal
|
|
173
173
|
*/
|
|
174
174
|
private updateUIForDownloadStart;
|
|
175
|
-
/**
|
|
176
|
-
* Normalize the style's sprite property into a uniform array of {id, url} sources.
|
|
177
|
-
* Handles string format, array format, and filters out already-patched idb:// URLs.
|
|
178
|
-
*/
|
|
179
|
-
private normalizeSpriteProperty;
|
|
180
175
|
/**
|
|
181
176
|
* Handle successful completion of a region download.
|
|
182
177
|
* Removes from tracking, resets UI if needed, and notifies listeners.
|
|
@@ -232,10 +232,6 @@ export declare class OfflineManagerControl implements IControl {
|
|
|
232
232
|
* ```
|
|
233
233
|
*/
|
|
234
234
|
loadOfflineStyle(styleId: string): Promise<void>;
|
|
235
|
-
/**
|
|
236
|
-
* Load styles from IndexedDB and apply to map
|
|
237
|
-
*/
|
|
238
|
-
private loadStylesFromIDB;
|
|
239
235
|
/**
|
|
240
236
|
* Show modal to select which style to load
|
|
241
237
|
*/
|
|
@@ -253,13 +249,6 @@ export declare class OfflineManagerControl implements IControl {
|
|
|
253
249
|
* ```
|
|
254
250
|
*/
|
|
255
251
|
loadOfflineStyles(): Promise<void>;
|
|
256
|
-
/**
|
|
257
|
-
* Load a specific offline style by its ID.
|
|
258
|
-
* Alias for `loadOfflineStyle()` for API clarity.
|
|
259
|
-
*
|
|
260
|
-
* @param styleId - The unique identifier of the stored style
|
|
261
|
-
*/
|
|
262
|
-
loadSpecificOfflineStyle(styleId: string): Promise<void>;
|
|
263
252
|
/**
|
|
264
253
|
* Update the style URL used for new region downloads.
|
|
265
254
|
*
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
* Centralizes magic numbers and configuration values
|
|
4
4
|
*/
|
|
5
5
|
export declare const DB_NAME = "offline-map-db";
|
|
6
|
-
export declare const DB_VERSION =
|
|
6
|
+
export declare const DB_VERSION = 4;
|
|
7
7
|
export declare const STORE_NAMES: {
|
|
8
8
|
readonly TILES: "tiles";
|
|
9
9
|
readonly STYLES: "styles";
|
|
10
10
|
readonly SPRITES: "sprites";
|
|
11
11
|
readonly GLYPHS: "glyphs";
|
|
12
12
|
readonly FONTS: "fonts";
|
|
13
|
+
readonly MODELS: "models";
|
|
13
14
|
};
|
|
14
15
|
export declare const DOWNLOAD_DEFAULTS: {
|
|
15
16
|
readonly BATCH_SIZE: 10;
|
|
@@ -27,7 +28,7 @@ export declare const TILE_CONFIG: {
|
|
|
27
28
|
export declare const GLYPH_CONFIG: {
|
|
28
29
|
readonly DEFAULT_URL: "https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf";
|
|
29
30
|
readonly DEFAULT_RANGES: readonly ["0-255"];
|
|
30
|
-
readonly COMPREHENSIVE_RANGES: readonly ["0-255", "256-511", "512-767", "768-1023", "1024-1279", "1280-1535", "1536-1791", "1792-2047", "2048-2303", "2304-2559", "2560-2815", "2816-3071", "3072-3327", "3328-3583", "3584-3839", "3840-4095", "4096-4351", "4352-4607", "4608-4863", "11904-12031", "12032-12255", "12288-12543", "12544-12799", "19968-20223", "20224-20479", "40960-42127", "44032-55203", "63744-64255", "65280-65535"];
|
|
31
|
+
readonly COMPREHENSIVE_RANGES: readonly ["0-255", "256-511", "512-767", "768-1023", "1024-1279", "1280-1535", "1536-1791", "1792-2047", "2048-2303", "2304-2559", "2560-2815", "2816-3071", "3072-3327", "3328-3583", "3584-3839", "3840-4095", "4096-4351", "4352-4607", "4608-4863", "7680-7935", "8192-8447", "8448-8703", "11904-12031", "12032-12255", "12288-12543", "12544-12799", "19968-20223", "20224-20479", "40960-42127", "44032-55203", "63744-64255", "64256-64511", "65024-65279", "65280-65535"];
|
|
31
32
|
};
|
|
32
33
|
export declare const STYLE_CONFIG: {
|
|
33
34
|
readonly OPENFREEMAP_BASE: "https://tiles.openfreemap.org/styles";
|
|
@@ -17,6 +17,14 @@ export declare function patchStyleForOffline(style: MapboxStyle, downloadId: str
|
|
|
17
17
|
* syntax (e.g. `["step", ["zoom"], ["literal", ["Font A"]], 10, ["literal", ["Font B"]]]`).
|
|
18
18
|
*/
|
|
19
19
|
export declare function extractFontNamesFromTextField(textFont: unknown): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Normalize a style's `sprite` property into a uniform array of {id, url} sources.
|
|
22
|
+
* Handles string format, array format, and filters out already-patched idb:// URLs.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeSpriteProperty(sprite: unknown): Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
url: string;
|
|
27
|
+
}>;
|
|
20
28
|
/**
|
|
21
29
|
* Collect all unique font names referenced in a style's layers.
|
|
22
30
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "map-gl-offline",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A TypeScript-compatible npm package for MapLibre GL JS that enables comprehensive offline storage and usage of vector/raster tiles, sprites, styles, fonts (glyphs), and entire map regions with advanced analytics, import/export capabilities, and intelligent cleanup.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|