map-gl-offline 0.8.5 → 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.
Files changed (54) hide show
  1. package/README.md +61 -0
  2. package/dist/index.esm.js +12 -2
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +12 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.umd.js +12 -2
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/managers/offlineMapManager/analyticsManagement.d.ts +1 -1
  9. package/dist/managers/offlineMapManager/base.d.ts +5 -5
  10. package/dist/managers/offlineMapManager/cleanupManagement.d.ts +1 -1
  11. package/dist/managers/offlineMapManager/importExportManagement.d.ts +1 -1
  12. package/dist/managers/offlineMapManager/maintenanceManagement.d.ts +1 -1
  13. package/dist/managers/offlineMapManager/regionManagement.d.ts +1 -1
  14. package/dist/managers/offlineMapManager/resourceManagement.d.ts +1 -1
  15. package/dist/managers/offlineMapManager/styleManagement.d.ts +3 -3
  16. package/dist/services/analyticsService.d.ts +1 -1
  17. package/dist/services/cleanupService.d.ts +1 -1
  18. package/dist/services/fontService.d.ts +1 -1
  19. package/dist/services/glyphService.d.ts +1 -1
  20. package/dist/services/importExportService.d.ts +1 -1
  21. package/dist/services/maintenanceService.d.ts +2 -2
  22. package/dist/services/modelService.d.ts +1 -1
  23. package/dist/services/regionService.d.ts +1 -1
  24. package/dist/services/resourceService.d.ts +2 -2
  25. package/dist/services/spriteService.d.ts +1 -1
  26. package/dist/services/styleService.d.ts +2 -2
  27. package/dist/services/tileService.d.ts +1 -1
  28. package/dist/storage/indexedDbManager.d.ts +1 -1
  29. package/dist/types/maintenance.d.ts +1 -1
  30. package/dist/types/region.d.ts +21 -3
  31. package/dist/types/style.d.ts +6 -2
  32. package/dist/ui/components/PanelActions.d.ts +1 -1
  33. package/dist/ui/components/PanelHeader.d.ts +1 -1
  34. package/dist/ui/components/RegionList.d.ts +1 -1
  35. package/dist/ui/components/shared/LanguageSelector.d.ts +1 -1
  36. package/dist/ui/components/shared/MapControlButton.d.ts +1 -1
  37. package/dist/ui/components/shared/PanelContent.d.ts +3 -3
  38. package/dist/ui/components/shared/RegionDrawingTool.d.ts +2 -2
  39. package/dist/ui/controls/polygonControl.d.ts +1 -1
  40. package/dist/ui/controls/regionControl.d.ts +4 -4
  41. package/dist/ui/managers/ControlButtonManager.d.ts +1 -1
  42. package/dist/ui/managers/PanelManager.d.ts +3 -3
  43. package/dist/ui/managers/downloadManager.d.ts +2 -2
  44. package/dist/ui/modals/mbtilesModal.d.ts +1 -1
  45. package/dist/ui/modals/regionDetailsModal.d.ts +1 -1
  46. package/dist/ui/modals/regionFormModal.d.ts +3 -3
  47. package/dist/ui/offlineManagerControl.d.ts +6 -3
  48. package/dist/utils/convertStyleForSW.d.ts +1 -1
  49. package/dist/utils/download.d.ts +1 -1
  50. package/dist/utils/importResolver.d.ts +1 -1
  51. package/dist/utils/styleProviderUtils.d.ts +1 -1
  52. package/dist/utils/styleUtils.d.ts +1 -1
  53. package/dist/utils/validation.d.ts +1 -1
  54. package/package.json +3 -2
package/README.md CHANGED
@@ -77,6 +77,8 @@ Then:
77
77
  ```typescript
78
78
  import mapboxgl from 'mapbox-gl';
79
79
  import { OfflineMapManager, OfflineManagerControl } from 'map-gl-offline';
80
+ import 'mapbox-gl/dist/mapbox-gl.css';
81
+ import 'map-gl-offline/style.css';
80
82
 
81
83
  mapboxgl.accessToken = 'YOUR_MAPBOX_TOKEN';
82
84
 
@@ -135,6 +137,65 @@ await offlineManager.cleanupExpiredRegions();
135
137
  await offlineManager.setupAutoCleanup({ intervalHours: 24, maxAge: 30 });
136
138
  ```
137
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
+
138
199
  ### Sparse-source detection
139
200
 
140
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');
@@ -12812,7 +12812,17 @@ class RegionControl {
12812
12812
  const styleUrl = this.options.styleUrl;
12813
12813
  if (!styleUrl)
12814
12814
  return new Set();
12815
- const response = await fetch(styleUrl);
12815
+ // Resolve mapbox:// style URLs — fetch() cannot load the mapbox: scheme
12816
+ // and throws "URL scheme \"mapbox\" is not supported" otherwise.
12817
+ let fetchUrl = styleUrl;
12818
+ if (isMapboxProtocol(styleUrl)) {
12819
+ if (!this.options.accessToken) {
12820
+ regionLogger.warn('Cannot resolve mapbox:// style URL for source filtering without an access token');
12821
+ return new Set();
12822
+ }
12823
+ fetchUrl = resolveMapboxUrl(styleUrl, this.options.accessToken);
12824
+ }
12825
+ const response = await fetch(fetchUrl);
12816
12826
  if (!response.ok)
12817
12827
  return new Set();
12818
12828
  const styleJson = (await response.json());