@india-boundary-corrector/openlayers-layer 0.0.1 → 0.0.2

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
@@ -1,7 +1,11 @@
1
1
  # @india-boundary-corrector/openlayers-layer
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@india-boundary-corrector/openlayers-layer)](https://www.npmjs.com/package/@india-boundary-corrector/openlayers-layer)
4
+
3
5
  OpenLayers TileLayer extension that automatically applies India boundary corrections.
4
6
 
7
+ [Try it on JSFiddle](https://jsfiddle.net/waoepz78/)
8
+
5
9
  ## Installation
6
10
 
7
11
  ```bash
@@ -28,11 +32,14 @@ No bundler required! Just include the script and use the global `IndiaBoundaryCo
28
32
  target: 'map',
29
33
  layers: [
30
34
  new IndiaBoundaryCorrectedTileLayer({
31
- url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
35
+ url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
36
+ sourceOptions: {
37
+ attributions: '© OpenStreetMap contributors'
38
+ }
32
39
  })
33
40
  ],
34
41
  view: new ol.View({
35
- center: ol.proj.fromLonLat([78.9629, 20.5937]),
42
+ center: ol.proj.fromLonLat([75.3412, 33.2778]),
36
43
  zoom: 5
37
44
  })
38
45
  });
@@ -50,11 +57,14 @@ const map = new Map({
50
57
  target: 'map',
51
58
  layers: [
52
59
  new IndiaBoundaryCorrectedTileLayer({
53
- url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
60
+ url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png',
61
+ sourceOptions: {
62
+ attributions: '© OpenStreetMap contributors'
63
+ }
54
64
  })
55
65
  ],
56
66
  view: new View({
57
- center: fromLonLat([78.9629, 20.5937]),
67
+ center: fromLonLat([75.3412, 33.2778]),
58
68
  zoom: 5
59
69
  })
60
70
  });
package/dist/index.cjs CHANGED
@@ -89,8 +89,7 @@ function createCorrectedTileLoadFunction(tileFixer, layerConfig, tileSize, layer
89
89
  image.src = blobUrl;
90
90
  }
91
91
  } catch (err) {
92
- console.warn("[IndiaBoundaryCorrectedTileLayer] Error applying corrections, falling back to original:", err);
93
- layer.dispatchEvent({ type: "correctionerror", error: err, coords: { z, x, y }, tileUrl: src });
92
+ console.warn("[IndiaBoundaryCorrectedTileLayer] Tile fetch failed:", err);
94
93
  const image = imageTile.getImage();
95
94
  if (typeof image.src !== "undefined") {
96
95
  image.src = src;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"sourcesContent":["import TileLayer from 'ol/layer/Tile.js';\nimport XYZ from 'ol/source/XYZ.js';\nimport { getPmtilesUrl } from '@india-boundary-corrector/data';\nimport { layerConfigs } from '@india-boundary-corrector/layer-configs';\nimport { BoundaryCorrector as TileFixer } from '@india-boundary-corrector/tilefixer';\n\n// Re-export for convenience\nexport { layerConfigs, LayerConfig } from '@india-boundary-corrector/layer-configs';\nexport { getPmtilesUrl } from '@india-boundary-corrector/data';\n\n/**\n * Handle tile fetching and correction application logic.\n * This method is extracted for testability.\n * @param {string} src - URL of the raster tile\n * @param {number} z - Zoom level\n * @param {number} x - Tile X coordinate\n * @param {number} y - Tile Y coordinate\n * @param {TileFixer} tileFixer - TileFixer instance\n * @param {Object} layerConfig - Layer configuration\n * @param {number} tileSize - Tile size in pixels\n * @returns {Promise<{blob: Blob, wasFixed: boolean, correctionsFailed: boolean, correctionsError: Error|null}>}\n */\nasync function fetchAndFixTile(src, z, x, y, tileFixer, layerConfig, tileSize) {\n const { data, wasFixed, correctionsFailed, correctionsError } = await tileFixer.fetchAndFixTile(\n src, z, x, y, layerConfig, { tileSize, mode: 'cors' }\n );\n const blob = new Blob([data], { type: wasFixed ? 'image/png' : undefined });\n return { blob, wasFixed, correctionsFailed, correctionsError };\n}\n\n/**\n * Create a custom tileLoadFunction that applies boundary corrections.\n * @param {TileFixer} tileFixer - The TileFixer instance\n * @param {Object} layerConfig - The layer configuration\n * @param {number} tileSize - Tile size in pixels\n * @param {IndiaBoundaryCorrectedTileLayer} layer - The layer instance for event dispatching\n * @returns {Function} Custom tile load function\n */\nfunction createCorrectedTileLoadFunction(tileFixer, layerConfig, tileSize, layer) {\n return async function(imageTile, src) {\n const tileCoord = imageTile.getTileCoord();\n const z = tileCoord[0];\n const x = tileCoord[1];\n const y = tileCoord[2];\n\n // TODO: Pass AbortSignal to fetchAndFixTile to cancel in-flight requests when tiles\n // go off-screen. OpenLayers' tileLoadFunction doesn't provide an AbortController,\n // so this would require custom tracking. Deferred due to complexity - will revisit\n // if performance becomes an issue during rapid panning.\n try {\n const { blob, correctionsFailed, correctionsError } = await fetchAndFixTile(src, z, x, y, tileFixer, layerConfig, tileSize);\n\n if (correctionsFailed) {\n console.warn('[IndiaBoundaryCorrectedTileLayer] Corrections fetch failed:', correctionsError);\n layer.dispatchEvent({ type: 'correctionerror', error: correctionsError, coords: { z, x, y }, tileUrl: src });\n }\n\n const image = imageTile.getImage();\n \n // Check if image is a canvas (OffscreenCanvas) or HTMLImageElement\n if (typeof image.getContext === 'function') {\n // OffscreenCanvas path\n const imageBitmap = await createImageBitmap(blob);\n image.width = imageBitmap.width;\n image.height = imageBitmap.height;\n const ctx = image.getContext('2d');\n ctx.drawImage(imageBitmap, 0, 0);\n imageBitmap.close?.();\n image.dispatchEvent(new Event('load'));\n } else {\n // HTMLImageElement path - use blob URL\n const blobUrl = URL.createObjectURL(blob);\n image.onload = () => {\n URL.revokeObjectURL(blobUrl);\n };\n image.onerror = () => {\n URL.revokeObjectURL(blobUrl);\n };\n image.src = blobUrl;\n }\n } catch (err) {\n console.warn('[IndiaBoundaryCorrectedTileLayer] Error applying corrections, falling back to original:', err);\n layer.dispatchEvent({ type: 'correctionerror', error: err, coords: { z, x, y }, tileUrl: src });\n // Fall back to original tile\n const image = imageTile.getImage();\n if (typeof image.src !== 'undefined') {\n // HTMLImageElement - load original tile\n image.src = src;\n } else if (typeof image.dispatchEvent === 'function') {\n // OffscreenCanvas - can't fall back, signal error\n image.dispatchEvent(new Event('error'));\n }\n }\n };\n}\n\n/**\n * Extended OpenLayers TileLayer with India boundary corrections.\n * Extends ol/layer/Tile with a custom XYZ source that applies corrections.\n */\nexport class IndiaBoundaryCorrectedTileLayer extends TileLayer {\n /**\n * @param {Object} options - Layer options\n * @param {string} options.url - Tile URL template with {x}, {y}, {z} placeholders\n * @param {string} [options.pmtilesUrl] - URL to PMTiles file (defaults to CDN)\n * @param {Object|string} [options.layerConfig] - LayerConfig or config ID (auto-detected if not provided)\n * @param {Object[]} [options.extraLayerConfigs] - Additional LayerConfigs for matching\n * @param {number} [options.tileSize=256] - Tile size in pixels\n * @param {Object} [options.sourceOptions] - Additional options for XYZ source\n * @param {Object} [options.layerOptions] - Additional options for TileLayer\n */\n constructor(options) {\n const {\n url,\n pmtilesUrl,\n layerConfig,\n extraLayerConfigs,\n tileSize = 256,\n sourceOptions = {},\n ...layerOptions\n } = options;\n\n // Initialize registry and resolve layer config\n const registry = layerConfigs.createMergedRegistry(extraLayerConfigs);\n let resolvedConfig;\n \n if (typeof layerConfig === 'string') {\n resolvedConfig = registry.get(layerConfig);\n } else if (layerConfig) {\n resolvedConfig = layerConfig;\n } else {\n // Auto-detect from URL\n resolvedConfig = registry.detectFromTemplates([url]);\n }\n\n // Create TileFixer\n const tileFixer = new TileFixer(pmtilesUrl ?? getPmtilesUrl());\n\n // Create XYZ source (tileLoadFunction set after super() to access 'this')\n const source = new XYZ({\n url,\n tileSize,\n crossOrigin: 'anonymous',\n ...sourceOptions,\n });\n\n super({\n source,\n ...layerOptions\n });\n\n this._tileFixer = tileFixer;\n this._layerConfig = resolvedConfig;\n this._registry = registry;\n\n // Set tileLoadFunction after super() so we can pass 'this' for event dispatching\n if (resolvedConfig) {\n source.setTileLoadFunction(createCorrectedTileLoadFunction(tileFixer, resolvedConfig, tileSize, this));\n }\n\n if (!resolvedConfig) {\n console.warn('[IndiaBoundaryCorrectedTileLayer] Could not detect layer config from URL. Corrections will not be applied.');\n }\n }\n\n /**\n * Get the TileFixer instance.\n * @returns {TileFixer}\n */\n getTileFixer() {\n return this._tileFixer;\n }\n\n /**\n * Get the resolved LayerConfig.\n * @returns {Object|null}\n */\n getLayerConfig() {\n return this._layerConfig;\n }\n\n /**\n * Get the registry.\n * @returns {LayerConfigRegistry}\n */\n getRegistry() {\n return this._registry;\n }\n\n /**\n * Fetch and fix a tile (exposed for testing).\n * @param {string} src - Tile URL\n * @param {number} z - Zoom level\n * @param {number} x - Tile X coordinate\n * @param {number} y - Tile Y coordinate\n * @returns {Promise<{blob: Blob, wasFixed: boolean}>}\n * @private\n */\n async _fetchAndFixTile(src, z, x, y) {\n const tileSize = this.getSource().getTileGrid()?.getTileSize(z) || 256;\n return fetchAndFixTile(src, z, x, y, this._tileFixer, this._layerConfig, tileSize);\n }\n}\n\n// Export for testing\nexport { fetchAndFixTile };\n\n/**\n * Factory function to create an IndiaBoundaryCorrectedTileLayer.\n * @param {Object} options - Layer options (see IndiaBoundaryCorrectedTileLayer constructor)\n * @returns {IndiaBoundaryCorrectedTileLayer}\n */\nexport function indiaBoundaryCorrectedTileLayer(options) {\n return new IndiaBoundaryCorrectedTileLayer(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsB;AACtB,iBAAgB;AAChB,kBAA8B;AAC9B,2BAA6B;AAC7B,uBAA+C;AAG/C,IAAAA,wBAA0C;AAC1C,IAAAC,eAA8B;AAc9B,eAAe,gBAAgB,KAAK,GAAG,GAAG,GAAG,WAAW,aAAa,UAAU;AAC7E,QAAM,EAAE,MAAM,UAAU,mBAAmB,iBAAiB,IAAI,MAAM,UAAU;AAAA,IAC9E;AAAA,IAAK;AAAA,IAAG;AAAA,IAAG;AAAA,IAAG;AAAA,IAAa,EAAE,UAAU,MAAM,OAAO;AAAA,EACtD;AACA,QAAM,OAAO,IAAI,KAAK,CAAC,IAAI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eAAe;AACb,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,iBAAiB;AACf,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,iBAAiB,KAAK,GAAG,GAAG,GAAG;AACnC,UAAM,WAAW,KAAK,UAAU,EAAE,YAAY,GAAG,YAAY,CAAC,KAAK;AACnE,WAAO,gBAAgB,KAAK,GAAG,GAAG,GAAG,KAAK,YAAY,KAAK,cAAc,QAAQ;AAAA,EACnF;AACF;AAUO,SAAS,gCAAgC,SAAS;AACvD,SAAO,IAAI,gCAAgC,OAAO;AACpD;","names":["import_layer_configs","import_data","TileLayer","TileFixer","XYZ"]}
1
+ {"version":3,"sources":["../src/index.js"],"sourcesContent":["import TileLayer from 'ol/layer/Tile.js';\nimport XYZ from 'ol/source/XYZ.js';\nimport { getPmtilesUrl } from '@india-boundary-corrector/data';\nimport { layerConfigs } from '@india-boundary-corrector/layer-configs';\nimport { BoundaryCorrector as TileFixer } from '@india-boundary-corrector/tilefixer';\n\n// Re-export for convenience\nexport { layerConfigs, LayerConfig } from '@india-boundary-corrector/layer-configs';\nexport { getPmtilesUrl } from '@india-boundary-corrector/data';\n\n/**\n * Handle tile fetching and correction application logic.\n * This method is extracted for testability.\n * @param {string} src - URL of the raster tile\n * @param {number} z - Zoom level\n * @param {number} x - Tile X coordinate\n * @param {number} y - Tile Y coordinate\n * @param {TileFixer} tileFixer - TileFixer instance\n * @param {Object} layerConfig - Layer configuration\n * @param {number} tileSize - Tile size in pixels\n * @returns {Promise<{blob: Blob, wasFixed: boolean, correctionsFailed: boolean, correctionsError: Error|null}>}\n */\nasync function fetchAndFixTile(src, z, x, y, tileFixer, layerConfig, tileSize) {\n const { data, wasFixed, correctionsFailed, correctionsError } = await tileFixer.fetchAndFixTile(\n src, z, x, y, layerConfig, { tileSize, mode: 'cors' }\n );\n const blob = new Blob([data], { type: wasFixed ? 'image/png' : undefined });\n return { blob, wasFixed, correctionsFailed, correctionsError };\n}\n\n/**\n * Create a custom tileLoadFunction that applies boundary corrections.\n * @param {TileFixer} tileFixer - The TileFixer instance\n * @param {Object} layerConfig - The layer configuration\n * @param {number} tileSize - Tile size in pixels\n * @param {IndiaBoundaryCorrectedTileLayer} layer - The layer instance for event dispatching\n * @returns {Function} Custom tile load function\n */\nfunction createCorrectedTileLoadFunction(tileFixer, layerConfig, tileSize, layer) {\n return async function(imageTile, src) {\n const tileCoord = imageTile.getTileCoord();\n const z = tileCoord[0];\n const x = tileCoord[1];\n const y = tileCoord[2];\n\n // TODO: Pass AbortSignal to fetchAndFixTile to cancel in-flight requests when tiles\n // go off-screen. OpenLayers' tileLoadFunction doesn't provide an AbortController,\n // so this would require custom tracking. Deferred due to complexity - will revisit\n // if performance becomes an issue during rapid panning.\n try {\n const { blob, correctionsFailed, correctionsError } = await fetchAndFixTile(src, z, x, y, tileFixer, layerConfig, tileSize);\n\n if (correctionsFailed) {\n // TODO: If abort is implemented, check for AbortError here and skip emitting correctionerror\n console.warn('[IndiaBoundaryCorrectedTileLayer] Corrections fetch failed:', correctionsError);\n layer.dispatchEvent({ type: 'correctionerror', error: correctionsError, coords: { z, x, y }, tileUrl: src });\n }\n\n const image = imageTile.getImage();\n \n // Check if image is a canvas (OffscreenCanvas) or HTMLImageElement\n if (typeof image.getContext === 'function') {\n // OffscreenCanvas path\n const imageBitmap = await createImageBitmap(blob);\n image.width = imageBitmap.width;\n image.height = imageBitmap.height;\n const ctx = image.getContext('2d');\n ctx.drawImage(imageBitmap, 0, 0);\n imageBitmap.close?.();\n image.dispatchEvent(new Event('load'));\n } else {\n // HTMLImageElement path - use blob URL\n const blobUrl = URL.createObjectURL(blob);\n image.onload = () => {\n URL.revokeObjectURL(blobUrl);\n };\n image.onerror = () => {\n URL.revokeObjectURL(blobUrl);\n };\n image.src = blobUrl;\n }\n } catch (err) {\n // Don't emit correctionerror for tile fetch/processing errors - only for PMTiles failures (handled above)\n console.warn('[IndiaBoundaryCorrectedTileLayer] Tile fetch failed:', err);\n // Fall back to original tile\n const image = imageTile.getImage();\n if (typeof image.src !== 'undefined') {\n // HTMLImageElement - load original tile\n image.src = src;\n } else if (typeof image.dispatchEvent === 'function') {\n // OffscreenCanvas - can't fall back, signal error\n image.dispatchEvent(new Event('error'));\n }\n }\n };\n}\n\n/**\n * Extended OpenLayers TileLayer with India boundary corrections.\n * Extends ol/layer/Tile with a custom XYZ source that applies corrections.\n */\nexport class IndiaBoundaryCorrectedTileLayer extends TileLayer {\n /**\n * @param {Object} options - Layer options\n * @param {string} options.url - Tile URL template with {x}, {y}, {z} placeholders\n * @param {string} [options.pmtilesUrl] - URL to PMTiles file (defaults to CDN)\n * @param {Object|string} [options.layerConfig] - LayerConfig or config ID (auto-detected if not provided)\n * @param {Object[]} [options.extraLayerConfigs] - Additional LayerConfigs for matching\n * @param {number} [options.tileSize=256] - Tile size in pixels\n * @param {Object} [options.sourceOptions] - Additional options for XYZ source\n * @param {Object} [options.layerOptions] - Additional options for TileLayer\n */\n constructor(options) {\n const {\n url,\n pmtilesUrl,\n layerConfig,\n extraLayerConfigs,\n tileSize = 256,\n sourceOptions = {},\n ...layerOptions\n } = options;\n\n // Initialize registry and resolve layer config\n const registry = layerConfigs.createMergedRegistry(extraLayerConfigs);\n let resolvedConfig;\n \n if (typeof layerConfig === 'string') {\n resolvedConfig = registry.get(layerConfig);\n } else if (layerConfig) {\n resolvedConfig = layerConfig;\n } else {\n // Auto-detect from URL\n resolvedConfig = registry.detectFromTemplates([url]);\n }\n\n // Create TileFixer\n const tileFixer = new TileFixer(pmtilesUrl ?? getPmtilesUrl());\n\n // Create XYZ source (tileLoadFunction set after super() to access 'this')\n const source = new XYZ({\n url,\n tileSize,\n crossOrigin: 'anonymous',\n ...sourceOptions,\n });\n\n super({\n source,\n ...layerOptions\n });\n\n this._tileFixer = tileFixer;\n this._layerConfig = resolvedConfig;\n this._registry = registry;\n\n // Set tileLoadFunction after super() so we can pass 'this' for event dispatching\n if (resolvedConfig) {\n source.setTileLoadFunction(createCorrectedTileLoadFunction(tileFixer, resolvedConfig, tileSize, this));\n }\n\n if (!resolvedConfig) {\n console.warn('[IndiaBoundaryCorrectedTileLayer] Could not detect layer config from URL. Corrections will not be applied.');\n }\n }\n\n /**\n * Get the TileFixer instance.\n * @returns {TileFixer}\n */\n getTileFixer() {\n return this._tileFixer;\n }\n\n /**\n * Get the resolved LayerConfig.\n * @returns {Object|null}\n */\n getLayerConfig() {\n return this._layerConfig;\n }\n\n /**\n * Get the registry.\n * @returns {LayerConfigRegistry}\n */\n getRegistry() {\n return this._registry;\n }\n\n /**\n * Fetch and fix a tile (exposed for testing).\n * @param {string} src - Tile URL\n * @param {number} z - Zoom level\n * @param {number} x - Tile X coordinate\n * @param {number} y - Tile Y coordinate\n * @returns {Promise<{blob: Blob, wasFixed: boolean}>}\n * @private\n */\n async _fetchAndFixTile(src, z, x, y) {\n const tileSize = this.getSource().getTileGrid()?.getTileSize(z) || 256;\n return fetchAndFixTile(src, z, x, y, this._tileFixer, this._layerConfig, tileSize);\n }\n}\n\n// Export for testing\nexport { fetchAndFixTile };\n\n/**\n * Factory function to create an IndiaBoundaryCorrectedTileLayer.\n * @param {Object} options - Layer options (see IndiaBoundaryCorrectedTileLayer constructor)\n * @returns {IndiaBoundaryCorrectedTileLayer}\n */\nexport function indiaBoundaryCorrectedTileLayer(options) {\n return new IndiaBoundaryCorrectedTileLayer(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsB;AACtB,iBAAgB;AAChB,kBAA8B;AAC9B,2BAA6B;AAC7B,uBAA+C;AAG/C,IAAAA,wBAA0C;AAC1C,IAAAC,eAA8B;AAc9B,eAAe,g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AAW,gBAAgB,UAAU,IAAI,CAAC;AAAA,IACvG;AAEA,QAAI,CAAC,gBAAgB;AACnB,cAAQ,KAAK,4GAA4G;AAAA,IAC3H;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe;AACb,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,iBAAiB;AACf,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,iBAAiB,KAAK,GAAG,GAAG,GAAG;AACnC,UAAM,WAAW,KAAK,UAAU,EAAE,YAAY,GAAG,YAAY,CAAC,KAAK;AACnE,WAAO,gBAAgB,KAAK,GAAG,GAAG,GAAG,KAAK,YAAY,KAAK,cAAc,QAAQ;AAAA,EACnF;AACF;AAUO,SAAS,gCAAgC,SAAS;AACvD,SAAO,IAAI,gCAAgC,OAAO;AACpD;","names":["import_layer_configs","import_data","TileLayer","TileFixer","XYZ"]}
@@ -11154,17 +11154,23 @@ var IndiaBoundaryCorrector = (() => {
11154
11154
  var XYZ_default = XYZ;
11155
11155
 
11156
11156
  // ../data/version.js
11157
- var packageVersion = "0.0.1";
11157
+ var packageVersion = "0.0.2";
11158
11158
 
11159
11159
  // ../data/index.js
11160
11160
  var import_meta = {};
11161
11161
  var PACKAGE_NAME = "@india-boundary-corrector/data";
11162
11162
  var PMTILES_FILENAME = "india_boundary_corrections.pmtiles";
11163
11163
  var DEFAULT_CDN_URL = `https://unpkg.com/${PACKAGE_NAME}@${packageVersion}/${PMTILES_FILENAME}`;
11164
+ function shouldUseCdnFallback(hostname) {
11165
+ return hostname === "esm.sh";
11166
+ }
11164
11167
  function detectPmtilesUrl() {
11165
11168
  try {
11166
11169
  if (typeof import_meta !== "undefined" && import_meta.url) {
11167
11170
  const moduleUrl = new URL(".", import_meta.url);
11171
+ if (shouldUseCdnFallback(moduleUrl.hostname)) {
11172
+ return DEFAULT_CDN_URL;
11173
+ }
11168
11174
  return new URL(PMTILES_FILENAME, moduleUrl).href;
11169
11175
  }
11170
11176
  } catch {
@@ -13828,7 +13834,7 @@ var IndiaBoundaryCorrector = (() => {
13828
13834
  if (!maskCanvas || maskCanvas.width !== tileSize || maskCanvas.height !== tileSize) {
13829
13835
  maskCanvas = new OffscreenCanvas(tileSize, tileSize);
13830
13836
  }
13831
- const maskCtx = maskCanvas.getContext("2d");
13837
+ const maskCtx = maskCanvas.getContext("2d", { willReadFrequently: true });
13832
13838
  maskCtx.fillStyle = "black";
13833
13839
  maskCtx.fillRect(0, 0, tileSize, tileSize);
13834
13840
  maskCtx.strokeStyle = "white";
@@ -14030,8 +14036,11 @@ var IndiaBoundaryCorrector = (() => {
14030
14036
  const useOsm = zoom >= zoomThreshold;
14031
14037
  const addLayerName = useOsm ? "to-add-osm" : "to-add-ne";
14032
14038
  const delLayerName = useOsm ? "to-del-osm" : "to-del-ne";
14033
- const canvas = new OffscreenCanvas(tileSize, tileSize);
14034
- const ctx = canvas.getContext("2d");
14039
+ if (!this._canvas || this._canvas.width !== tileSize) {
14040
+ this._canvas = new OffscreenCanvas(tileSize, tileSize);
14041
+ }
14042
+ const canvas = this._canvas;
14043
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
14035
14044
  const blob = new Blob([rasterTile]);
14036
14045
  const imageBitmap = await createImageBitmap(blob);
14037
14046
  ctx.drawImage(imageBitmap, 0, 0, tileSize, tileSize);
@@ -14156,8 +14165,7 @@ var IndiaBoundaryCorrector = (() => {
14156
14165
  image.src = blobUrl;
14157
14166
  }
14158
14167
  } catch (err2) {
14159
- console.warn("[IndiaBoundaryCorrectedTileLayer] Error applying corrections, falling back to original:", err2);
14160
- layer.dispatchEvent({ type: "correctionerror", error: err2, coords: { z: z2, x: x3, y }, tileUrl: src });
14168
+ console.warn("[IndiaBoundaryCorrectedTileLayer] Tile fetch failed:", err2);
14161
14169
  const image = imageTile.getImage();
14162
14170
  if (typeof image.src !== "undefined") {
14163
14171
  image.src = src;