@naivemap/map-gl-layer-adaptor 0.1.0
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 +21 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +45 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(r){if(Array.isArray(r))return r;const a=r?.defaultProjectionData?.mainMatrix;if(a)return a;throw new Error("Unable to resolve projection matrix from render arguments.")}function d(r){const e=r?.painter;!e||e.terrain||(e.currentStencilSource=void 0,e._tileClippingMaskIDs={})}function i(r,e){let a;return{id:e.id,type:"custom",renderingMode:e.renderingMode??"2d",onAdd(t,n){a=t,r.onAdd(t,n)},onRemove(t,n){r.onRemove(t,n),a=void 0},render(t,n){if(!a)throw new Error("Layer adaptor render invoked before onAdd.");r.render({map:a,gl:t,matrix:(e.resolveMatrix??o)(n),rawArgs:n,prepareStencilMask:e.prepareStencilMask?()=>e.prepareStencilMask(a):void 0})}}}const c=i,p=i;exports.clearTileClippingMask=d;exports.createCustomLayerAdaptor=i;exports.createMapLibreLayerAdaptor=c;exports.createMapboxLayerAdaptor=p;exports.resolveLayerMatrix=o;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type LngLatTuple = [number, number];
|
|
2
|
+
export type Coordinates = [LngLatTuple, LngLatTuple, LngLatTuple, LngLatTuple];
|
|
3
|
+
export type ProjectionMatrix = number[] | Float32Array;
|
|
4
|
+
export interface ProjectedPoint {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
export interface GeoPoint {
|
|
9
|
+
lng: number;
|
|
10
|
+
lat: number;
|
|
11
|
+
}
|
|
12
|
+
export interface LayerMap {
|
|
13
|
+
project(lngLat: LngLatTuple): ProjectedPoint;
|
|
14
|
+
unproject(point: [number, number]): GeoPoint;
|
|
15
|
+
getCanvas(): HTMLCanvasElement;
|
|
16
|
+
getCanvasContainer(): HTMLElement;
|
|
17
|
+
isMoving(): boolean;
|
|
18
|
+
triggerRepaint(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface LayerRenderFrame<M extends LayerMap = LayerMap> {
|
|
21
|
+
map: M;
|
|
22
|
+
gl: WebGLRenderingContext;
|
|
23
|
+
matrix: ProjectionMatrix;
|
|
24
|
+
rawArgs: unknown;
|
|
25
|
+
prepareStencilMask?: () => void;
|
|
26
|
+
}
|
|
27
|
+
export interface LayerController<M extends LayerMap = LayerMap> {
|
|
28
|
+
onAdd(map: M, gl?: WebGLRenderingContext): void;
|
|
29
|
+
onRemove(map: M, gl?: WebGLRenderingContext): void;
|
|
30
|
+
render(frame: LayerRenderFrame<M>): void;
|
|
31
|
+
}
|
|
32
|
+
export interface CustomLayerAdaptorOptions<M extends LayerMap = LayerMap> {
|
|
33
|
+
id: string;
|
|
34
|
+
renderingMode?: '2d' | '3d';
|
|
35
|
+
resolveMatrix?: (args: unknown) => ProjectionMatrix;
|
|
36
|
+
prepareStencilMask?: (map: M) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface CustomLayerLike<M extends LayerMap = LayerMap> {
|
|
39
|
+
id: string;
|
|
40
|
+
type: 'custom';
|
|
41
|
+
renderingMode?: '2d' | '3d';
|
|
42
|
+
onAdd(map: M, gl: WebGLRenderingContext): void;
|
|
43
|
+
onRemove(map: M, gl: WebGLRenderingContext): void;
|
|
44
|
+
render(gl: WebGLRenderingContext, args: unknown): void;
|
|
45
|
+
}
|
|
46
|
+
export declare function resolveLayerMatrix(args: unknown): ProjectionMatrix;
|
|
47
|
+
export declare function clearTileClippingMask(map: {
|
|
48
|
+
painter?: any;
|
|
49
|
+
} | undefined): void;
|
|
50
|
+
export declare function createCustomLayerAdaptor<M extends LayerMap>(controller: LayerController<M>, options: CustomLayerAdaptorOptions<M>): CustomLayerLike<M>;
|
|
51
|
+
export declare const createMapLibreLayerAdaptor: typeof createCustomLayerAdaptor;
|
|
52
|
+
export declare const createMapboxLayerAdaptor: typeof createCustomLayerAdaptor;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function o(e) {
|
|
2
|
+
if (Array.isArray(e))
|
|
3
|
+
return e;
|
|
4
|
+
const t = e?.defaultProjectionData?.mainMatrix;
|
|
5
|
+
if (t)
|
|
6
|
+
return t;
|
|
7
|
+
throw new Error("Unable to resolve projection matrix from render arguments.");
|
|
8
|
+
}
|
|
9
|
+
function d(e) {
|
|
10
|
+
const r = e?.painter;
|
|
11
|
+
!r || r.terrain || (r.currentStencilSource = void 0, r._tileClippingMaskIDs = {});
|
|
12
|
+
}
|
|
13
|
+
function i(e, r) {
|
|
14
|
+
let t;
|
|
15
|
+
return {
|
|
16
|
+
id: r.id,
|
|
17
|
+
type: "custom",
|
|
18
|
+
renderingMode: r.renderingMode ?? "2d",
|
|
19
|
+
onAdd(n, a) {
|
|
20
|
+
t = n, e.onAdd(n, a);
|
|
21
|
+
},
|
|
22
|
+
onRemove(n, a) {
|
|
23
|
+
e.onRemove(n, a), t = void 0;
|
|
24
|
+
},
|
|
25
|
+
render(n, a) {
|
|
26
|
+
if (!t)
|
|
27
|
+
throw new Error("Layer adaptor render invoked before onAdd.");
|
|
28
|
+
e.render({
|
|
29
|
+
map: t,
|
|
30
|
+
gl: n,
|
|
31
|
+
matrix: (r.resolveMatrix ?? o)(a),
|
|
32
|
+
rawArgs: a,
|
|
33
|
+
prepareStencilMask: r.prepareStencilMask ? () => r.prepareStencilMask(t) : void 0
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const c = i, p = i;
|
|
39
|
+
export {
|
|
40
|
+
d as clearTileClippingMask,
|
|
41
|
+
i as createCustomLayerAdaptor,
|
|
42
|
+
c as createMapLibreLayerAdaptor,
|
|
43
|
+
p as createMapboxLayerAdaptor,
|
|
44
|
+
o as resolveLayerMatrix
|
|
45
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@naivemap/map-gl-layer-adaptor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Framework-agnostic adaptor primitives for MapLibre GL JS and Mapbox GL JS custom layers.",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"maplibre",
|
|
20
|
+
"mapbox",
|
|
21
|
+
"custom",
|
|
22
|
+
"layer",
|
|
23
|
+
"adaptor"
|
|
24
|
+
],
|
|
25
|
+
"author": "naivemap",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"repository": "https://github.com/naivemap/maplibre-gl-layers",
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "vite build",
|
|
35
|
+
"typedocs": "typedoc"
|
|
36
|
+
}
|
|
37
|
+
}
|