@stampgis/webrtc 1.0.1 → 1.0.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 +95 -48
- package/dist/index.cjs +12334 -4921
- package/dist/index.d.mts +8475 -1263
- package/dist/index.d.ts +8475 -1263
- package/dist/index.js +12334 -4921
- package/dist-cli/cli.js +220 -0
- package/package.json +28 -4
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
# @stampgis/webrtc
|
|
2
2
|
|
|
3
|
-
StampGIS
|
|
4
|
-
|
|
3
|
+
StampGIS 三维地图 WebRTC(像素流)开发 SDK,对底层工具类、核心脚本加载与全局配置做模块化封装。
|
|
4
|
+
|
|
5
|
+
解决传统「多 `<script>` 标签按序引入 + 全局变量污染 + 无法通过 ES Module 导入」的痛点,开箱即用,支持按需加载、动态资源注入,适配 Vite / Webpack / CDN 多种接入方式。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 核心脚本(config / pixelstreaming / playerControl)已内置在 npm 包 `assets/` 目录,无需手动复制文件
|
|
10
|
+
- 提供 `loadCore()` 动态加载、`initMap()` 一键初始化,自动处理脚本依赖顺序与全局变量就绪等待
|
|
11
|
+
- 内置 `StampUtil` 接口库,提供 500+ 个地图操作方法(量算、图层管理、标绘标注、空间分析、视角控制等)
|
|
12
|
+
- ES Module(`import`)与 CommonJS(`require`)双格式,附带完整 TypeScript 类型声明
|
|
13
|
+
|
|
14
|
+
## 环境要求
|
|
15
|
+
|
|
16
|
+
- **浏览器环境**:依赖 `window` / `document`,不支持 Node / SSR
|
|
17
|
+
- 使用 `useBundledAssets` 时需 Vite 或 Webpack 5+(依赖 `import.meta.url` 解析静态资源)
|
|
18
|
+
- 使用 `baseUrl` 或精确 URL 方式加载时,对打包器无特殊要求
|
|
5
19
|
|
|
6
20
|
## 安装
|
|
7
21
|
|
|
@@ -16,36 +30,25 @@ pnpm add @stampgis/webrtc
|
|
|
16
30
|
### 1. HTML 中准备容器
|
|
17
31
|
|
|
18
32
|
```html
|
|
19
|
-
<div id="earth" style="width: 100vw;height: 100vh;"></div>
|
|
33
|
+
<div id="earth" style="width: 100vw; height: 100vh;"></div>
|
|
20
34
|
```
|
|
21
35
|
|
|
22
|
-
> SDK
|
|
36
|
+
> SDK 初始化时会自动补全 `width: 100%`、`overflow: hidden`、`position: absolute` 等样式,**容器高度需自行设置**(如 `height: 100vh` 或 flex 布局)。
|
|
23
37
|
|
|
24
38
|
### 2. 加载核心脚本 + 初始化地球
|
|
25
39
|
|
|
26
|
-
#### 方式一:从包内 assets 加载(Vite 推荐)
|
|
27
|
-
|
|
28
|
-
脚本已内置在 npm 包中,无需手动复制任何文件:
|
|
29
|
-
|
|
30
40
|
```ts
|
|
31
41
|
import { loadCore, initMap } from "@stampgis/webrtc";
|
|
32
42
|
|
|
43
|
+
// 从包内 assets 加载核心脚本(可选:不调用时 initMap 内部会自动加载)
|
|
33
44
|
await loadCore({ useBundledAssets: true });
|
|
34
45
|
|
|
35
|
-
initMap({
|
|
36
|
-
container: "earth",
|
|
46
|
+
await initMap({
|
|
47
|
+
container: "earth", // 必填,支持 id 或 HTMLElement
|
|
37
48
|
mapIndex: 0,
|
|
38
49
|
});
|
|
39
50
|
```
|
|
40
51
|
|
|
41
|
-
#### 方式二:从服务器/CDN 加载
|
|
42
|
-
|
|
43
|
-
将 `config/` 和 `core/` 目录部署到服务器或 `public/` 目录:
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
await loadCore({ baseUrl: "/gis/" });
|
|
47
|
-
```
|
|
48
|
-
|
|
49
52
|
### 3. 使用 StampUtil 接口
|
|
50
53
|
|
|
51
54
|
```ts
|
|
@@ -60,44 +63,88 @@ const guid = StampUtil.createGuid();
|
|
|
60
63
|
console.log(guid);
|
|
61
64
|
```
|
|
62
65
|
|
|
66
|
+
## 核心脚本加载
|
|
67
|
+
|
|
68
|
+
三个核心脚本按依赖顺序加载:`stamp_core_config.js` → `pixelstreaming.js` → `playerControl.js`,最终在 `window` 上注册 `StampAPI` 全局对象。
|
|
69
|
+
|
|
70
|
+
`loadCore(options)` 支持四种加载方式:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { loadCore } from "@stampgis/webrtc";
|
|
74
|
+
|
|
75
|
+
// 方式一:从包内 assets 加载(推荐,无需手动复制文件)
|
|
76
|
+
await loadCore({ useBundledAssets: true });
|
|
77
|
+
|
|
78
|
+
// 方式二:从服务器 / CDN 加载(自动拼接固定相对路径)
|
|
79
|
+
await loadCore({ baseUrl: "/gis/" });
|
|
80
|
+
|
|
81
|
+
// 方式三:精确指定每个脚本 URL
|
|
82
|
+
await loadCore({
|
|
83
|
+
configUrl: "https://cdn.example.com/config/stamp_core_config.js",
|
|
84
|
+
pixelstreamingUrl: "https://cdn.example.com/core/pixelstreaming.js",
|
|
85
|
+
playerControlUrl: "https://cdn.example.com/core/playerControl.js",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 方式四:通过打包器 import 获取包内 assets 的 URL(最大灵活性)
|
|
89
|
+
import configUrl from "@stampgis/webrtc/assets/config/stamp_core_config.js";
|
|
90
|
+
import pixelstreamingUrl from "@stampgis/webrtc/assets/core/pixelstreaming.js";
|
|
91
|
+
import playerControlUrl from "@stampgis/webrtc/assets/core/playerControl.js";
|
|
92
|
+
await loadCore({ configUrl, pixelstreamingUrl, playerControlUrl });
|
|
93
|
+
```
|
|
94
|
+
|
|
63
95
|
## API
|
|
64
96
|
|
|
65
|
-
### `loadCore(options
|
|
97
|
+
### `loadCore(options?: CoreLoadOptions): Promise<void>`
|
|
98
|
+
|
|
99
|
+
动态加载三个核心脚本,按依赖顺序执行,并等待对应全局变量就绪。
|
|
100
|
+
|
|
101
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
102
|
+
| ------------------- | --------- | ---- | ----------------------------------------------------------- |
|
|
103
|
+
| `useBundledAssets` | `boolean` | 否 | 从包内 `assets/` 目录加载脚本,默认 `false` |
|
|
104
|
+
| `baseUrl` | `string` | 否 | 基础路径,自动拼接 `config/stamp_core_config.js` 等相对路径 |
|
|
105
|
+
| `configUrl` | `string` | 否 | 精确指定 `stamp_core_config.js` 的 URL |
|
|
106
|
+
| `pixelstreamingUrl` | `string` | 否 | 精确指定 `pixelstreaming.js` 的 URL |
|
|
107
|
+
| `playerControlUrl` | `string` | 否 | 精确指定 `playerControl.js` 的 URL |
|
|
108
|
+
| `match_maker` | `string` | 否 | 覆盖 `stamp_core_config` 中的 matchmaker 地址 |
|
|
109
|
+
| `timeout` | `number` | 否 | 超时毫秒数,默认 `30000` |
|
|
110
|
+
|
|
111
|
+
> 三种 URL 来源的优先级:显式 URL(`configUrl` 等)> `useBundledAssets` > `baseUrl` 拼接。
|
|
66
112
|
|
|
67
|
-
|
|
113
|
+
### `initMap(options: InitMapOptions): Promise<unknown>`
|
|
68
114
|
|
|
69
|
-
|
|
70
|
-
| ------------------- | -------- | --------------------------------------------------- |
|
|
71
|
-
| `baseUrl` | `string` | 基础路径,自动拼接 `config/stamp_core_config.js` 等 |
|
|
72
|
-
| `configUrl` | `string` | 精确指定 stamp_core_config.js 的 URL |
|
|
73
|
-
| `pixelstreamingUrl` | `string` | 精确指定 pixelstreaming.js 的 URL |
|
|
74
|
-
| `playerControlUrl` | `string` | 精确指定 playerControl.js 的 URL |
|
|
75
|
-
| `match_maker` | `string` | 覆盖 stamp_core_config 中的matchmaker地址 |
|
|
76
|
-
| `timeout` | `number` | 超时毫秒数,默认 30000 |
|
|
115
|
+
初始化地图渲染。若核心脚本尚未加载(`window.StampAPI` 不存在),会自动调用 `loadCore()`。`errorContainer` 不传则内部自动创建。
|
|
77
116
|
|
|
78
|
-
|
|
117
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
118
|
+
| ---------------- | ----------------------- | ---- | ----------------------------------------------- |
|
|
119
|
+
| `container` | `string \| HTMLElement` | 是 | 地球容器,支持 DOM 元素或元素 id |
|
|
120
|
+
| `errorContainer` | `string \| HTMLElement` | 否 | 错误提示容器,不传则内部自动创建 |
|
|
121
|
+
| `mapIndex` | `number` | 否 | 屏幕索引(0=主屏、1=副屏1、2=副屏2),默认 `0` |
|
|
122
|
+
| `showTips` | `boolean` | 否 | 是否显示提示,默认 `true` |
|
|
123
|
+
| `coreOptions` | `CoreLoadOptions` | 否 | 核心脚本加载配置,默认 `useBundledAssets: true` |
|
|
79
124
|
|
|
80
|
-
|
|
125
|
+
### `StampUtil`(默认导出 / 命名导出)
|
|
81
126
|
|
|
82
|
-
|
|
83
|
-
| ---------------- | ----------------------- | ----------------------------------------------- |
|
|
84
|
-
| `container` | `string \| HTMLElement` | 地球容器,支持 DOM 元素或元素 id |
|
|
85
|
-
| `errorContainer` | `string \| HTMLElement` | 错误提示容器(可选),不传则内部自动创建 |
|
|
86
|
-
| `mapIndex` | `number` | 屏幕索引 0/1/2,默认 0 |
|
|
87
|
-
| `showTips` | `boolean` | 是否显示提示,默认 true |
|
|
88
|
-
| `coreOptions` | `CoreLoadOptions` | 核心脚本加载配置(可选,默认 useBundledAssets) |
|
|
127
|
+
内置接口库,提供 500+ 个地图操作方法,覆盖:
|
|
89
128
|
|
|
90
|
-
|
|
129
|
+
- **量算**:水平距离、面积、高度等
|
|
130
|
+
- **图层管理**:DEM / DOM / BIM / 倾斜摄影 / 点云 / 矢量瓦片等多种图层类型
|
|
131
|
+
- **标绘标注**:点 / 线 / 面 / 体 / 图标 / 模型等
|
|
132
|
+
- **空间分析**:通视、坡度、剖面等
|
|
133
|
+
- **视角控制**:飞行定位、视点获取等
|
|
134
|
+
- **工具函数**:GUID 生成、坐标转换、文件保存等
|
|
91
135
|
|
|
92
|
-
|
|
136
|
+
通过 IDE 的 TypeScript 类型提示可查看完整方法列表与参数签名。
|
|
93
137
|
|
|
94
138
|
### 其他导出
|
|
95
139
|
|
|
96
|
-
| 导出
|
|
97
|
-
|
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
140
|
+
| 导出 | 说明 |
|
|
141
|
+
| ------------------------------------------- | ----------------------------------------- |
|
|
142
|
+
| `StampUtil` | 接口库(命名导出) |
|
|
143
|
+
| `STAMP_RTTI` | 图层 / 标绘对象 / 视角等类型常量枚举 |
|
|
144
|
+
| `ASSET_PATHS` | 包内 `assets/` 脚本路径常量 |
|
|
145
|
+
| `loadScript(url)` | 动态加载单个脚本(同 URL 自动去重) |
|
|
146
|
+
| `waitForGlobal(name, timeout?, interval?)` | 等待全局变量就绪,默认超时 10s |
|
|
147
|
+
| `CoreLoadOptions` / `InitMapOptions` 等类型 | 完整 TypeScript 类型定义(`import type`) |
|
|
101
148
|
|
|
102
149
|
## 代理配置(必读)
|
|
103
150
|
|
|
@@ -109,10 +156,10 @@ console.log(guid);
|
|
|
109
156
|
// vite.config.ts
|
|
110
157
|
server: {
|
|
111
158
|
proxy: {
|
|
112
|
-
|
|
113
|
-
target:
|
|
159
|
+
"/matchmaker": {
|
|
160
|
+
target: "http://<推流服务器IP>:30080",
|
|
114
161
|
changeOrigin: true,
|
|
115
|
-
rewrite: (path) => path.replace(/^\/matchmaker/,
|
|
162
|
+
rewrite: (path) => path.replace(/^\/matchmaker/, ""),
|
|
116
163
|
},
|
|
117
164
|
},
|
|
118
165
|
}
|
|
@@ -128,7 +175,7 @@ location /matchmaker/ {
|
|
|
128
175
|
|
|
129
176
|
### 不想配代理?
|
|
130
177
|
|
|
131
|
-
|
|
178
|
+
若 matchmaker 服务端开启了 CORS,可通过 `match_maker` 参数直连:
|
|
132
179
|
|
|
133
180
|
```ts
|
|
134
181
|
await initMap({
|