@india-boundary-corrector/tilefixer 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 +92 -0
- package/dist/index.cjs +2603 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2580 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
- package/src/corrections.js +280 -0
- package/src/index.d.ts +154 -0
- package/src/index.js +538 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @india-boundary-corrector/tilefixer
|
|
2
|
+
|
|
3
|
+
Core library for fetching and applying India boundary corrections to raster map tiles.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @india-boundary-corrector/tilefixer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import { BoundaryCorrector } from '@india-boundary-corrector/tilefixer';
|
|
15
|
+
import { getPmtilesUrl } from '@india-boundary-corrector/data';
|
|
16
|
+
import { layerConfigs } from '@india-boundary-corrector/layer-configs';
|
|
17
|
+
|
|
18
|
+
// Create a boundary corrector
|
|
19
|
+
const corrector = new BoundaryCorrector(getPmtilesUrl());
|
|
20
|
+
|
|
21
|
+
// Get corrections for a tile
|
|
22
|
+
const corrections = await corrector.getCorrections(z, x, y);
|
|
23
|
+
// Returns: { 'to-add-osm': [...], 'to-del-osm': [...], 'to-add-ne': [...], 'to-del-ne': [...] }
|
|
24
|
+
|
|
25
|
+
// Apply corrections to a raster tile
|
|
26
|
+
const layerConfig = layerConfigs.get('osm-carto');
|
|
27
|
+
const fixedTileData = await corrector.fixTile(
|
|
28
|
+
corrections,
|
|
29
|
+
originalTileArrayBuffer,
|
|
30
|
+
layerConfig,
|
|
31
|
+
z, // zoom level
|
|
32
|
+
256 // tile size (optional, defaults to 256)
|
|
33
|
+
);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
### `BoundaryCorrector`
|
|
39
|
+
|
|
40
|
+
#### Constructor
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
new BoundaryCorrector(pmtilesUrl, options?)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Parameter | Type | Description |
|
|
47
|
+
|-----------|------|-------------|
|
|
48
|
+
| `pmtilesUrl` | string | URL to the PMTiles file |
|
|
49
|
+
| `options.cacheSize` | number | Maximum tiles to cache (default: 64) |
|
|
50
|
+
|
|
51
|
+
#### Methods
|
|
52
|
+
|
|
53
|
+
| Method | Returns | Description |
|
|
54
|
+
|--------|---------|-------------|
|
|
55
|
+
| `getCorrections(z, x, y)` | `Promise<Object>` | Get correction features for a tile. Supports overzoom beyond zoom 14. |
|
|
56
|
+
| `fixTile(corrections, rasterTile, layerConfig, zoom, tileSize?)` | `Promise<ArrayBuffer>` | Apply corrections to a raster tile and return corrected PNG. |
|
|
57
|
+
| `fetchAndFixTile(tileUrl, z, x, y, layerConfig, options?)` | `Promise<Object>` | Fetch a tile, apply corrections, and return result. See below. |
|
|
58
|
+
| `getSource()` | `PMTiles` | Get the underlying PMTiles source object |
|
|
59
|
+
| `clearCache()` | `void` | Clear the tile cache |
|
|
60
|
+
|
|
61
|
+
#### `fetchAndFixTile` Options and Return Value
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
const result = await corrector.fetchAndFixTile(tileUrl, z, x, y, layerConfig, {
|
|
65
|
+
tileSize: 256, // Tile size in pixels (default: 256)
|
|
66
|
+
signal: abortSignal, // AbortSignal for cancellation
|
|
67
|
+
mode: 'cors', // Fetch mode
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// result: {
|
|
71
|
+
// data: ArrayBuffer, // The tile image data
|
|
72
|
+
// wasFixed: boolean, // Whether corrections were applied
|
|
73
|
+
// correctionsFailed: boolean, // Whether corrections fetch failed
|
|
74
|
+
// correctionsError: Error|null // The error if corrections failed
|
|
75
|
+
// }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## How It Works
|
|
79
|
+
|
|
80
|
+
1. **Fetching corrections**: The corrector fetches vector tile data from the PMTiles file containing boundary correction geometries.
|
|
81
|
+
|
|
82
|
+
2. **Overzoom support**: For zoom levels > 14 (max data zoom), parent tile data is fetched and transformed to the correct sub-tile quadrant.
|
|
83
|
+
|
|
84
|
+
3. **Applying corrections**:
|
|
85
|
+
- **Deletions**: Uses median blur along deletion paths to erase incorrect boundary lines
|
|
86
|
+
- **Additions**: Draws correct boundary lines with configurable colors and dash patterns
|
|
87
|
+
|
|
88
|
+
4. **Caching**: Parsed vector tiles are cached in an LRU cache to avoid repeated fetches.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
Unlicense
|