@neogis-auxiliary/maplibre 0.0.0-stage → 0.2.0-next.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.
@@ -0,0 +1,23 @@
1
+ import type { Map as LibreMap } from 'maplibre-gl';
2
+ import type { MapBounds, MapCamera, MapEnginePort } from '@neogis-auxiliary/core';
3
+ export { mapLibrePreset, mapLibreBoundsToMapBounds } from './preset.js';
4
+ /** MapLibre 的兼容构造入口,具体转换由配置驱动适配器执行。 */
5
+ export declare class MapLibreAdapter implements MapEnginePort {
6
+ private readonly adapter;
7
+ constructor(mapInstance: LibreMap);
8
+ getCamera(): MapCamera;
9
+ getBounds(): MapBounds;
10
+ getViewport(): {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ project(position: [number, number]): {
15
+ x: number;
16
+ y: number;
17
+ };
18
+ unproject(point: {
19
+ x: number;
20
+ y: number;
21
+ }): [number, number];
22
+ on(event: 'camera' | 'resize', listener: () => void): () => void;
23
+ }
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { createMapEngineAdapter } from '@neogis-auxiliary/adapters';
2
+ import { mapLibrePreset } from './preset.js';
3
+ export { mapLibrePreset, mapLibreBoundsToMapBounds } from './preset.js';
4
+ /** MapLibre 的兼容构造入口,具体转换由配置驱动适配器执行。 */
5
+ export class MapLibreAdapter {
6
+ adapter;
7
+ constructor(mapInstance) {
8
+ this.adapter = createMapEngineAdapter({
9
+ config: { version: 1, engine: 'maplibre' },
10
+ targets: { map: mapInstance },
11
+ presets: { maplibre: mapLibrePreset },
12
+ });
13
+ }
14
+ getCamera() { return this.adapter.getCamera(); }
15
+ getBounds() { return this.adapter.getBounds(); }
16
+ getViewport() { return this.adapter.getViewport(); }
17
+ project(position) { return this.adapter.project(position); }
18
+ unproject(point) { return this.adapter.unproject(point); }
19
+ on(event, listener) { return this.adapter.on(event, listener); }
20
+ }
@@ -0,0 +1,100 @@
1
+ import type { LngLatBounds } from 'maplibre-gl';
2
+ import type { MapBounds } from '@neogis-auxiliary/core';
3
+ /** 处理世界环绕与跨日期线范围,保持 MapLibre 的原始经度跨度。 */
4
+ export declare function mapLibreBoundsToMapBounds(bounds: Pick<LngLatBounds, 'getWest' | 'getEast' | 'getSouth' | 'getNorth'>): MapBounds;
5
+ /** 接入方注册已有地图为 map;创建预置时只编译规则。 */
6
+ export declare const mapLibrePreset: {
7
+ role: "engine";
8
+ config: {
9
+ getCamera: {
10
+ compose: {
11
+ center: {
12
+ call: string;
13
+ convert: {
14
+ type: string;
15
+ args: string[];
16
+ };
17
+ };
18
+ zoom: {
19
+ call: string;
20
+ convert: {
21
+ type: string;
22
+ };
23
+ };
24
+ bearing: {
25
+ call: string;
26
+ convert: {
27
+ type: string;
28
+ };
29
+ };
30
+ pitch: {
31
+ call: string;
32
+ convert: {
33
+ type: string;
34
+ };
35
+ };
36
+ };
37
+ convert: {
38
+ type: string;
39
+ };
40
+ };
41
+ getBounds: {
42
+ call: string;
43
+ convert: {
44
+ type: string;
45
+ };
46
+ };
47
+ getViewport: {
48
+ call: string;
49
+ convert: {
50
+ type: string;
51
+ args: {
52
+ width: string;
53
+ height: string;
54
+ }[];
55
+ };
56
+ };
57
+ project: {
58
+ call: string;
59
+ convert: {
60
+ type: string;
61
+ args: {
62
+ x: string;
63
+ y: string;
64
+ }[];
65
+ };
66
+ };
67
+ unproject: {
68
+ call: string;
69
+ args: {
70
+ convert: {
71
+ type: string;
72
+ args: string[];
73
+ };
74
+ }[];
75
+ convert: {
76
+ type: string;
77
+ args: string[];
78
+ };
79
+ };
80
+ events: {
81
+ camera: {
82
+ mode: string;
83
+ target: string;
84
+ subscribe: string;
85
+ unsubscribe: string;
86
+ event: string;
87
+ };
88
+ resize: {
89
+ mode: string;
90
+ target: string;
91
+ subscribe: string;
92
+ unsubscribe: string;
93
+ event: string;
94
+ };
95
+ };
96
+ };
97
+ converters: {
98
+ mapLibreBoundsToMapBounds: typeof mapLibreBoundsToMapBounds;
99
+ };
100
+ };
package/dist/preset.js ADDED
@@ -0,0 +1,59 @@
1
+ /** 处理世界环绕与跨日期线范围,保持 MapLibre 的原始经度跨度。 */
2
+ export function mapLibreBoundsToMapBounds(bounds) {
3
+ const rawWest = bounds.getWest();
4
+ const rawEast = bounds.getEast();
5
+ const fullWorld = rawEast - rawWest >= 360;
6
+ const normalize = (value) => ((value + 180) % 360 + 360) % 360 - 180;
7
+ const west = fullWorld ? -180 : normalize(rawWest);
8
+ const east = fullWorld ? 180 : normalize(rawEast);
9
+ return {
10
+ west,
11
+ east,
12
+ south: bounds.getSouth(),
13
+ north: bounds.getNorth(),
14
+ crossesAntimeridian: !fullWorld && west > east,
15
+ };
16
+ }
17
+ /** 接入方注册已有地图为 map;创建预置时只编译规则。 */
18
+ export const mapLibrePreset = {
19
+ role: 'engine',
20
+ config: {
21
+ getCamera: {
22
+ compose: {
23
+ center: {
24
+ call: 'map.getCenter',
25
+ convert: { type: 'createArray', args: ['$result.lng', '$result.lat'] },
26
+ },
27
+ zoom: { call: 'map.getZoom', convert: { type: 'identity' } },
28
+ bearing: { call: 'map.getBearing', convert: { type: 'identity' } },
29
+ pitch: { call: 'map.getPitch', convert: { type: 'identity' } },
30
+ },
31
+ convert: { type: 'identity' },
32
+ },
33
+ getBounds: {
34
+ call: 'map.getBounds',
35
+ convert: { type: 'mapLibreBoundsToMapBounds' },
36
+ },
37
+ getViewport: {
38
+ call: 'map.getCanvas',
39
+ convert: {
40
+ type: 'createObject',
41
+ args: [{ width: '$result.clientWidth', height: '$result.clientHeight' }],
42
+ },
43
+ },
44
+ project: {
45
+ call: 'map.project',
46
+ convert: { type: 'createObject', args: [{ x: '$result.x', y: '$result.y' }] },
47
+ },
48
+ unproject: {
49
+ call: 'map.unproject',
50
+ args: [{ convert: { type: 'createArray', args: ['$input.point.x', '$input.point.y'] } }],
51
+ convert: { type: 'createArray', args: ['$result.lng', '$result.lat'] },
52
+ },
53
+ events: {
54
+ camera: { mode: 'on-off', target: 'map', subscribe: 'on', unsubscribe: 'off', event: 'move' },
55
+ resize: { mode: 'on-off', target: 'map', subscribe: 'on', unsubscribe: 'off', event: 'resize' },
56
+ },
57
+ },
58
+ converters: { mapLibreBoundsToMapBounds },
59
+ };
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
- {
2
- "name": "@neogis-auxiliary/maplibre",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@neogis-auxiliary/maplibre",
3
+ "version": "0.2.0-next.0",
4
+ "publishConfig": {
5
+ "registry": "https://registry.npmjs.org/",
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "dependencies": {
19
+ "@neogis-auxiliary/core": "0.1.0",
20
+ "@neogis-auxiliary/adapters": "0.2.0-next.0"
21
+ },
22
+ "peerDependencies": {
23
+ "maplibre-gl": "^5.6.0"
24
+ }
25
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.