@naivemap/maplibre-gl-image-layer 0.0.1-alpha.0 → 0.0.1-alpha.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 ADDED
@@ -0,0 +1,11 @@
1
+ # @naivemap/maplibre-gl-image-layer
2
+
3
+ ImageLayer ([@naivemap/maplibre-gl-image-layer](https://www.npmjs.com/package/@naivemap/maplibre-gl-image-layer)): A versatile layer for displaying georeferenced images with **various projections** on the map. It supports loading and correctly positioning images from different coordinate systems, making it ideal for integrating non-standard raster data, historical maps, or aerial imagery.
4
+
5
+ [API References](https://www.naivemap.com/maplibre-gl-layers/api/image-layer/)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @naivemap/maplibre-gl-image-layer
11
+ ```
@@ -1,29 +1,107 @@
1
1
  import { default as maplibregl } from 'maplibre-gl';
2
2
  import { Coordinates } from './arrugator';
3
+ /**
4
+ * The properties for masking the image layer.
5
+ */
3
6
  export type MaskProperty = {
7
+ /**
8
+ * The type of mask to apply.
9
+ * - 'in': The mask is applied inside the polygon (default).
10
+ * - 'out': The mask is applied outside the polygon.
11
+ */
4
12
  type?: 'in' | 'out';
13
+ /**
14
+ * The data for the mask, which can be a GeoJSON Polygon or MultiPolygon.
15
+ * If not provided, no mask will be applied.
16
+ */
5
17
  data: GeoJSON.Polygon | GeoJSON.MultiPolygon;
6
18
  };
19
+ /**
20
+ * The options for the ImageLayer.
21
+ */
7
22
  export type ImageOption = {
23
+ /**
24
+ * URL that points to an image.
25
+ */
8
26
  url: string;
27
+ /**
28
+ * The projection of the image, typically an EPSG code like 'EPSG:4326'.
29
+ */
9
30
  projection: string;
31
+ /**
32
+ * Corners of image specified in longitude, latitude pairs.
33
+ */
10
34
  coordinates: Coordinates;
35
+ /**
36
+ * The resampling/interpolation method to use for overscaling.
37
+ * - 'linear': Linear interpolation (default).
38
+ * - 'nearest': Nearest neighbor interpolation.
39
+ * If not specified, the default is 'linear'.
40
+ */
11
41
  resampling?: 'linear' | 'nearest';
42
+ /**
43
+ * Opacity of the image layer, ranging from 0 (fully transparent) to 1 (fully opaque).
44
+ * Defaults to 1.
45
+ */
12
46
  opacity?: number;
47
+ /**
48
+ * Cross-origin attribute for the image, which can be used to specify how the image should be fetched.
49
+ * Defaults to 'anonymous'.
50
+ */
13
51
  crossOrigin?: string;
52
+ /**
53
+ * The step size for the Arrugator algorithm, which controls the granularity of the image rendering.
54
+ */
14
55
  arrugatorStep?: number;
56
+ /**
57
+ * Masking properties for the image layer.
58
+ * If not provided, no mask will be applied.
59
+ */
15
60
  mask?: MaskProperty;
16
- metadata?: any;
17
61
  };
18
62
  /**
19
- * ImageLayer is a custom layer for MapLibre GL that renders an image
20
- * with support for projection, coordinates, resampling, opacity, and masking.
63
+ * A custom MapLibre GL JS layer for rendering georeferenced images with arbitrary projections.
64
+ *
65
+ * @remarks
66
+ * This layer uses `proj4js` to transform image coordinates from any source projection
67
+ * into the map's coordinate system. It triangulates the image corners to correctly
68
+ * warp and display it on the map canvas. This is ideal for overlaying historical maps,
69
+ * floor plans, or other non-standard raster data.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import ImageLayer from '@naivemap/maplibre-gl-image-layer';
74
+ * import proj4 from 'proj4';
75
+ *
76
+ * // 1. Define the source projection if it's not standard
77
+ * proj4.defs('EPSG:2154', '+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs');
78
+ *
79
+ * // 2. Create the layer instance
80
+ * const layer = new ImageLayer('image-layer', {
81
+ * url: 'https://example.com/my-image.png',
82
+ * coordinates: [
83
+ * [100000, 6700000], // Top-left corner in source projection
84
+ * [110000, 6700000], // Top-right
85
+ * [110000, 6600000], // Bottom-right
86
+ * [100000, 6600000] // Bottom-left
87
+ * ],
88
+ * projection: 'EPSG:2154'
89
+ * });
90
+ *
91
+ * // 3. Add the layer to the map
92
+ * map.addLayer(layer);
93
+ * ```
21
94
  */
22
95
  export default class ImageLayer implements maplibregl.CustomLayerInterface {
23
96
  id: string;
97
+ /**
98
+ * @ignore
99
+ */
24
100
  type: 'custom';
101
+ /**
102
+ * @ignore
103
+ */
25
104
  renderingMode?: '2d' | '3d' | undefined;
26
- metadata?: any;
27
105
  private option;
28
106
  private map?;
29
107
  private gl?;
@@ -35,9 +113,22 @@ export default class ImageLayer implements maplibregl.CustomLayerInterface {
35
113
  private maskProperty;
36
114
  private maskProgramInfo?;
37
115
  private maskBufferInfo?;
116
+ /**
117
+ * @param id - A unique layer id
118
+ * @param option - ImageLayer options
119
+ */
38
120
  constructor(id: string, option: ImageOption);
121
+ /**
122
+ * @ignore
123
+ */
39
124
  onAdd(map: maplibregl.Map, gl: WebGLRenderingContext): void;
125
+ /**
126
+ * @ignore
127
+ */
40
128
  onRemove(_: maplibregl.Map, gl: WebGLRenderingContext): void;
129
+ /**
130
+ * @ignore
131
+ */
41
132
  render(gl: WebGLRenderingContext, args: any): void;
42
133
  /**
43
134
  * Updates the URL, the projection, the coordinates, the opacity or the resampling of the image.