map-gl-offline 0.8.6 → 0.8.7

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
@@ -137,6 +137,65 @@ await offlineManager.cleanupExpiredRegions();
137
137
  await offlineManager.setupAutoCleanup({ intervalHours: 24, maxAge: 30 });
138
138
  ```
139
139
 
140
+ ### Multi-region downloads (global overview + city detail)
141
+
142
+ For app shipping use cases — a low-zoom basemap of the world, plus high-zoom detail in the cities your users actually visit — set `multipleRegions: true` on each region so the manager reuses the shared style/sprites/glyphs across downloads. The exported `BoundingBox` type keeps city lists from being widened to `number[][]`, so you can write the bounds inline without `as` casts.
143
+
144
+ ```typescript
145
+ import mapboxgl from 'mapbox-gl';
146
+ import {
147
+ OfflineMapManager,
148
+ type BoundingBox,
149
+ type DownloadRegionProgress,
150
+ } from 'map-gl-offline';
151
+
152
+ const offlineManager = new OfflineMapManager();
153
+ const STYLE_URL = 'mapbox://styles/mapbox/standard';
154
+
155
+ const opts = {
156
+ accessToken: mapboxgl.accessToken, // `string | null` is accepted — no cast needed
157
+ onProgress: ({ phase, percentage, message }: DownloadRegionProgress) =>
158
+ console.log(`[${phase}] ${percentage.toFixed(1)}% ${message ?? ''}`),
159
+ };
160
+
161
+ // 1) Whole planet, low zoom only (~5,500 tiles/source) — countries, major cities
162
+ await offlineManager.downloadRegion(
163
+ {
164
+ id: 'global-overview',
165
+ name: 'Global overview',
166
+ bounds: [[-180, -85.0511], [180, 85.0511]], // ±85.0511° = Web Mercator cutoff
167
+ minZoom: 0,
168
+ maxZoom: 6,
169
+ styleUrl: STYLE_URL,
170
+ multipleRegions: true,
171
+ },
172
+ opts,
173
+ );
174
+
175
+ // 2) High-detail per city — tight bbox per place your users actually go
176
+ const cities: Array<{ id: string; name: string; bounds: BoundingBox }> = [
177
+ { id: 'nyc', name: 'New York', bounds: [[-74.05, 40.68], [-73.90, 40.82]] },
178
+ { id: 'london', name: 'London', bounds: [[-0.25, 51.43], [0.02, 51.57]] },
179
+ ];
180
+
181
+ for (const city of cities) {
182
+ await offlineManager.downloadRegion(
183
+ {
184
+ id: city.id,
185
+ name: city.name,
186
+ bounds: city.bounds,
187
+ minZoom: 6, // overlaps the overview's maxZoom — clean handoff, no seam
188
+ maxZoom: 14, // street-level detail
189
+ styleUrl: STYLE_URL,
190
+ multipleRegions: true,
191
+ },
192
+ opts,
193
+ );
194
+ }
195
+ ```
196
+
197
+ > **Don't download the whole globe at high zoom.** The tile count quadruples per zoom level — `minZoom: 0, maxZoom: 15` for the whole planet is ~1.4 billion tiles per source, which will blow past IndexedDB quota and may violate provider TOS. The two-tier setup above gives countries-everywhere plus streets-where-it-matters for a few thousand tiles total.
198
+
140
199
  ### Sparse-source detection
141
200
 
142
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 }`.
package/dist/index.esm.js CHANGED
@@ -11365,7 +11365,7 @@ class PanelRenderer extends BaseComponent {
11365
11365
  try {
11366
11366
  const { loadStyleById } = await Promise.resolve().then(function () { return styleService; });
11367
11367
  const styleEntry = await loadStyleById(region.styleId);
11368
- accessToken = styleEntry?.accessToken;
11368
+ accessToken = styleEntry?.accessToken ?? undefined;
11369
11369
  }
11370
11370
  catch {
11371
11371
  panelLogger.warn('Could not retrieve access token from stored style');