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 +4 -1
- package/dist/index.esm.js +87 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +88 -6
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +7448 -41
- package/dist/index.umd.js.map +1 -1
- package/dist/services/tileService.d.ts +9 -0
- package/dist/style.css +1 -1
- package/dist/types/font.d.ts +5 -1
- package/dist/types/tile.d.ts +29 -9
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/sqlJsLoader.d.ts +1 -2
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -183,6 +183,28 @@ const MAPBOX_API = {
|
|
|
183
183
|
MODELS_PATH: '/models/v1',
|
|
184
184
|
PROTOCOL: 'mapbox://',
|
|
185
185
|
};
|
|
186
|
+
/**
|
|
187
|
+
* Mapbox Standard sub-tilesets that are sparse-by-design across the planet.
|
|
188
|
+
* These only have tiles where the underlying feature (indoor venues, landmark
|
|
189
|
+
* POIs, 3D procedural buildings) actually exists, and return 404 for nearly
|
|
190
|
+
* every other coordinate. The tile downloader pre-skips any source whose tile
|
|
191
|
+
* URL templates reference one of these tileset IDs, so we never issue probe
|
|
192
|
+
* or download requests for them — eliminating the 404 noise in devtools.
|
|
193
|
+
*
|
|
194
|
+
* Matching is done against the tileset segment of the tile URL template
|
|
195
|
+
* (e.g. `https://api.mapbox.com/v4/mapbox.indoor-v3/{z}/{x}/{y}.vector.pbf`
|
|
196
|
+
* or `mapbox://mapbox.indoor-v3`).
|
|
197
|
+
*
|
|
198
|
+
* The ids below are the ones the live Mapbox Standard style declares — note
|
|
199
|
+
* that the landmark-POI tileset is `mapbox.mapbox-landmark-pois-v1` (doubled
|
|
200
|
+
* `mapbox` segment), unlike the other two. The matcher is delimiter-anchored,
|
|
201
|
+
* so an approximate id silently never matches.
|
|
202
|
+
*/
|
|
203
|
+
const MAPBOX_STANDARD_SPARSE_TILESETS = [
|
|
204
|
+
'mapbox.indoor-v3',
|
|
205
|
+
'mapbox.mapbox-landmark-pois-v1',
|
|
206
|
+
'mapbox.procedural-buildings-v1',
|
|
207
|
+
];
|
|
186
208
|
// Map Providers
|
|
187
209
|
const MAP_PROVIDERS = {
|
|
188
210
|
AUTO: 'auto',
|
|
@@ -3285,15 +3307,42 @@ function configureSqlJs(config) {
|
|
|
3285
3307
|
sqlJsPromise = null;
|
|
3286
3308
|
}
|
|
3287
3309
|
/**
|
|
3288
|
-
*
|
|
3289
|
-
*
|
|
3310
|
+
* Resolve the `initSqlJs` factory.
|
|
3311
|
+
*
|
|
3312
|
+
* Bundler builds resolve the npm package via dynamic `import()`, so `sql.js`
|
|
3313
|
+
* only ships with bundles that actually call MBTiles code. The UMD/CDN build
|
|
3314
|
+
* has no module resolver, so the import throws there — fall back to the
|
|
3315
|
+
* `initSqlJs` global that sql.js's own `<script>` build defines.
|
|
3316
|
+
*/
|
|
3317
|
+
async function resolveInitSqlJs() {
|
|
3318
|
+
let importError;
|
|
3319
|
+
try {
|
|
3320
|
+
const mod = (await import('sql.js'));
|
|
3321
|
+
if (typeof mod?.default === 'function')
|
|
3322
|
+
return mod.default;
|
|
3323
|
+
}
|
|
3324
|
+
catch (error) {
|
|
3325
|
+
// Bare specifier not resolvable (UMD/CDN), or the module threw while
|
|
3326
|
+
// initialising. Either way, try the global before giving up.
|
|
3327
|
+
importError = error;
|
|
3328
|
+
}
|
|
3329
|
+
const globalInit = globalThis.initSqlJs;
|
|
3330
|
+
if (typeof globalInit === 'function')
|
|
3331
|
+
return globalInit;
|
|
3332
|
+
// Preserve the original failure — a module that resolved but threw is a
|
|
3333
|
+
// very different problem from one that couldn't be resolved at all.
|
|
3334
|
+
throw new Error('sql.js could not be loaded. Install `sql.js` when bundling, or load ' +
|
|
3335
|
+
'https://cdn.jsdelivr.net/npm/sql.js/dist/sql-wasm.js before map-gl-offline ' +
|
|
3336
|
+
'when using the UMD build.', importError !== undefined ? { cause: importError } : undefined);
|
|
3337
|
+
}
|
|
3338
|
+
/**
|
|
3339
|
+
* Lazily initialise `sql.js`.
|
|
3290
3340
|
*/
|
|
3291
3341
|
async function getSqlJs() {
|
|
3292
3342
|
if (sqlJsPromise)
|
|
3293
3343
|
return sqlJsPromise;
|
|
3294
3344
|
sqlJsPromise = (async () => {
|
|
3295
|
-
const
|
|
3296
|
-
const initSqlJs = mod.default;
|
|
3345
|
+
const initSqlJs = await resolveInitSqlJs();
|
|
3297
3346
|
const options = {};
|
|
3298
3347
|
if (currentConfig.wasmBinary) {
|
|
3299
3348
|
options.wasmBinary = currentConfig.wasmBinary;
|
|
@@ -6147,6 +6196,26 @@ const getExpiredResourceCount = () => cleanupService.getExpiredResourceCount();
|
|
|
6147
6196
|
const cleanupExpiredTiles = (styleId) => cleanupService.cleanupExpiredTiles(styleId);
|
|
6148
6197
|
|
|
6149
6198
|
const tileLogger = logger.scope('TileService');
|
|
6199
|
+
/**
|
|
6200
|
+
* Match a tile-URL template against the known-sparse Mapbox Standard
|
|
6201
|
+
* sub-tilesets. Catches:
|
|
6202
|
+
* - `mapbox://<tileset>` — original style source URL.
|
|
6203
|
+
* - `.../v4/<tileset>.json...` — resolved TileJSON URL produced when the
|
|
6204
|
+
* library resolves a `mapbox://` source URL into an HTTPS one.
|
|
6205
|
+
* - `.../v4/<tileset>/{z}/{x}/{y}...` — resolved tile-template URL.
|
|
6206
|
+
*/
|
|
6207
|
+
function urlReferencesKnownSparseTileset(template) {
|
|
6208
|
+
return MAPBOX_STANDARD_SPARSE_TILESETS.some(tileset => {
|
|
6209
|
+
if (template.includes(`mapbox://${tileset}`))
|
|
6210
|
+
return true;
|
|
6211
|
+
// `/v4/<tileset>` followed by `/` (tile template) or `.` (e.g. `.json`)
|
|
6212
|
+
const idx = template.indexOf(`/${tileset}`);
|
|
6213
|
+
if (idx === -1)
|
|
6214
|
+
return false;
|
|
6215
|
+
const next = template[idx + tileset.length + 1];
|
|
6216
|
+
return next === '/' || next === '.';
|
|
6217
|
+
});
|
|
6218
|
+
}
|
|
6150
6219
|
/**
|
|
6151
6220
|
* Service for managing offline map tiles
|
|
6152
6221
|
* Handles downloading, storing, and retrieving map tiles from IndexedDB
|
|
@@ -6164,7 +6233,7 @@ class TileService {
|
|
|
6164
6233
|
*/
|
|
6165
6234
|
async downloadTiles(region, style, styleId, options = {}) {
|
|
6166
6235
|
const db = await this.db;
|
|
6167
|
-
const { onProgress, batchSize = 10, maxRetries = 3, skipExisting = true, timeout = 10000, retryDelay = 1000, priorityZoomLevels = [], storageQuotaCheck = true, validateTiles = false, compressTiles = false, bandwidthLimit, probeSourcesBeforeDownload = true, } = options;
|
|
6236
|
+
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;
|
|
6168
6237
|
const startTime = Date.now();
|
|
6169
6238
|
let totalSize = 0;
|
|
6170
6239
|
let downloadedTiles = 0;
|
|
@@ -6268,6 +6337,16 @@ class TileService {
|
|
|
6268
6337
|
tileLogger.debug(`Skipping source ${sourceId}: no tiles array`);
|
|
6269
6338
|
continue;
|
|
6270
6339
|
}
|
|
6340
|
+
// Pre-skip Mapbox Standard sparse sub-tilesets (indoor-v3 etc.) before
|
|
6341
|
+
// issuing any network request. They 404 for nearly every coord in a
|
|
6342
|
+
// typical region; the downstream probe step would catch them, but the
|
|
6343
|
+
// probe itself logs 404s in devtools. Matching here keeps the console
|
|
6344
|
+
// clean.
|
|
6345
|
+
if (skipKnownSparseSources &&
|
|
6346
|
+
tiles.some(template => urlReferencesKnownSparseTileset(template))) {
|
|
6347
|
+
tileLogger.info(`Skipping source "${sourceId}" — references a known sparse Mapbox Standard sub-tileset (no probe/download issued)`);
|
|
6348
|
+
continue;
|
|
6349
|
+
}
|
|
6271
6350
|
const sourceMinZ = Math.ceil(sourceConfig.minzoom ?? region.minZoom);
|
|
6272
6351
|
const sourceMaxZ = Math.floor(sourceConfig.maxzoom ?? region.maxZoom);
|
|
6273
6352
|
let coordsForSource = tileCoords.filter(coord => coord.z >= sourceMinZ && coord.z <= sourceMaxZ);
|
|
@@ -7045,7 +7124,8 @@ var tileService$1 = /*#__PURE__*/Object.freeze({
|
|
|
7045
7124
|
downloadTiles: downloadTiles,
|
|
7046
7125
|
getTileAnalytics: getTileAnalytics,
|
|
7047
7126
|
getTileStats: getTileStats,
|
|
7048
|
-
tileService: tileService
|
|
7127
|
+
tileService: tileService,
|
|
7128
|
+
urlReferencesKnownSparseTileset: urlReferencesKnownSparseTileset
|
|
7049
7129
|
});
|
|
7050
7130
|
|
|
7051
7131
|
const glyphLogger = logger.scope('GlyphService');
|
|
@@ -14017,6 +14097,7 @@ exports.ImportExportService = ImportExportService;
|
|
|
14017
14097
|
exports.MAPBOX_API = MAPBOX_API;
|
|
14018
14098
|
exports.MAPBOX_CACHE_TTL = MAPBOX_CACHE_TTL;
|
|
14019
14099
|
exports.MAPBOX_CLASSIC_STYLES = MAPBOX_CLASSIC_STYLES;
|
|
14100
|
+
exports.MAPBOX_STANDARD_SPARSE_TILESETS = MAPBOX_STANDARD_SPARSE_TILESETS;
|
|
14020
14101
|
exports.MAP_PROVIDERS = MAP_PROVIDERS;
|
|
14021
14102
|
exports.MAX_GLYPH_CODEPOINT = MAX_GLYPH_CODEPOINT;
|
|
14022
14103
|
exports.MaintenanceService = MaintenanceService;
|
|
@@ -14137,6 +14218,7 @@ exports.stopAutoCleanup = stopAutoCleanup;
|
|
|
14137
14218
|
exports.t = t;
|
|
14138
14219
|
exports.tileService = tileService;
|
|
14139
14220
|
exports.unregisterOfflineServiceWorker = unregisterOfflineServiceWorker;
|
|
14221
|
+
exports.urlReferencesKnownSparseTileset = urlReferencesKnownSparseTileset;
|
|
14140
14222
|
exports.validateBounds = validateBounds;
|
|
14141
14223
|
exports.validateRegionOptions = validateRegionOptions;
|
|
14142
14224
|
exports.validateResource = validateResource;
|