map-gl-offline 0.6.0 → 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 +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +368 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +375 -23
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +375 -23
- package/dist/index.umd.js.map +1 -1
- package/dist/managers/offlineMapManager/resourceManagement.d.ts +4 -0
- package/dist/services/modelService.d.ts +57 -0
- package/dist/services/resourceService.d.ts +11 -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 +11 -1
- package/dist/types/style.d.ts +11 -2
- package/dist/ui/managers/downloadManager.d.ts +1 -1
- package/dist/utils/constants.d.ts +2 -1
- package/package.json +1 -1
|
@@ -20,5 +20,9 @@ export interface ResourceManagement {
|
|
|
20
20
|
loadGlyphsForStyle: ResourceService['loadGlyphsForStyle'];
|
|
21
21
|
cleanupOldGlyphs: ResourceService['cleanupOldGlyphs'];
|
|
22
22
|
verifyAndRepairGlyphs: ResourceService['verifyAndRepairGlyphs'];
|
|
23
|
+
downloadModelsWithOptions: ResourceService['downloadModelsWithOptions'];
|
|
24
|
+
getModelStats: ResourceService['getModelStats'];
|
|
25
|
+
cleanupOldModels: ResourceService['cleanupOldModels'];
|
|
26
|
+
verifyAndRepairModels: ResourceService['verifyAndRepairModels'];
|
|
23
27
|
}
|
|
24
28
|
export declare const createResourceManagement: (services: OfflineManagerServices) => ResourceManagement;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ModelEntry, ModelDownloadOptions, ModelDownloadResult, EnhancedModelStats } from '@/types';
|
|
2
|
+
/** True when the given key belongs to the given styleId's model store prefix. */
|
|
3
|
+
export declare function modelKeyBelongsToStyle(key: string, styleId: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Service for downloading, storing, and serving Mapbox 3D model (.glb) files.
|
|
6
|
+
*
|
|
7
|
+
* Mapbox Standard declares 32 models at the top of `style.models`:
|
|
8
|
+
*
|
|
9
|
+
* ```json
|
|
10
|
+
* {
|
|
11
|
+
* "maple1-lod1": "mapbox://models/mapbox/maple1-v4-lod1.glb",
|
|
12
|
+
* ...
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* `model` layers (e.g. `trees`, `wind-turbine-towers`) pick one by name at
|
|
17
|
+
* render time. For offline use each referenced URL is fetched and stored
|
|
18
|
+
* here, and `patchStyleForOffline` rewrites the dictionary entries to
|
|
19
|
+
* `idb://{styleId}/model/{name}` URLs.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ModelService {
|
|
22
|
+
private db;
|
|
23
|
+
/**
|
|
24
|
+
* Download the set of models referenced by `style.models` for one style.
|
|
25
|
+
*
|
|
26
|
+
* @param models `{ modelName: resolvedHttpUrl }` — URLs must already be
|
|
27
|
+
* resolved (mapbox:// URLs should be resolved by the caller).
|
|
28
|
+
* @param styleId The owning style's key.
|
|
29
|
+
*/
|
|
30
|
+
downloadModels(models: Record<string, string>, styleId: string, options?: ModelDownloadOptions): Promise<ModelDownloadResult>;
|
|
31
|
+
/** Retrieve a single model by `{styleId, modelName}`. */
|
|
32
|
+
getModel(styleId: string, modelName: string): Promise<ModelEntry | undefined>;
|
|
33
|
+
/** Aggregate stats across all stored models. */
|
|
34
|
+
getModelStats(): Promise<EnhancedModelStats>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete models older than `maxAge` days. Defaults to 30.
|
|
37
|
+
*/
|
|
38
|
+
cleanupOldModels(maxAge?: number): Promise<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Basic integrity check: remove entries with empty/missing data.
|
|
41
|
+
*/
|
|
42
|
+
verifyAndRepairModels(): Promise<{
|
|
43
|
+
verified: number;
|
|
44
|
+
repaired: number;
|
|
45
|
+
removed: number;
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
export declare const modelService: ModelService;
|
|
49
|
+
export declare const downloadModels: (models: Record<string, string>, styleId: string, options?: ModelDownloadOptions) => Promise<ModelDownloadResult>;
|
|
50
|
+
export declare const getModel: (styleId: string, modelName: string) => Promise<ModelEntry | undefined>;
|
|
51
|
+
export declare const getModelStats: () => Promise<EnhancedModelStats>;
|
|
52
|
+
export declare const cleanupOldModels: (maxAge?: number) => Promise<number>;
|
|
53
|
+
export declare const verifyAndRepairModels: () => Promise<{
|
|
54
|
+
verified: number;
|
|
55
|
+
repaired: number;
|
|
56
|
+
removed: number;
|
|
57
|
+
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnhancedGlyphStats } from './glyphService';
|
|
2
|
-
import type { OfflineRegionOptions, MapboxStyle, TileDownloadOptions, TileDownloadResult, TileStats, SpriteDownloadOptions, SpriteDownloadResult, EnhancedSpriteStats, FontDownloadOptions, FontDownloadResult, EnhancedFontStats, GlyphDownloadOptions, GlyphDownloadResult } from '@/types';
|
|
2
|
+
import type { OfflineRegionOptions, MapboxStyle, TileDownloadOptions, TileDownloadResult, TileStats, SpriteDownloadOptions, SpriteDownloadResult, EnhancedSpriteStats, FontDownloadOptions, FontDownloadResult, EnhancedFontStats, GlyphDownloadOptions, GlyphDownloadResult, ModelDownloadOptions, ModelDownloadResult, EnhancedModelStats } from '@/types';
|
|
3
3
|
export declare class ResourceService {
|
|
4
4
|
downloadTilesWithOptions(region: OfflineRegionOptions, style: MapboxStyle, styleId: string, options?: TileDownloadOptions): Promise<TileDownloadResult>;
|
|
5
5
|
getTileStats(styleId?: string): Promise<TileStats>;
|
|
@@ -39,4 +39,14 @@ export declare class ResourceService {
|
|
|
39
39
|
repaired: number;
|
|
40
40
|
removed: number;
|
|
41
41
|
}>;
|
|
42
|
+
downloadModelsWithOptions(models: Record<string, string>, styleId: string, options?: ModelDownloadOptions): Promise<ModelDownloadResult>;
|
|
43
|
+
getModelStats(): Promise<EnhancedModelStats>;
|
|
44
|
+
cleanupOldModels(options?: {
|
|
45
|
+
maxAge?: number;
|
|
46
|
+
}): Promise<number>;
|
|
47
|
+
verifyAndRepairModels(): Promise<{
|
|
48
|
+
verified: number;
|
|
49
|
+
repaired: number;
|
|
50
|
+
removed: number;
|
|
51
|
+
}>;
|
|
42
52
|
}
|
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
|
@@ -2,11 +2,12 @@ import type { StyleProvider } from './style';
|
|
|
2
2
|
import type { TileDownloadOptions, TileDownloadResult } from './tile';
|
|
3
3
|
import type { SpriteDownloadResult } from './sprite';
|
|
4
4
|
import type { GlyphDownloadResult } from './glyph';
|
|
5
|
+
import type { ModelDownloadResult } from './model';
|
|
5
6
|
import type { StyleDownloadResult } from './style';
|
|
6
7
|
/**
|
|
7
8
|
* Phase of a region download pipeline, reported via `DownloadRegionOptions.onProgress`.
|
|
8
9
|
*/
|
|
9
|
-
export type DownloadRegionPhase = 'style' | 'sprites' | 'glyphs' | 'tiles' | 'metadata';
|
|
10
|
+
export type DownloadRegionPhase = 'style' | 'sprites' | 'glyphs' | 'models' | 'tiles' | 'metadata';
|
|
10
11
|
/**
|
|
11
12
|
* Progress update emitted by `OfflineMapManager.downloadRegion`.
|
|
12
13
|
*/
|
|
@@ -31,6 +32,14 @@ export interface DownloadRegionOptions {
|
|
|
31
32
|
skipGlyphs?: boolean;
|
|
32
33
|
/** Skip sprite download entirely. Default: false. */
|
|
33
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;
|
|
34
43
|
/** Override Unicode glyph ranges fetched per font. Defaults to `GLYPH_CONFIG.COMPREHENSIVE_RANGES`. */
|
|
35
44
|
glyphRanges?: string[];
|
|
36
45
|
/** Extra options forwarded to the tile download step. */
|
|
@@ -45,6 +54,7 @@ export interface DownloadRegionResult {
|
|
|
45
54
|
styleResult?: StyleDownloadResult;
|
|
46
55
|
spriteResults: SpriteDownloadResult[];
|
|
47
56
|
glyphResult?: GlyphDownloadResult;
|
|
57
|
+
modelResult?: ModelDownloadResult;
|
|
48
58
|
tileResult: TileDownloadResult;
|
|
49
59
|
}
|
|
50
60
|
/**
|
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;
|
|
@@ -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.
|
|
@@ -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;
|
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",
|