@india-boundary-corrector/leaflet-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 ADDED
@@ -0,0 +1,154 @@
1
+ # @india-boundary-corrector/leaflet-layer
2
+
3
+ Leaflet TileLayer extension that automatically applies India boundary corrections.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @india-boundary-corrector/leaflet-layer leaflet
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://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
19
+ <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
20
+ <script src="https://unpkg.com/@india-boundary-corrector/leaflet-layer/dist/index.global.js"></script>
21
+
22
+ <div id="map" style="height: 400px;"></div>
23
+
24
+ <script>
25
+ // Extend Leaflet with corrected tile layer
26
+ IndiaBoundaryCorrector.extendLeaflet(L);
27
+
28
+ // Create map
29
+ const map = L.map('map').setView([20.5937, 78.9629], 5);
30
+
31
+ // Use corrected tile layer - config auto-detected from URL
32
+ L.tileLayer.indiaBoundaryCorrected('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
33
+ attribution: '© OpenStreetMap contributors'
34
+ }).addTo(map);
35
+ </script>
36
+ ```
37
+
38
+ ### ES Modules
39
+
40
+ ```javascript
41
+ import L from 'leaflet';
42
+ import { extendLeaflet } from '@india-boundary-corrector/leaflet-layer';
43
+
44
+ // Extend Leaflet with corrected tile layer
45
+ extendLeaflet(L);
46
+
47
+ // Create map
48
+ const map = L.map('map').setView([20.5937, 78.9629], 5);
49
+
50
+ // Use corrected tile layer - config auto-detected from URL
51
+ L.tileLayer.indiaBoundaryCorrected('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
52
+ attribution: '© OpenStreetMap contributors'
53
+ }).addTo(map);
54
+ ```
55
+
56
+ ### With Explicit Layer Config
57
+
58
+ ```javascript
59
+ import L from 'leaflet';
60
+ import { extendLeaflet, layerConfigs } from '@india-boundary-corrector/leaflet-layer';
61
+
62
+ extendLeaflet(L);
63
+
64
+ const map = L.map('map').setView([20.5937, 78.9629], 5);
65
+
66
+ // Use a specific config by ID
67
+ L.tileLayer.indiaBoundaryCorrected('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
68
+ layerConfig: 'cartodb-dark',
69
+ attribution: '© CartoDB © OpenStreetMap contributors'
70
+ }).addTo(map);
71
+ ```
72
+
73
+ ### With Custom Layer Config
74
+
75
+ ```javascript
76
+ import L from 'leaflet';
77
+ import { extendLeaflet, LayerConfig } from '@india-boundary-corrector/leaflet-layer';
78
+
79
+ extendLeaflet(L);
80
+
81
+ const map = L.map('map').setView([20.5937, 78.9629], 5);
82
+
83
+ // Create custom config
84
+ const osmDeConfig = new LayerConfig({
85
+ id: 'osm-de',
86
+ tileUrlTemplates: ['https://tile.openstreetmap.de/{z}/{x}/{y}.png'],
87
+ lineWidthStops: { 1: 0.5, 2: 0.6, 3: 0.7, 4: 1.0, 10: 3.75 },
88
+ lineStyles: [
89
+ { color: 'rgb(180, 200, 180)' },
90
+ { color: 'rgb(121, 146, 127)', widthFraction: 1/3, dashArray: [30, 2, 8, 2] },
91
+ ],
92
+ });
93
+
94
+ // Pass as layerConfig option
95
+ L.tileLayer.indiaBoundaryCorrected('https://tile.openstreetmap.de/{z}/{x}/{y}.png', {
96
+ layerConfig: osmDeConfig,
97
+ attribution: '© OpenStreetMap contributors'
98
+ }).addTo(map);
99
+
100
+ // Or register with extraLayerConfigs for auto-detection
101
+ L.tileLayer.indiaBoundaryCorrected('https://tile.openstreetmap.de/{z}/{x}/{y}.png', {
102
+ extraLayerConfigs: [osmDeConfig],
103
+ attribution: '© OpenStreetMap contributors'
104
+ }).addTo(map);
105
+ ```
106
+
107
+ ## Options
108
+
109
+ All standard `L.TileLayer` options are supported, plus:
110
+
111
+ | Option | Type | Description |
112
+ |--------|------|-------------|
113
+ | `pmtilesUrl` | string | URL to PMTiles file (auto-detected if not provided) |
114
+ | `layerConfig` | LayerConfig \| string | Layer config object or config ID |
115
+ | `extraLayerConfigs` | LayerConfig[] | Additional configs for auto-detection |
116
+
117
+ ## Events
118
+
119
+ ### `correctionerror`
120
+
121
+ Fired when the corrections data fails to load (e.g., PMTiles fetch failure). The tile will still display using the original uncorrected image.
122
+
123
+ ```javascript
124
+ layer.on('correctionerror', (e) => {
125
+ console.warn('Corrections unavailable:', e.error);
126
+ console.log('Tile coords:', e.coords); // { z, x, y }
127
+ console.log('Tile URL:', e.tileUrl);
128
+ });
129
+ ```
130
+
131
+ | Property | Type | Description |
132
+ |----------|------|-------------|
133
+ | `error` | Error | The error that occurred |
134
+ | `coords` | object | Tile coordinates `{ z, x, y }` |
135
+ | `tileUrl` | string | URL of the tile being loaded |
136
+
137
+ ## Global Auto-extension
138
+
139
+ If Leaflet is available as a global `L` object, the extension is applied automatically on import:
140
+
141
+ ```html
142
+ <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
143
+ <script type="module">
144
+ import '@india-boundary-corrector/leaflet-layer';
145
+
146
+ // L.TileLayer.IndiaBoundaryCorrected is now available
147
+ const map = L.map('map').setView([20.5937, 78.9629], 5);
148
+ L.tileLayer.indiaBoundaryCorrected('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
149
+ </script>
150
+ ```
151
+
152
+ ## License
153
+
154
+ Unlicense