@india-boundary-corrector/openlayers-layer 0.0.1
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 +153 -0
- package/dist/index.cjs +192 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.global.js +14261 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
- package/src/index.d.ts +48 -0
- package/src/index.js +215 -0
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @india-boundary-corrector/openlayers-layer
|
|
2
|
+
|
|
3
|
+
OpenLayers TileLayer extension that automatically applies India boundary corrections.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @india-boundary-corrector/openlayers-layer ol
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Script Tag (IIFE) - Simplest Setup
|
|
14
|
+
|
|
15
|
+
No bundler required! Just include the script and use the global `IndiaBoundaryCorrector`:
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@10.3.1/ol.css">
|
|
19
|
+
<script src="https://cdn.jsdelivr.net/npm/ol@10.3.1/dist/ol.js"></script>
|
|
20
|
+
<script src="https://unpkg.com/@india-boundary-corrector/openlayers-layer/dist/index.global.js"></script>
|
|
21
|
+
|
|
22
|
+
<div id="map" style="height: 400px;"></div>
|
|
23
|
+
|
|
24
|
+
<script>
|
|
25
|
+
const { IndiaBoundaryCorrectedTileLayer } = IndiaBoundaryCorrector;
|
|
26
|
+
|
|
27
|
+
const map = new ol.Map({
|
|
28
|
+
target: 'map',
|
|
29
|
+
layers: [
|
|
30
|
+
new IndiaBoundaryCorrectedTileLayer({
|
|
31
|
+
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
|
|
32
|
+
})
|
|
33
|
+
],
|
|
34
|
+
view: new ol.View({
|
|
35
|
+
center: ol.proj.fromLonLat([78.9629, 20.5937]),
|
|
36
|
+
zoom: 5
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### ES Modules
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import { Map, View } from 'ol';
|
|
46
|
+
import { fromLonLat } from 'ol/proj';
|
|
47
|
+
import { IndiaBoundaryCorrectedTileLayer } from '@india-boundary-corrector/openlayers-layer';
|
|
48
|
+
|
|
49
|
+
const map = new Map({
|
|
50
|
+
target: 'map',
|
|
51
|
+
layers: [
|
|
52
|
+
new IndiaBoundaryCorrectedTileLayer({
|
|
53
|
+
url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
|
54
|
+
})
|
|
55
|
+
],
|
|
56
|
+
view: new View({
|
|
57
|
+
center: fromLonLat([78.9629, 20.5937]),
|
|
58
|
+
zoom: 5
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### With Explicit Layer Config
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { IndiaBoundaryCorrectedTileLayer } from '@india-boundary-corrector/openlayers-layer';
|
|
67
|
+
|
|
68
|
+
const layer = new IndiaBoundaryCorrectedTileLayer({
|
|
69
|
+
url: 'https://{a-c}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
|
|
70
|
+
layerConfig: 'cartodb-dark'
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### With Custom Layer Config
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import { IndiaBoundaryCorrectedTileLayer, LayerConfig } from '@india-boundary-corrector/openlayers-layer';
|
|
78
|
+
|
|
79
|
+
const osmDeConfig = new LayerConfig({
|
|
80
|
+
id: 'osm-de',
|
|
81
|
+
tileUrlTemplates: ['https://tile.openstreetmap.de/{z}/{x}/{y}.png'],
|
|
82
|
+
lineWidthStops: { 1: 0.5, 2: 0.6, 3: 0.7, 4: 1.0, 10: 3.75 },
|
|
83
|
+
lineStyles: [
|
|
84
|
+
{ color: 'rgb(180, 200, 180)' },
|
|
85
|
+
{ color: 'rgb(121, 146, 127)', widthFraction: 1/3, dashArray: [30, 2, 8, 2] },
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const layer = new IndiaBoundaryCorrectedTileLayer({
|
|
90
|
+
url: 'https://tile.openstreetmap.de/{z}/{x}/{y}.png',
|
|
91
|
+
layerConfig: osmDeConfig
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Or use extraLayerConfigs for auto-detection
|
|
95
|
+
const layer2 = new IndiaBoundaryCorrectedTileLayer({
|
|
96
|
+
url: 'https://tile.openstreetmap.de/{z}/{x}/{y}.png',
|
|
97
|
+
extraLayerConfigs: [osmDeConfig]
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Factory Function
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
import { indiaBoundaryCorrectedTileLayer } from '@india-boundary-corrector/openlayers-layer';
|
|
105
|
+
|
|
106
|
+
const layer = indiaBoundaryCorrectedTileLayer({
|
|
107
|
+
url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Options
|
|
112
|
+
|
|
113
|
+
| Option | Type | Description |
|
|
114
|
+
|--------|------|-------------|
|
|
115
|
+
| `url` | string | Tile URL template with `{z}`, `{x}`, `{y}` placeholders |
|
|
116
|
+
| `pmtilesUrl` | string | URL to PMTiles file (auto-detected if not provided) |
|
|
117
|
+
| `layerConfig` | LayerConfig \| string | Layer config object or config ID |
|
|
118
|
+
| `extraLayerConfigs` | LayerConfig[] | Additional configs for auto-detection |
|
|
119
|
+
| `tileSize` | number | Tile size in pixels (default: 256) |
|
|
120
|
+
| `sourceOptions` | Object | Additional options passed to XYZ source |
|
|
121
|
+
| `...layerOptions` | Object | Additional options passed to TileLayer |
|
|
122
|
+
|
|
123
|
+
## Methods
|
|
124
|
+
|
|
125
|
+
| Method | Returns | Description |
|
|
126
|
+
|--------|---------|-------------|
|
|
127
|
+
| `getTileFixer()` | `TileFixer` | Get the underlying TileFixer instance |
|
|
128
|
+
| `getLayerConfig()` | `LayerConfig` | Get the resolved layer configuration |
|
|
129
|
+
| `getRegistry()` | `LayerConfigRegistry` | Get the layer config registry |
|
|
130
|
+
|
|
131
|
+
## Events
|
|
132
|
+
|
|
133
|
+
### `correctionerror`
|
|
134
|
+
|
|
135
|
+
Fired when the corrections data fails to load (e.g., PMTiles fetch failure). The tile will still display using the original uncorrected image.
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
layer.on('correctionerror', (e) => {
|
|
139
|
+
console.warn('Corrections unavailable:', e.error);
|
|
140
|
+
console.log('Tile coords:', e.coords); // { z, x, y }
|
|
141
|
+
console.log('Tile URL:', e.tileUrl);
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
| Property | Type | Description |
|
|
146
|
+
|----------|------|-------------|
|
|
147
|
+
| `error` | Error | The error that occurred |
|
|
148
|
+
| `coords` | object | Tile coordinates `{ z, x, y }` |
|
|
149
|
+
| `tileUrl` | string | URL of the tile being loaded |
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
Unlicense
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.js
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
IndiaBoundaryCorrectedTileLayer: () => IndiaBoundaryCorrectedTileLayer,
|
|
34
|
+
LayerConfig: () => import_layer_configs2.LayerConfig,
|
|
35
|
+
fetchAndFixTile: () => fetchAndFixTile,
|
|
36
|
+
getPmtilesUrl: () => import_data2.getPmtilesUrl,
|
|
37
|
+
indiaBoundaryCorrectedTileLayer: () => indiaBoundaryCorrectedTileLayer,
|
|
38
|
+
layerConfigs: () => import_layer_configs2.layerConfigs
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
var import_Tile = __toESM(require("ol/layer/Tile.js"), 1);
|
|
42
|
+
var import_XYZ = __toESM(require("ol/source/XYZ.js"), 1);
|
|
43
|
+
var import_data = require("@india-boundary-corrector/data");
|
|
44
|
+
var import_layer_configs = require("@india-boundary-corrector/layer-configs");
|
|
45
|
+
var import_tilefixer = require("@india-boundary-corrector/tilefixer");
|
|
46
|
+
var import_layer_configs2 = require("@india-boundary-corrector/layer-configs");
|
|
47
|
+
var import_data2 = require("@india-boundary-corrector/data");
|
|
48
|
+
async function fetchAndFixTile(src, z, x, y, tileFixer, layerConfig, tileSize) {
|
|
49
|
+
const { data, wasFixed, correctionsFailed, correctionsError } = await tileFixer.fetchAndFixTile(
|
|
50
|
+
src,
|
|
51
|
+
z,
|
|
52
|
+
x,
|
|
53
|
+
y,
|
|
54
|
+
layerConfig,
|
|
55
|
+
{ tileSize, mode: "cors" }
|
|
56
|
+
);
|
|
57
|
+
const blob = new Blob([data], { type: wasFixed ? "image/png" : void 0 });
|
|
58
|
+
return { blob, wasFixed, correctionsFailed, correctionsError };
|
|
59
|
+
}
|
|
60
|
+
function createCorrectedTileLoadFunction(tileFixer, layerConfig, tileSize, layer) {
|
|
61
|
+
return async function(imageTile, src) {
|
|
62
|
+
const tileCoord = imageTile.getTileCoord();
|
|
63
|
+
const z = tileCoord[0];
|
|
64
|
+
const x = tileCoord[1];
|
|
65
|
+
const y = tileCoord[2];
|
|
66
|
+
try {
|
|
67
|
+
const { blob, correctionsFailed, correctionsError } = await fetchAndFixTile(src, z, x, y, tileFixer, layerConfig, tileSize);
|
|
68
|
+
if (correctionsFailed) {
|
|
69
|
+
console.warn("[IndiaBoundaryCorrectedTileLayer] Corrections fetch failed:", correctionsError);
|
|
70
|
+
layer.dispatchEvent({ type: "correctionerror", error: correctionsError, coords: { z, x, y }, tileUrl: src });
|
|
71
|
+
}
|
|
72
|
+
const image = imageTile.getImage();
|
|
73
|
+
if (typeof image.getContext === "function") {
|
|
74
|
+
const imageBitmap = await createImageBitmap(blob);
|
|
75
|
+
image.width = imageBitmap.width;
|
|
76
|
+
image.height = imageBitmap.height;
|
|
77
|
+
const ctx = image.getContext("2d");
|
|
78
|
+
ctx.drawImage(imageBitmap, 0, 0);
|
|
79
|
+
imageBitmap.close?.();
|
|
80
|
+
image.dispatchEvent(new Event("load"));
|
|
81
|
+
} else {
|
|
82
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
83
|
+
image.onload = () => {
|
|
84
|
+
URL.revokeObjectURL(blobUrl);
|
|
85
|
+
};
|
|
86
|
+
image.onerror = () => {
|
|
87
|
+
URL.revokeObjectURL(blobUrl);
|
|
88
|
+
};
|
|
89
|
+
image.src = blobUrl;
|
|
90
|
+
}
|
|
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 });
|
|
94
|
+
const image = imageTile.getImage();
|
|
95
|
+
if (typeof image.src !== "undefined") {
|
|
96
|
+
image.src = src;
|
|
97
|
+
} else if (typeof image.dispatchEvent === "function") {
|
|
98
|
+
image.dispatchEvent(new Event("error"));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var IndiaBoundaryCorrectedTileLayer = class extends import_Tile.default {
|
|
104
|
+
/**
|
|
105
|
+
* @param {Object} options - Layer options
|
|
106
|
+
* @param {string} options.url - Tile URL template with {x}, {y}, {z} placeholders
|
|
107
|
+
* @param {string} [options.pmtilesUrl] - URL to PMTiles file (defaults to CDN)
|
|
108
|
+
* @param {Object|string} [options.layerConfig] - LayerConfig or config ID (auto-detected if not provided)
|
|
109
|
+
* @param {Object[]} [options.extraLayerConfigs] - Additional LayerConfigs for matching
|
|
110
|
+
* @param {number} [options.tileSize=256] - Tile size in pixels
|
|
111
|
+
* @param {Object} [options.sourceOptions] - Additional options for XYZ source
|
|
112
|
+
* @param {Object} [options.layerOptions] - Additional options for TileLayer
|
|
113
|
+
*/
|
|
114
|
+
constructor(options) {
|
|
115
|
+
const {
|
|
116
|
+
url,
|
|
117
|
+
pmtilesUrl,
|
|
118
|
+
layerConfig,
|
|
119
|
+
extraLayerConfigs,
|
|
120
|
+
tileSize = 256,
|
|
121
|
+
sourceOptions = {},
|
|
122
|
+
...layerOptions
|
|
123
|
+
} = options;
|
|
124
|
+
const registry = import_layer_configs.layerConfigs.createMergedRegistry(extraLayerConfigs);
|
|
125
|
+
let resolvedConfig;
|
|
126
|
+
if (typeof layerConfig === "string") {
|
|
127
|
+
resolvedConfig = registry.get(layerConfig);
|
|
128
|
+
} else if (layerConfig) {
|
|
129
|
+
resolvedConfig = layerConfig;
|
|
130
|
+
} else {
|
|
131
|
+
resolvedConfig = registry.detectFromTemplates([url]);
|
|
132
|
+
}
|
|
133
|
+
const tileFixer = new import_tilefixer.BoundaryCorrector(pmtilesUrl ?? (0, import_data.getPmtilesUrl)());
|
|
134
|
+
const source = new import_XYZ.default({
|
|
135
|
+
url,
|
|
136
|
+
tileSize,
|
|
137
|
+
crossOrigin: "anonymous",
|
|
138
|
+
...sourceOptions
|
|
139
|
+
});
|
|
140
|
+
super({
|
|
141
|
+
source,
|
|
142
|
+
...layerOptions
|
|
143
|
+
});
|
|
144
|
+
this._tileFixer = tileFixer;
|
|
145
|
+
this._layerConfig = resolvedConfig;
|
|
146
|
+
this._registry = registry;
|
|
147
|
+
if (resolvedConfig) {
|
|
148
|
+
source.setTileLoadFunction(createCorrectedTileLoadFunction(tileFixer, resolvedConfig, tileSize, this));
|
|
149
|
+
}
|
|
150
|
+
if (!resolvedConfig) {
|
|
151
|
+
console.warn("[IndiaBoundaryCorrectedTileLayer] Could not detect layer config from URL. Corrections will not be applied.");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the TileFixer instance.
|
|
156
|
+
* @returns {TileFixer}
|
|
157
|
+
*/
|
|
158
|
+
getTileFixer() {
|
|
159
|
+
return this._tileFixer;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the resolved LayerConfig.
|
|
163
|
+
* @returns {Object|null}
|
|
164
|
+
*/
|
|
165
|
+
getLayerConfig() {
|
|
166
|
+
return this._layerConfig;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get the registry.
|
|
170
|
+
* @returns {LayerConfigRegistry}
|
|
171
|
+
*/
|
|
172
|
+
getRegistry() {
|
|
173
|
+
return this._registry;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Fetch and fix a tile (exposed for testing).
|
|
177
|
+
* @param {string} src - Tile URL
|
|
178
|
+
* @param {number} z - Zoom level
|
|
179
|
+
* @param {number} x - Tile X coordinate
|
|
180
|
+
* @param {number} y - Tile Y coordinate
|
|
181
|
+
* @returns {Promise<{blob: Blob, wasFixed: boolean}>}
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
async _fetchAndFixTile(src, z, x, y) {
|
|
185
|
+
const tileSize = this.getSource().getTileGrid()?.getTileSize(z) || 256;
|
|
186
|
+
return fetchAndFixTile(src, z, x, y, this._tileFixer, this._layerConfig, tileSize);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
function indiaBoundaryCorrectedTileLayer(options) {
|
|
190
|
+
return new IndiaBoundaryCorrectedTileLayer(options);
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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,GAAG,EAAE,MAAM,WAAW,cAAc,OAAU,CAAC;AAC1E,SAAO,EAAE,MAAM,UAAU,mBAAmB,iBAAiB;AAC/D;AAUA,SAAS,gCAAgC,WAAW,aAAa,UAAU,OAAO;AAChF,SAAO,eAAe,WAAW,KAAK;AACpC,UAAM,YAAY,UAAU,aAAa;AACzC,UAAM,IAAI,UAAU,CAAC;AACrB,UAAM,IAAI,UAAU,CAAC;AACrB,UAAM,IAAI,UAAU,CAAC;AAMrB,QAAI;AACF,YAAM,EAAE,MAAM,mBAAmB,iBAAiB,IAAI,MAAM,gBAAgB,KAAK,GAAG,GAAG,GAAG,WAAW,aAAa,QAAQ;AAE1H,UAAI,mBAAmB;AACrB,gBAAQ,KAAK,+DAA+D,gBAAgB;AAC5F,cAAM,cAAc,EAAE,MAAM,mBAAmB,OAAO,kBAAkB,QAAQ,EAAE,GAAG,GAAG,EAAE,GAAG,SAAS,IAAI,CAAC;AAAA,MAC7G;AAEA,YAAM,QAAQ,UAAU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