map-gl-offline 0.8.7 → 0.8.9

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
@@ -25,7 +25,7 @@ TypeScript offline-map library for **MapLibre GL JS** and **Mapbox GL JS**. Down
25
25
  npm install map-gl-offline
26
26
  ```
27
27
 
28
- Or via CDN as the `mapgloffline` global:
28
+ Or via CDN as the `mapgloffline` global. The UMD build is self-contained — only your map library needs to be on the page:
29
29
 
30
30
  ```html
31
31
  <script src="https://unpkg.com/map-gl-offline/dist/index.umd.js"></script>
@@ -200,6 +200,8 @@ for (const city of cities) {
200
200
 
201
201
  For composite styles (e.g. Mapbox Standard) that reference sparse tilesets like `indoor-v3` or `landmark-pois-v1`, the tile downloader probes start/middle/end tiles per source and drops any that return majority-404. Disable with `tileOptions: { probeSourcesBeforeDownload: false }`.
202
202
 
203
+ Three Mapbox Standard sub-tilesets are sparse-by-design across the planet — `mapbox.indoor-v3`, `mapbox.mapbox-landmark-pois-v1`, `mapbox.procedural-buildings-v1`. Since 0.8.8 these are hard-skipped **before** the probe step so no network request is issued (and no 404s land in devtools). Opt out with `tileOptions: { skipKnownSparseSources: false }` to run them through the probe path instead.
204
+
203
205
  ### Recovering from an incompatible DB
204
206
 
205
207
  If another app on the same origin has created `offline-map-db` at a newer version, `dbPromise` throws a typed error. Offer a reset UX:
@@ -224,6 +226,7 @@ try {
224
226
  ## API at a glance
225
227
 
226
228
  - **Regions** — `downloadRegion`, `loadRegion`, `addRegion`, `getStoredRegion`, `listStoredRegions`, `listRegions`, `deleteRegion`
229
+ - **Styles** — `downloadStyle`, `downloadMapboxStyle`, `downloadMapLibreStyle`, `downloadStyleWithAutoDetection`, `listStyles`, `loadStyleById`, `getStyleStats`, `deleteStyle`, `cleanupOldStyles`
227
230
  - **Analytics** — `getComprehensiveStorageAnalytics`, `getRegionAnalytics`, `getTileStats`, `getFontStats`, `getSpriteStats`, `getGlyphStats`
228
231
  - **Cleanup** — `cleanupExpiredRegions`, `performSmartCleanup`, `cleanupOld{Fonts,Sprites,Glyphs}`, `verifyAndRepair{Fonts,Sprites,Glyphs}`, `setupAutoCleanup`, `performCompleteMaintenance`
229
232
  - **Import / Export** — `exportRegionAsMBTiles`, `importRegion`, `downloadExportedRegion` (binary SQLite MBTiles, QGIS/tippecanoe-compatible)
package/dist/index.esm.js CHANGED
@@ -160,6 +160,28 @@ const MAPBOX_API = {
160
160
  MODELS_PATH: '/models/v1',
161
161
  PROTOCOL: 'mapbox://',
162
162
  };
163
+ /**
164
+ * Mapbox Standard sub-tilesets that are sparse-by-design across the planet.
165
+ * These only have tiles where the underlying feature (indoor venues, landmark
166
+ * POIs, 3D procedural buildings) actually exists, and return 404 for nearly
167
+ * every other coordinate. The tile downloader pre-skips any source whose tile
168
+ * URL templates reference one of these tileset IDs, so we never issue probe
169
+ * or download requests for them — eliminating the 404 noise in devtools.
170
+ *
171
+ * Matching is done against the tileset segment of the tile URL template
172
+ * (e.g. `https://api.mapbox.com/v4/mapbox.indoor-v3/{z}/{x}/{y}.vector.pbf`
173
+ * or `mapbox://mapbox.indoor-v3`).
174
+ *
175
+ * The ids below are the ones the live Mapbox Standard style declares — note
176
+ * that the landmark-POI tileset is `mapbox.mapbox-landmark-pois-v1` (doubled
177
+ * `mapbox` segment), unlike the other two. The matcher is delimiter-anchored,
178
+ * so an approximate id silently never matches.
179
+ */
180
+ const MAPBOX_STANDARD_SPARSE_TILESETS = [
181
+ 'mapbox.indoor-v3',
182
+ 'mapbox.mapbox-landmark-pois-v1',
183
+ 'mapbox.procedural-buildings-v1',
184
+ ];
163
185
  // Map Providers
164
186
  const MAP_PROVIDERS = {
165
187
  AUTO: 'auto',
@@ -3262,15 +3284,42 @@ function configureSqlJs(config) {
3262
3284
  sqlJsPromise = null;
3263
3285
  }
3264
3286
  /**
3265
- * Lazily initialise `sql.js`. The underlying module is loaded via dynamic
3266
- * `import()` so it only ships with bundles that actually call MBTiles code.
3287
+ * Resolve the `initSqlJs` factory.
3288
+ *
3289
+ * Bundler builds resolve the npm package via dynamic `import()`, so `sql.js`
3290
+ * only ships with bundles that actually call MBTiles code. The UMD/CDN build
3291
+ * has no module resolver, so the import throws there — fall back to the
3292
+ * `initSqlJs` global that sql.js's own `<script>` build defines.
3293
+ */
3294
+ async function resolveInitSqlJs() {
3295
+ let importError;
3296
+ try {
3297
+ const mod = (await import('sql.js'));
3298
+ if (typeof mod?.default === 'function')
3299
+ return mod.default;
3300
+ }
3301
+ catch (error) {
3302
+ // Bare specifier not resolvable (UMD/CDN), or the module threw while
3303
+ // initialising. Either way, try the global before giving up.
3304
+ importError = error;
3305
+ }
3306
+ const globalInit = globalThis.initSqlJs;
3307
+ if (typeof globalInit === 'function')
3308
+ return globalInit;
3309
+ // Preserve the original failure — a module that resolved but threw is a
3310
+ // very different problem from one that couldn't be resolved at all.
3311
+ throw new Error('sql.js could not be loaded. Install `sql.js` when bundling, or load ' +
3312
+ 'https://cdn.jsdelivr.net/npm/sql.js/dist/sql-wasm.js before map-gl-offline ' +
3313
+ 'when using the UMD build.', importError !== undefined ? { cause: importError } : undefined);
3314
+ }
3315
+ /**
3316
+ * Lazily initialise `sql.js`.
3267
3317
  */
3268
3318
  async function getSqlJs() {
3269
3319
  if (sqlJsPromise)
3270
3320
  return sqlJsPromise;
3271
3321
  sqlJsPromise = (async () => {
3272
- const mod = (await import('sql.js'));
3273
- const initSqlJs = mod.default;
3322
+ const initSqlJs = await resolveInitSqlJs();
3274
3323
  const options = {};
3275
3324
  if (currentConfig.wasmBinary) {
3276
3325
  options.wasmBinary = currentConfig.wasmBinary;
@@ -6124,6 +6173,26 @@ const getExpiredResourceCount = () => cleanupService.getExpiredResourceCount();
6124
6173
  const cleanupExpiredTiles = (styleId) => cleanupService.cleanupExpiredTiles(styleId);
6125
6174
 
6126
6175
  const tileLogger = logger.scope('TileService');
6176
+ /**
6177
+ * Match a tile-URL template against the known-sparse Mapbox Standard
6178
+ * sub-tilesets. Catches:
6179
+ * - `mapbox://<tileset>` — original style source URL.
6180
+ * - `.../v4/<tileset>.json...` — resolved TileJSON URL produced when the
6181
+ * library resolves a `mapbox://` source URL into an HTTPS one.
6182
+ * - `.../v4/<tileset>/{z}/{x}/{y}...` — resolved tile-template URL.
6183
+ */
6184
+ function urlReferencesKnownSparseTileset(template) {
6185
+ return MAPBOX_STANDARD_SPARSE_TILESETS.some(tileset => {
6186
+ if (template.includes(`mapbox://${tileset}`))
6187
+ return true;
6188
+ // `/v4/<tileset>` followed by `/` (tile template) or `.` (e.g. `.json`)
6189
+ const idx = template.indexOf(`/${tileset}`);
6190
+ if (idx === -1)
6191
+ return false;
6192
+ const next = template[idx + tileset.length + 1];
6193
+ return next === '/' || next === '.';
6194
+ });
6195
+ }
6127
6196
  /**
6128
6197
  * Service for managing offline map tiles
6129
6198
  * Handles downloading, storing, and retrieving map tiles from IndexedDB
@@ -6141,7 +6210,7 @@ class TileService {
6141
6210
  */
6142
6211
  async downloadTiles(region, style, styleId, options = {}) {
6143
6212
  const db = await this.db;
6144
- const { onProgress, batchSize = 10, maxRetries = 3, skipExisting = true, timeout = 10000, retryDelay = 1000, priorityZoomLevels = [], storageQuotaCheck = true, validateTiles = false, compressTiles = false, bandwidthLimit, probeSourcesBeforeDownload = true, } = options;
6213
+ const { onProgress, batchSize = 10, maxRetries = 3, skipExisting = true, timeout = 10000, retryDelay = 1000, priorityZoomLevels = [], storageQuotaCheck = true, validateTiles = false, compressTiles = false, bandwidthLimit, probeSourcesBeforeDownload = true, skipKnownSparseSources = true, } = options;
6145
6214
  const startTime = Date.now();
6146
6215
  let totalSize = 0;
6147
6216
  let downloadedTiles = 0;
@@ -6245,6 +6314,16 @@ class TileService {
6245
6314
  tileLogger.debug(`Skipping source ${sourceId}: no tiles array`);
6246
6315
  continue;
6247
6316
  }
6317
+ // Pre-skip Mapbox Standard sparse sub-tilesets (indoor-v3 etc.) before
6318
+ // issuing any network request. They 404 for nearly every coord in a
6319
+ // typical region; the downstream probe step would catch them, but the
6320
+ // probe itself logs 404s in devtools. Matching here keeps the console
6321
+ // clean.
6322
+ if (skipKnownSparseSources &&
6323
+ tiles.some(template => urlReferencesKnownSparseTileset(template))) {
6324
+ tileLogger.info(`Skipping source "${sourceId}" — references a known sparse Mapbox Standard sub-tileset (no probe/download issued)`);
6325
+ continue;
6326
+ }
6248
6327
  const sourceMinZ = Math.ceil(sourceConfig.minzoom ?? region.minZoom);
6249
6328
  const sourceMaxZ = Math.floor(sourceConfig.maxzoom ?? region.maxZoom);
6250
6329
  let coordsForSource = tileCoords.filter(coord => coord.z >= sourceMinZ && coord.z <= sourceMaxZ);
@@ -7022,7 +7101,8 @@ var tileService$1 = /*#__PURE__*/Object.freeze({
7022
7101
  downloadTiles: downloadTiles,
7023
7102
  getTileAnalytics: getTileAnalytics,
7024
7103
  getTileStats: getTileStats,
7025
- tileService: tileService
7104
+ tileService: tileService,
7105
+ urlReferencesKnownSparseTileset: urlReferencesKnownSparseTileset
7026
7106
  });
7027
7107
 
7028
7108
  const glyphLogger = logger.scope('GlyphService');
@@ -13977,5 +14057,5 @@ class OfflineManagerControl {
13977
14057
  }
13978
14058
  }
13979
14059
 
13980
- export { AnalyticsService, CONTENT_TYPES, CategorizedError, CleanupService, DB_NAME, DB_VERSION, DOWNLOAD_DEFAULTS, ERROR_MESSAGES, ErrorType, FontService, GLYPH_BLOCK_SIZE, GLYPH_CONFIG, GZIP_MAGIC_BYTES, GlyphService, ImportExportService, LogLevel, MAPBOX_API, MAPBOX_CACHE_TTL, MAPBOX_CLASSIC_STYLES, MAP_PROVIDERS, MAX_GLYPH_CODEPOINT, MaintenanceService, ModelService, OfflineManagerControl, OfflineMapDBVersionError, OfflineMapManager, RESOURCE_TYPES, RegionService, ResourceService, STORAGE_CONFIG, STORE_NAMES, STYLE_CONFIG, SUCCESS_MESSAGES, ScopedLogger, SpriteService, TILE_CONFIG, TileService, URL_SCHEMES, VALIDATION_PATTERNS, applyProxy, categorizeError, cleanupCompressedTiles, cleanupExpiredTiles, cleanupOldFonts, cleanupOldGlyphs, cleanupOldModels, cleanupOldSprites, cleanupOldStyles, cleanupOldTiles, cleanupService, clearAllCaches, configureLogger, configureProxy, configureSqlJs, convertStyleForServiceWorker, countCompressedTiles, createProgressTracker, createTileKey, dbPromise, OfflineMapManager as default, deleteStyleById, deleteStyles, deriveTileExtension, detectCssPrefix, detectStyleProvider, downloadFonts, downloadGlyphs, downloadModels, downloadSprites, downloadStyleWithProvider, downloadStyles, downloadTiles, escapeHtml$1 as escapeHtml, extractAccessToken, extractAllFontNames, extractFontNamesFromTextField, extractTileExtensionFromUrl, fetchResourceWithRetry, fetchWithRetry, fontService, formatBytes, formatDate, generateGlyphUrlsFromStyle, getExpiredResourceCount, getFontAnalytics, getFontStats, getGlyphAnalytics, getGlyphStats, getIcon, getModel, getModelStats, getRegionAnalytics, getSpriteAnalytics, getSpriteStats, getSqlJs, getStyleStats, getTileAnalytics, getTileStats, getUrlHostname, getUserErrorMessage, glyphService, hasImports, hostMatches, i18n, icons, idbFetchHandler, isMapboxHost, isMapboxProtocol, isStyleDownloaded, loadAllStoredRegions, loadGlyphs, loadStyleById, loadStyles, logger, modelKeyBelongsToStyle, modelService, normalizeSpriteProperty, normalizeStyleUrl, optimizeStorage, parseCacheExpiry, parseTileKey, patchStyleForOffline, performCleanup, processBatch, processStyleSources, registerOfflineServiceWorker, resetOfflineMapDB, resolveImports, resolveMapboxUrl, resourceKeyBelongsToStyle, rewriteMapboxCdnTileUrl, safeExecute, sanitizeIndoorExpressions, setupAutoCleanup, spriteService, stopAutoCleanup, t, tileService, unregisterOfflineServiceWorker, validateBounds, validateRegionOptions, validateResource, validateStyleForProvider, validateZoomLevels, verifyAndRepairFonts, verifyAndRepairGlyphs, verifyAndRepairModels, verifyAndRepairSprites };
14060
+ export { AnalyticsService, CONTENT_TYPES, CategorizedError, CleanupService, DB_NAME, DB_VERSION, DOWNLOAD_DEFAULTS, ERROR_MESSAGES, ErrorType, FontService, GLYPH_BLOCK_SIZE, GLYPH_CONFIG, GZIP_MAGIC_BYTES, GlyphService, ImportExportService, LogLevel, MAPBOX_API, MAPBOX_CACHE_TTL, MAPBOX_CLASSIC_STYLES, MAPBOX_STANDARD_SPARSE_TILESETS, MAP_PROVIDERS, MAX_GLYPH_CODEPOINT, MaintenanceService, ModelService, OfflineManagerControl, OfflineMapDBVersionError, OfflineMapManager, RESOURCE_TYPES, RegionService, ResourceService, STORAGE_CONFIG, STORE_NAMES, STYLE_CONFIG, SUCCESS_MESSAGES, ScopedLogger, SpriteService, TILE_CONFIG, TileService, URL_SCHEMES, VALIDATION_PATTERNS, applyProxy, categorizeError, cleanupCompressedTiles, cleanupExpiredTiles, cleanupOldFonts, cleanupOldGlyphs, cleanupOldModels, cleanupOldSprites, cleanupOldStyles, cleanupOldTiles, cleanupService, clearAllCaches, configureLogger, configureProxy, configureSqlJs, convertStyleForServiceWorker, countCompressedTiles, createProgressTracker, createTileKey, dbPromise, OfflineMapManager as default, deleteStyleById, deleteStyles, deriveTileExtension, detectCssPrefix, detectStyleProvider, downloadFonts, downloadGlyphs, downloadModels, downloadSprites, downloadStyleWithProvider, downloadStyles, downloadTiles, escapeHtml$1 as escapeHtml, extractAccessToken, extractAllFontNames, extractFontNamesFromTextField, extractTileExtensionFromUrl, fetchResourceWithRetry, fetchWithRetry, fontService, formatBytes, formatDate, generateGlyphUrlsFromStyle, getExpiredResourceCount, getFontAnalytics, getFontStats, getGlyphAnalytics, getGlyphStats, getIcon, getModel, getModelStats, getRegionAnalytics, getSpriteAnalytics, getSpriteStats, getSqlJs, getStyleStats, getTileAnalytics, getTileStats, getUrlHostname, getUserErrorMessage, glyphService, hasImports, hostMatches, i18n, icons, idbFetchHandler, isMapboxHost, isMapboxProtocol, isStyleDownloaded, loadAllStoredRegions, loadGlyphs, loadStyleById, loadStyles, logger, modelKeyBelongsToStyle, modelService, normalizeSpriteProperty, normalizeStyleUrl, optimizeStorage, parseCacheExpiry, parseTileKey, patchStyleForOffline, performCleanup, processBatch, processStyleSources, registerOfflineServiceWorker, resetOfflineMapDB, resolveImports, resolveMapboxUrl, resourceKeyBelongsToStyle, rewriteMapboxCdnTileUrl, safeExecute, sanitizeIndoorExpressions, setupAutoCleanup, spriteService, stopAutoCleanup, t, tileService, unregisterOfflineServiceWorker, urlReferencesKnownSparseTileset, validateBounds, validateRegionOptions, validateResource, validateStyleForProvider, validateZoomLevels, verifyAndRepairFonts, verifyAndRepairGlyphs, verifyAndRepairModels, verifyAndRepairSprites };
13981
14061
  //# sourceMappingURL=index.esm.js.map