map-gl-offline 0.5.0 → 0.5.1

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
@@ -61,6 +61,22 @@ yarn add map-gl-offline
61
61
  pnpm add map-gl-offline
62
62
  ```
63
63
 
64
+ ### CDN (UMD)
65
+
66
+ For use via `<script>` tag, the library is available as the `mapgloffline` global (similar to `mapboxgl` and `maplibregl`):
67
+
68
+ ```html
69
+ <script src="https://unpkg.com/map-gl-offline/dist/index.umd.js"></script>
70
+ <link rel="stylesheet" href="https://unpkg.com/map-gl-offline/dist/style.css" />
71
+ <script>
72
+ const manager = new mapgloffline.OfflineMapManager();
73
+ const control = new mapgloffline.OfflineManagerControl(manager, {
74
+ styleUrl: 'https://api.maptiler.com/maps/streets/style.json?key=YOUR_KEY',
75
+ });
76
+ map.addControl(control, 'top-right');
77
+ </script>
78
+ ```
79
+
64
80
  ## 🔑 Environment Setup
65
81
 
66
82
  For development or when using Maptiler styles, create a `.env` file:
@@ -169,10 +185,10 @@ await offlineManager.addRegion({
169
185
  },
170
186
  });
171
187
 
172
- // Retrieve and use stored region
173
- const region = await offlineManager.getRegion('downtown');
188
+ // Retrieve a stored region
189
+ const region = await offlineManager.getStoredRegion('downtown');
174
190
  if (region) {
175
- map.setStyle(region.offlineStyle); // Apply offline style
191
+ console.log(`Region: ${region.name}, created: ${new Date(region.created).toLocaleDateString()}`);
176
192
  }
177
193
 
178
194
  // List all regions
@@ -198,18 +214,18 @@ console.log(`Recommendations:`, analytics.recommendations);
198
214
  ### Cleanup & Maintenance
199
215
 
200
216
  ```typescript
201
- // Clean up old tiles (7 days)
202
- const tileCleanup = await offlineManager.cleanupOldTiles(7 * 24 * 60 * 60 * 1000);
203
- console.log(`Cleaned ${tileCleanup} old tiles`);
204
-
205
- // Verify and repair tiles
206
- const verification = await offlineManager.verifyAndRepairTiles();
207
- console.log(`Valid: ${verification.validTiles}, Corrupted: ${verification.corruptedTiles}`);
208
-
209
- // Start automatic cleanup
210
- offlineManager.startAutoCleanup({
211
- interval: 24 * 60 * 60 * 1000, // Daily
212
- maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
217
+ // Clean up expired regions
218
+ const deletedCount = await offlineManager.cleanupExpiredRegions();
219
+ console.log(`Cleaned ${deletedCount} expired regions`);
220
+
221
+ // Verify and repair fonts
222
+ const verification = await offlineManager.verifyAndRepairFonts('style_123', { removeCorrupted: true });
223
+ console.log(`Verified: ${verification.verified}, Repaired: ${verification.repaired}, Removed: ${verification.removed}`);
224
+
225
+ // Set up automatic cleanup (runs every 24 hours)
226
+ const cleanupId = await offlineManager.setupAutoCleanup({
227
+ intervalHours: 24,
228
+ maxAge: 30, // days
213
229
  });
214
230
  ```
215
231
 
@@ -222,36 +238,41 @@ Main class for managing offline maps.
222
238
  **Constructor:**
223
239
 
224
240
  ```typescript
225
- const manager = new OfflineMapManager(options?: {
226
- autoCleanup?: boolean;
227
- cleanupInterval?: number;
228
- });
241
+ const manager = new OfflineMapManager(overrides?: OfflineManagerServiceOverrides);
229
242
  ```
230
243
 
244
+ The constructor accepts optional service overrides for dependency injection (advanced usage). For most cases, use the default: `new OfflineMapManager()`.
245
+
231
246
  **Core Methods:**
232
247
 
233
248
  - `addRegion(options: OfflineRegionOptions)` - Download and store a map region
234
- - `getRegion(id: string)` - Retrieve a stored region by ID
249
+ - `getStoredRegion(id: string)` - Retrieve a stored region by ID
235
250
  - `deleteRegion(id: string)` - Delete a specific region and its resources
236
251
  - `listStoredRegions()` - List all stored regions with metadata
237
- - `updateRegion(id: string, updates: Partial<OfflineRegionOptions>)` - Update region settings
252
+ - `listRegions()` - List all region options
238
253
 
239
254
  **Analytics Methods:**
240
255
 
241
256
  - `getComprehensiveStorageAnalytics()` - Get detailed storage statistics
242
- - `getRegionAnalytics(regionId: string)` - Get analytics for specific region
243
- - `getTileStats()` - Get tile-specific statistics
244
- - `getFontStats()` - Get font statistics
245
- - `getSpriteStats()` - Get sprite statistics
257
+ - `getRegionAnalytics()` - Get aggregate analytics across all regions
258
+ - `getTileStatistics(styleId: string)` - Get tile-specific statistics
259
+ - `getFontStatistics(styleId: string)` - Get font statistics
260
+ - `getSpriteStatistics(styleId: string)` - Get sprite statistics
246
261
 
247
- **Maintenance Methods:**
262
+ **Cleanup & Maintenance Methods:**
248
263
 
249
- - `cleanupOldTiles(maxAge: number)` - Remove tiles older than specified age
250
- - `cleanupOldFonts(maxAge: number)` - Remove old font data
251
264
  - `cleanupExpiredRegions()` - Remove regions past expiration date
252
- - `verifyAndRepairTiles()` - Verify tile integrity and repair if possible
253
- - `startAutoCleanup(options)` - Enable automatic cleanup
254
- - `stopAutoCleanup()` - Disable automatic cleanup
265
+ - `performSmartCleanup(options)` - Intelligent cleanup with configurable criteria
266
+ - `cleanupOldFonts(styleId?, options?)` - Remove old font data
267
+ - `cleanupOldSprites(styleId?, options?)` - Remove old sprite data
268
+ - `cleanupOldGlyphs(styleId?, options?)` - Remove old glyph data
269
+ - `verifyAndRepairFonts(styleId, options?)` - Verify font integrity
270
+ - `verifyAndRepairSprites(styleId, options?)` - Verify sprite integrity
271
+ - `verifyAndRepairGlyphs(styleId, options?)` - Verify glyph integrity
272
+ - `setupAutoCleanup(options)` - Enable automatic periodic cleanup
273
+ - `stopAutoCleanup(cleanupId?)` - Disable a specific auto-cleanup
274
+ - `stopAllAutoCleanup()` - Disable all auto-cleanups
275
+ - `performCompleteMaintenance(options?)` - Run comprehensive maintenance
255
276
 
256
277
  ### OfflineManagerControl
257
278
 
@@ -288,14 +309,15 @@ const control = new OfflineManagerControl(offlineManager, {
288
309
  ```typescript
289
310
  interface OfflineRegionOptions {
290
311
  id: string; // Unique region identifier
291
- name?: string; // Human-readable name
312
+ name: string; // Human-readable name (required)
292
313
  bounds: [[number, number], [number, number]]; // [[lng, lat], [lng, lat]]
293
314
  minZoom: number; // Minimum zoom level (e.g., 10)
294
315
  maxZoom: number; // Maximum zoom level (e.g., 16)
295
- styleUrl: string; // Map style URL
296
- onProgress?: (progress: ProgressInfo) => void; // Progress callback
297
- expiresAt?: number; // Expiration timestamp (ms)
298
- autoDelete?: boolean; // Auto-delete on expiration
316
+ styleUrl?: string; // Map style URL
317
+ expiry?: number; // Expiration timestamp (ms since epoch)
318
+ deleteOnExpiry?: boolean; // Auto-delete on expiration
319
+ multipleRegions?: boolean; // Part of a multi-region download
320
+ tileExtension?: string; // Tile extension (pbf, mvt, png, etc.)
299
321
  }
300
322
  ```
301
323
 
@@ -328,9 +350,8 @@ const region = {
328
350
  // Monitor storage usage
329
351
  const analytics = await manager.getComprehensiveStorageAnalytics();
330
352
  if (analytics.totalStorageSize > 500 * 1024 * 1024) {
331
- // 500MB
332
353
  console.warn('High storage usage detected');
333
- await manager.cleanupExpiredRegions();
354
+ await manager.performSmartCleanup({ maxStorageSize: 500 * 1024 * 1024 });
334
355
  }
335
356
 
336
357
  // Use progressive loading for better UX
@@ -367,12 +388,12 @@ if ('storage' in navigator && 'estimate' in navigator.storage) {
367
388
  }
368
389
 
369
390
  // Regular cleanup
370
- await manager.cleanupOldTiles(7 * 24 * 60 * 60 * 1000); // 7 days
391
+ await manager.cleanupExpiredRegions();
371
392
 
372
393
  // Auto-cleanup on startup
373
- manager.startAutoCleanup({
374
- interval: 24 * 60 * 60 * 1000, // Daily
375
- maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
394
+ await manager.setupAutoCleanup({
395
+ intervalHours: 24, // Daily
396
+ maxAge: 30, // 30 days
376
397
  });
377
398
  ```
378
399
 
@@ -485,7 +506,7 @@ map-gl-offline/
485
506
 
486
507
  ## 🔄 Recent Updates
487
508
 
488
- ### v0.2.0 (Latest)
509
+ ### v0.5.0 (Latest)
489
510
 
490
511
  - ✅ **Mapbox GL JS Support**: Full support for Mapbox styles, including `mapbox://` protocol URL resolution
491
512
  - ✅ **Mapbox Standard Style**: 3D models, raster-dem terrain, and import-based style resolution
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * map-gl-offline
3
3
  *
4
- * A TypeScript library for offline map storage with MapLibre GL JS.
4
+ * A TypeScript library for offline map storage with MapLibre GL JS and Mapbox GL JS.
5
5
  * Enables comprehensive offline storage and usage of vector/raster tiles,
6
6
  * sprites, styles, fonts (glyphs), and entire map regions.
7
7
  *
@@ -10,32 +10,38 @@
10
10
  *
11
11
  * @example Basic usage
12
12
  * ```typescript
13
- * import { OfflineMapManager } from 'map-gl-offline';
13
+ * import { OfflineMapManager, OfflineManagerControl } from 'map-gl-offline';
14
14
  * import maplibregl from 'maplibre-gl';
15
+ * import 'map-gl-offline/dist/style.css';
15
16
  *
16
17
  * const map = new maplibregl.Map({
17
18
  * container: 'map',
18
- * style: 'https://tiles.openfreemap.org/styles/liberty'
19
+ * style: 'https://api.maptiler.com/maps/streets/style.json?key=YOUR_KEY'
19
20
  * });
20
21
  *
21
- * const offlineManager = new OfflineMapManager(map);
22
+ * const offlineManager = new OfflineMapManager();
22
23
  *
23
- * // Download a region for offline use
24
- * await offlineManager.downloadRegion({
25
- * name: 'San Francisco',
26
- * bounds: [[-122.5, 37.7], [-122.3, 37.9]],
27
- * minZoom: 10,
28
- * maxZoom: 14,
29
- * styleUrl: 'https://tiles.openfreemap.org/styles/liberty'
24
+ * map.on('load', () => {
25
+ * const control = new OfflineManagerControl(offlineManager, {
26
+ * styleUrl: 'https://api.maptiler.com/maps/streets/style.json?key=YOUR_KEY',
27
+ * mapLib: maplibregl,
28
+ * });
29
+ * map.addControl(control, 'top-right');
30
30
  * });
31
31
  * ```
32
32
  *
33
- * @example Using the UI Control
33
+ * @example Programmatic region download
34
34
  * ```typescript
35
- * import { OfflineManagerControl } from 'map-gl-offline';
36
- * import 'map-gl-offline/style.css';
35
+ * const offlineManager = new OfflineMapManager();
37
36
  *
38
- * map.addControl(new OfflineManagerControl());
37
+ * await offlineManager.addRegion({
38
+ * id: 'sf',
39
+ * name: 'San Francisco',
40
+ * bounds: [[-122.5, 37.7], [-122.3, 37.9]],
41
+ * minZoom: 10,
42
+ * maxZoom: 14,
43
+ * styleUrl: 'https://api.maptiler.com/maps/streets/style.json?key=YOUR_KEY'
44
+ * });
39
45
  * ```
40
46
  */
41
47
  export { OfflineMapManager } from './managers/offlineMapManager';