@naivemap/maplibre-gl-image-layer 0.1.0 → 0.2.0-alpha.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Naive Map
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Naive Map
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +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 proj4
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/map-gl-layers/api/image-layer/)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @naivemap/maplibre-gl-image-layer proj4
11
+ ```
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { default as ImageLayer } from './ImageLayer';
2
- export type { ImageLayerOption } from './ImageLayer';
3
- export default ImageLayer;
4
- export type { MaskProperty } from './mask';
1
+ export * from './maplibre-gl-image-layer/src/index'
2
+ export {}
3
+ import ImageLayer from './maplibre-gl-image-layer/src/index'
4
+ export default ImageLayer
5
+ export * from './maplibre-gl-image-layer/src/index'
6
+ export {}
@@ -0,0 +1,61 @@
1
+ import t from "@naivemap/image-layer-core";
2
+ import { createMapLibreLayerAdaptor as o, clearTileClippingMask as d } from "@naivemap/map-gl-layer-adaptor";
3
+ class n {
4
+ id;
5
+ /**
6
+ * @ignore
7
+ */
8
+ type = "custom";
9
+ /**
10
+ * @ignore
11
+ */
12
+ renderingMode = "2d";
13
+ core;
14
+ adaptor;
15
+ /**
16
+ * @param id - A unique layer id
17
+ * @param option - ImageLayer options
18
+ */
19
+ constructor(e, r) {
20
+ this.id = e, this.core = new t(r), this.adaptor = o(this.core, {
21
+ id: e,
22
+ renderingMode: this.renderingMode,
23
+ prepareStencilMask: (a) => d(a)
24
+ });
25
+ }
26
+ /**
27
+ * @ignore
28
+ */
29
+ onAdd(e, r) {
30
+ this.adaptor.onAdd(e, r);
31
+ }
32
+ /**
33
+ * @ignore
34
+ */
35
+ onRemove(e, r) {
36
+ this.adaptor.onRemove(e, r);
37
+ }
38
+ /**
39
+ * @ignore
40
+ */
41
+ render(e, r) {
42
+ this.adaptor.render(e, r);
43
+ }
44
+ /**
45
+ * Updates the URL, the projection, the coordinates, the opacity or the resampling of the image.
46
+ * @param {Object} option Options object.
47
+ */
48
+ updateImage(e) {
49
+ return this.core.updateImage(e);
50
+ }
51
+ /**
52
+ * Updates the mask property of the image layer.
53
+ * @param mask
54
+ */
55
+ updateMask(e) {
56
+ return this.core.updateMask(e);
57
+ }
58
+ }
59
+ export {
60
+ n as default
61
+ };
@@ -0,0 +1 @@
1
+ (function(r,t){typeof exports=="object"&&typeof module<"u"?module.exports=t(require("@naivemap/image-layer-core"),require("@naivemap/map-gl-layer-adaptor")):typeof define=="function"&&define.amd?define(["@naivemap/image-layer-core","@naivemap/map-gl-layer-adaptor"],t):(r=typeof globalThis<"u"?globalThis:r||self,r.ImageLayer=t(r.ImageLayerCore,r.mapGlLayerAdaptor))})(this,function(r,t){"use strict";class i{id;type="custom";renderingMode="2d";core;adaptor;constructor(e,a){this.id=e,this.core=new r(a),this.adaptor=t.createMapLibreLayerAdaptor(this.core,{id:e,renderingMode:this.renderingMode,prepareStencilMask:d=>t.clearTileClippingMask(d)})}onAdd(e,a){this.adaptor.onAdd(e,a)}onRemove(e,a){this.adaptor.onRemove(e,a)}render(e,a){this.adaptor.render(e,a)}updateImage(e){return this.core.updateImage(e)}updateMask(e){return this.core.updateMask(e)}}return i});
@@ -0,0 +1,76 @@
1
+ import { default as ImageLayerCore, ImageLayerOption, MaskProperty } from '@naivemap/image-layer-core';
2
+ import { CustomLayerInterface, Map } from 'maplibre-gl';
3
+ export type { ImageLayerOption } from '@naivemap/image-layer-core';
4
+ /**
5
+ * A custom MapLibre GL JS layer for rendering georeferenced images with arbitrary projections.
6
+ *
7
+ * @remarks
8
+ * This layer uses `proj4js` to transform image coordinates from any source projection
9
+ * into the map's coordinate system. It triangulates the image corners to correctly
10
+ * warp and display it on the map canvas. This is ideal for overlaying historical maps,
11
+ * floor plans, or other non-standard raster data.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import ImageLayer from '@naivemap/maplibre-gl-image-layer';
16
+ * import proj4 from 'proj4';
17
+ *
18
+ * // 1. Define the source projection if it's not standard
19
+ * 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');
20
+ *
21
+ * // 2. Create the layer instance
22
+ * const layer = new ImageLayer('image-layer', {
23
+ * url: 'https://example.com/my-image.png',
24
+ * coordinates: [
25
+ * [100000, 6700000], // Top-left corner in source projection
26
+ * [110000, 6700000], // Top-right
27
+ * [110000, 6600000], // Bottom-right
28
+ * [100000, 6600000] // Bottom-left
29
+ * ],
30
+ * projection: 'EPSG:2154'
31
+ * });
32
+ *
33
+ * // 3. Add the layer to the map
34
+ * map.addLayer(layer);
35
+ * ```
36
+ */
37
+ export default class ImageLayer implements CustomLayerInterface {
38
+ id: string;
39
+ /**
40
+ * @ignore
41
+ */
42
+ type: 'custom';
43
+ /**
44
+ * @ignore
45
+ */
46
+ renderingMode?: '2d' | '3d' | undefined;
47
+ private core;
48
+ private adaptor;
49
+ /**
50
+ * @param id - A unique layer id
51
+ * @param option - ImageLayer options
52
+ */
53
+ constructor(id: string, option: ImageLayerOption);
54
+ /**
55
+ * @ignore
56
+ */
57
+ onAdd(map: Map, gl: WebGLRenderingContext): void;
58
+ /**
59
+ * @ignore
60
+ */
61
+ onRemove(map: Map, gl: WebGLRenderingContext): void;
62
+ /**
63
+ * @ignore
64
+ */
65
+ render(gl: WebGLRenderingContext, args: unknown): void;
66
+ /**
67
+ * Updates the URL, the projection, the coordinates, the opacity or the resampling of the image.
68
+ * @param {Object} option Options object.
69
+ */
70
+ updateImage(option: Partial<Omit<ImageLayerOption, 'mask'>>): ImageLayerCore;
71
+ /**
72
+ * Updates the mask property of the image layer.
73
+ * @param mask
74
+ */
75
+ updateMask(mask: Partial<MaskProperty>): ImageLayerCore;
76
+ }
@@ -0,0 +1,4 @@
1
+ import { default as ImageLayer } from './ImageLayer';
2
+ export type { ImageLayerOption } from '@naivemap/image-layer-core';
3
+ export default ImageLayer;
4
+ export type { MaskProperty } from '@naivemap/image-layer-core';
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@naivemap/maplibre-gl-image-layer",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-alpha.1",
4
4
  "description": "Load a static image of any projection via Arrugator and Proj4js.",
5
- "main": "./dist/index.umd.cjs",
6
- "module": "./dist/index.js",
5
+ "main": "./dist/index.umd.js",
6
+ "module": "./dist/index.es.js",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/index.js",
11
- "require": "./dist/index.umd.cjs"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.es.js",
12
+ "require": "./dist/index.umd.js"
12
13
  }
13
14
  },
14
15
  "files": [
@@ -27,18 +28,16 @@
27
28
  "publishConfig": {
28
29
  "access": "public"
29
30
  },
31
+ "sideEffects": false,
30
32
  "peerDependencies": {
31
33
  "maplibre-gl": "^4.0.0 || ^5.0.0",
32
34
  "proj4": "^2.8.0"
33
35
  },
34
36
  "dependencies": {
35
- "@types/geojson": "^7946.0.16",
36
- "earcut": "^3.0.1",
37
- "tinyqueue": "^3.0.0",
38
- "twgl.js": "^5.5.4"
37
+ "@naivemap/image-layer-core": "0.2.0-alpha.0",
38
+ "@naivemap/map-gl-layer-adaptor": "0.2.0-alpha.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/earcut": "^2.1.1",
42
41
  "@types/proj4": "^2.5.2"
43
42
  },
44
43
  "scripts": {
@@ -1,130 +0,0 @@
1
- import { default as maplibregl } from 'maplibre-gl';
2
- import { MaskProperty } from './mask';
3
- /**
4
- * The options for the ImageLayer.
5
- */
6
- export type ImageLayerOption = {
7
- /**
8
- * URL that points to an image.
9
- */
10
- url: string;
11
- /**
12
- * The projection of the image, typically an EPSG code like 'EPSG:4326'.
13
- */
14
- projection: string;
15
- /**
16
- * Corners of image specified in longitude, latitude pairs.
17
- */
18
- coordinates: maplibregl.Coordinates;
19
- /**
20
- * The resampling/interpolation method to use for overscaling.
21
- * - 'linear': Linear interpolation (default).
22
- * - 'nearest': Nearest neighbor interpolation.
23
- * If not specified, the default is 'linear'.
24
- */
25
- resampling?: 'linear' | 'nearest';
26
- /**
27
- * Opacity of the image layer, ranging from 0 (fully transparent) to 1 (fully opaque).
28
- * Defaults to 1.
29
- */
30
- opacity?: number;
31
- /**
32
- * Cross-origin attribute for the image, which can be used to specify how the image should be fetched.
33
- * Defaults to 'anonymous'.
34
- */
35
- crossOrigin?: string;
36
- /**
37
- * The step size for the Arrugator algorithm, which controls the granularity of the image rendering.
38
- */
39
- arrugatorStep?: number;
40
- /**
41
- * Masking properties for the image layer.
42
- * If not provided, no mask will be applied.
43
- */
44
- mask?: MaskProperty;
45
- };
46
- /**
47
- * A custom MapLibre GL JS layer for rendering georeferenced images with arbitrary projections.
48
- *
49
- * @remarks
50
- * This layer uses `proj4js` to transform image coordinates from any source projection
51
- * into the map's coordinate system. It triangulates the image corners to correctly
52
- * warp and display it on the map canvas. This is ideal for overlaying historical maps,
53
- * floor plans, or other non-standard raster data.
54
- *
55
- * @example
56
- * ```ts
57
- * import ImageLayer from '@naivemap/maplibre-gl-image-layer';
58
- * import proj4 from 'proj4';
59
- *
60
- * // 1. Define the source projection if it's not standard
61
- * 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');
62
- *
63
- * // 2. Create the layer instance
64
- * const layer = new ImageLayer('image-layer', {
65
- * url: 'https://example.com/my-image.png',
66
- * coordinates: [
67
- * [100000, 6700000], // Top-left corner in source projection
68
- * [110000, 6700000], // Top-right
69
- * [110000, 6600000], // Bottom-right
70
- * [100000, 6600000] // Bottom-left
71
- * ],
72
- * projection: 'EPSG:2154'
73
- * });
74
- *
75
- * // 3. Add the layer to the map
76
- * map.addLayer(layer);
77
- * ```
78
- */
79
- export default class ImageLayer implements maplibregl.CustomLayerInterface {
80
- id: string;
81
- /**
82
- * @ignore
83
- */
84
- type: 'custom';
85
- /**
86
- * @ignore
87
- */
88
- renderingMode?: '2d' | '3d' | undefined;
89
- private option;
90
- private map?;
91
- private gl?;
92
- private loaded;
93
- private arrugado;
94
- private programInfo?;
95
- private bufferInfo?;
96
- private texture?;
97
- private maskProperty;
98
- private maskProgramInfo?;
99
- private maskBufferInfo?;
100
- /**
101
- * @param id - A unique layer id
102
- * @param option - ImageLayer options
103
- */
104
- constructor(id: string, option: ImageLayerOption);
105
- /**
106
- * @ignore
107
- */
108
- onAdd(map: maplibregl.Map, gl: WebGLRenderingContext): void;
109
- /**
110
- * @ignore
111
- */
112
- onRemove(_: maplibregl.Map, gl: WebGLRenderingContext): void;
113
- /**
114
- * @ignore
115
- */
116
- render(gl: WebGLRenderingContext, args: any): void;
117
- /**
118
- * Updates the URL, the projection, the coordinates, the opacity or the resampling of the image.
119
- * @param {Object} option Options object.
120
- */
121
- updateImage(option: Partial<Omit<ImageLayerOption, 'mask'>>): this;
122
- /**
123
- * Updates the mask property of the image layer.
124
- * @param mask
125
- * @returns
126
- */
127
- updateMask(mask: Partial<MaskProperty>): this;
128
- private loadTexture;
129
- private getMaskBufferInfo;
130
- }
@@ -1,18 +0,0 @@
1
- export default class Arrugator {
2
- constructor(projector: any, verts: any, uv: any, trigs: any);
3
- _segment(v1: any, v2: any, t: any, maxEpsilon?: number): any;
4
- output(): {
5
- unprojected: unknown[];
6
- projected: unknown[];
7
- uv: unknown[];
8
- trigs: unknown[];
9
- };
10
- private _stepsWithSameEpsilon;
11
- lowerEpsilon(targetEpsilon: any): void;
12
- get epsilon(): any;
13
- set epsilon(ep: any);
14
- step(): void;
15
- force(): void;
16
- private _splitSegment;
17
- private _splitTriangle;
18
- }
@@ -1,6 +0,0 @@
1
- export type ArrugadoFlat = {
2
- pos: number[];
3
- uv: number[];
4
- trigs: number[];
5
- };
6
- export declare function initArrugator(fromProj: string, coordinates: maplibregl.Coordinates, step?: number): ArrugadoFlat;