@india-boundary-corrector/leaflet-layer 0.0.1 → 0.0.3

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/leaflet-layer
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@india-boundary-corrector/leaflet-layer)](https://www.npmjs.com/package/@india-boundary-corrector/leaflet-layer)
4
+
3
5
  Leaflet TileLayer extension that automatically applies India boundary corrections.
4
6
 
7
+ [Try it on JSFiddle](https://jsfiddle.net/z8d76em5/1/)
8
+
5
9
  ## Installation
6
10
 
7
11
  ```bash
@@ -26,7 +30,7 @@ No bundler required! Just include the script and use the global `IndiaBoundaryCo
26
30
  IndiaBoundaryCorrector.extendLeaflet(L);
27
31
 
28
32
  // Create map
29
- const map = L.map('map').setView([20.5937, 78.9629], 5);
33
+ const map = L.map('map').setView([33.2778, 75.3412], 5);
30
34
 
31
35
  // Use corrected tile layer - config auto-detected from URL
32
36
  L.tileLayer.indiaBoundaryCorrected('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@@ -45,7 +49,7 @@ import { extendLeaflet } from '@india-boundary-corrector/leaflet-layer';
45
49
  extendLeaflet(L);
46
50
 
47
51
  // Create map
48
- const map = L.map('map').setView([20.5937, 78.9629], 5);
52
+ const map = L.map('map').setView([33.2778, 75.3412], 5);
49
53
 
50
54
  // Use corrected tile layer - config auto-detected from URL
51
55
  L.tileLayer.indiaBoundaryCorrected('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@@ -61,12 +65,12 @@ import { extendLeaflet, layerConfigs } from '@india-boundary-corrector/leaflet-l
61
65
 
62
66
  extendLeaflet(L);
63
67
 
64
- const map = L.map('map').setView([20.5937, 78.9629], 5);
68
+ const map = L.map('map').setView([33.2778, 75.3412], 5);
65
69
 
66
70
  // Use a specific config by ID
67
71
  L.tileLayer.indiaBoundaryCorrected('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
68
72
  layerConfig: 'cartodb-dark',
69
- attribution: '© CartoDB © OpenStreetMap contributors'
73
+ attribution: '© CARTO © OpenStreetMap contributors'
70
74
  }).addTo(map);
71
75
  ```
72
76
 
@@ -78,7 +82,7 @@ import { extendLeaflet, LayerConfig } from '@india-boundary-corrector/leaflet-la
78
82
 
79
83
  extendLeaflet(L);
80
84
 
81
- const map = L.map('map').setView([20.5937, 78.9629], 5);
85
+ const map = L.map('map').setView([33.2778, 75.3412], 5);
82
86
 
83
87
  // Create custom config
84
88
  const osmDeConfig = new LayerConfig({
@@ -134,21 +138,6 @@ layer.on('correctionerror', (e) => {
134
138
  | `coords` | object | Tile coordinates `{ z, x, y }` |
135
139
  | `tileUrl` | string | URL of the tile being loaded |
136
140
 
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
141
  ## License
153
142
 
154
143
  Unlicense
package/dist/index.cjs CHANGED
@@ -139,10 +139,10 @@ function templateToTemplateRegex(template) {
139
139
  let pattern = template.replace(/[.*+?^${}()|[\]\\]/g, (char) => {
140
140
  if (char === "{" || char === "}") return char;
141
141
  return "\\" + char;
142
- }).replace(/^https:\/\//, "https?://").replace(/^http:\/\//, "https?://").replace(/\{([a-z0-9])-([a-z0-9])\}/gi, (_2, start, end) => `(\\{${start}-${end}\\}|[a-z0-9]+)`).replace(/\{(z|x|y|s|r)\}/gi, (_2, name) => {
142
+ }).replace(/^https:\/\//, "https?://").replace(/^http:\/\//, "https?://").replace(/\{([a-z0-9])-([a-z0-9])\}/gi, (_2, start, end) => `(\\{${start}-${end}\\}|\\{s\\}|[a-z0-9]+)`).replace(/\{(z|x|y|s|r)\}/gi, (_2, name) => {
143
143
  const lowerName = name.toLowerCase();
144
144
  if (lowerName === "s") {
145
- return "(\\{s\\}|[a-z0-9]+)";
145
+ return "(\\{s\\}|\\{[a-z0-9]-[a-z0-9]\\}|[a-z0-9]+)";
146
146
  }
147
147
  if (lowerName === "r") {
148
148
  return "(\\{r\\}|@\\d+x)?";
@@ -176,6 +176,9 @@ var LayerConfig = class _LayerConfig {
176
176
  if (!id || typeof id !== "string") {
177
177
  throw new Error("LayerConfig requires a non-empty string id");
178
178
  }
179
+ if (id.includes("/")) {
180
+ throw new Error(`LayerConfig id cannot contain slashes: "${id}"`);
181
+ }
179
182
  this.id = id;
180
183
  this.startZoom = startZoom;
181
184
  this.zoomThreshold = zoomThreshold;
@@ -2677,7 +2680,7 @@ function applyMedianBlurAlongPath(ctx, features, lineWidth, tileSize, maskCanvas
2677
2680
  if (!maskCanvas || maskCanvas.width !== tileSize || maskCanvas.height !== tileSize) {
2678
2681
  maskCanvas = new OffscreenCanvas(tileSize, tileSize);
2679
2682
  }
2680
- const maskCtx = maskCanvas.getContext("2d");
2683
+ const maskCtx = maskCanvas.getContext("2d", { willReadFrequently: true });
2681
2684
  maskCtx.fillStyle = "black";
2682
2685
  maskCtx.fillRect(0, 0, tileSize, tileSize);
2683
2686
  maskCtx.strokeStyle = "white";
@@ -2879,8 +2882,11 @@ var BoundaryCorrector = class {
2879
2882
  const useOsm = zoom >= zoomThreshold;
2880
2883
  const addLayerName = useOsm ? "to-add-osm" : "to-add-ne";
2881
2884
  const delLayerName = useOsm ? "to-del-osm" : "to-del-ne";
2882
- const canvas = new OffscreenCanvas(tileSize, tileSize);
2883
- const ctx = canvas.getContext("2d");
2885
+ if (!this._canvas || this._canvas.width !== tileSize) {
2886
+ this._canvas = new OffscreenCanvas(tileSize, tileSize);
2887
+ }
2888
+ const canvas = this._canvas;
2889
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
2884
2890
  const blob = new Blob([rasterTile]);
2885
2891
  const imageBitmap = await createImageBitmap(blob);
2886
2892
  ctx.drawImage(imageBitmap, 0, 0, tileSize, tileSize);