@xingm/vmap-cesium-toolbar 0.0.6 → 1.0.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.
Files changed (133) hide show
  1. package/README.md +126 -230
  2. package/dist/README.md +172 -0
  3. package/dist/adapters/DrawHelperAdapter.d.ts +143 -0
  4. package/dist/adapters/MapLoaderAdapter.d.ts +44 -0
  5. package/dist/adapters/OverlayServiceAdapter.d.ts +102 -0
  6. package/dist/adapters/ToolbarAdapter.d.ts +71 -0
  7. package/dist/adapters/index.d.ts +23 -0
  8. package/dist/components/BaseComponent.d.ts +116 -0
  9. package/dist/components/SearchBox.d.ts +136 -0
  10. package/dist/components/Toolbar.d.ts +115 -0
  11. package/dist/components/ToolbarButton.d.ts +100 -0
  12. package/dist/components/index.d.ts +33 -0
  13. package/dist/core/MapPlugin.d.ts +164 -0
  14. package/dist/core/constants.d.ts +88 -0
  15. package/dist/core/entities/BaseOverlay.d.ts +156 -0
  16. package/dist/core/entities/Circle.d.ts +102 -0
  17. package/dist/core/entities/Icon.d.ts +86 -0
  18. package/dist/core/entities/InfoWindow.d.ts +116 -0
  19. package/dist/core/entities/Label.d.ts +92 -0
  20. package/dist/core/entities/Marker.d.ts +66 -0
  21. package/dist/core/entities/Polygon.d.ts +93 -0
  22. package/dist/core/entities/Polyline.d.ts +72 -0
  23. package/dist/core/entities/Rectangle.d.ts +99 -0
  24. package/dist/core/entities/Ring.d.ts +114 -0
  25. package/dist/core/entities/SVG.d.ts +89 -0
  26. package/dist/core/entities/index.d.ts +27 -0
  27. package/dist/core/index.d.ts +25 -0
  28. package/dist/core/layers/BaiduMapLayer.d.ts +37 -0
  29. package/dist/core/layers/CustomMapLayer.d.ts +43 -0
  30. package/dist/core/layers/GaodeMapLayer.d.ts +41 -0
  31. package/dist/core/layers/HeatmapLayer.d.ts +118 -0
  32. package/dist/core/layers/MapLayer.d.ts +37 -0
  33. package/dist/core/layers/OSMMapLayer.d.ts +37 -0
  34. package/dist/core/layers/PointClusterLayer.d.ts +119 -0
  35. package/dist/core/layers/TDTMapLayer.d.ts +61 -0
  36. package/dist/core/layers/index.d.ts +16 -0
  37. package/dist/core/services/draw/DrawInteractionController.d.ts +16 -0
  38. package/dist/core/services/draw/DrawService.d.ts +38 -0
  39. package/dist/core/services/draw/DrawSessionStore.d.ts +28 -0
  40. package/dist/core/services/draw/drawDefaults.d.ts +16 -0
  41. package/dist/core/services/draw/entities/drawEntityFactory.d.ts +10 -0
  42. package/dist/core/services/draw/entities/drawEntityRegistry.d.ts +8 -0
  43. package/dist/core/services/draw/entities/drawFinalFactory.d.ts +14 -0
  44. package/dist/core/services/draw/entities/drawPreviewFactory.d.ts +15 -0
  45. package/dist/core/services/draw/geometry/drawGeometry.d.ts +11 -0
  46. package/dist/core/services/draw/geometry/drawPosition.d.ts +6 -0
  47. package/dist/core/services/draw/index.d.ts +7 -0
  48. package/dist/core/services/draw/labels/drawHint.d.ts +16 -0
  49. package/dist/core/services/draw/labels/measurementCanvas.d.ts +8 -0
  50. package/dist/core/services/draw/labels/measurementLabelFactory.d.ts +18 -0
  51. package/dist/core/services/draw/measurementThemeResolver.d.ts +9 -0
  52. package/dist/core/services/draw/types/drawState.d.ts +37 -0
  53. package/dist/core/services/draw/types/drawTypes.d.ts +97 -0
  54. package/dist/core/services/index.d.ts +10 -0
  55. package/dist/core/services/overlay/OverlayService.d.ts +188 -0
  56. package/dist/core/services/overlay/index.d.ts +7 -0
  57. package/dist/core/services/toolbar/ToolbarService.d.ts +175 -0
  58. package/dist/core/services/toolbar/buttons/BaseButtonHandler.d.ts +111 -0
  59. package/dist/core/services/toolbar/buttons/LayersButtonHandler.d.ts +47 -0
  60. package/dist/core/services/toolbar/buttons/MeasureButtonHandler.d.ts +94 -0
  61. package/dist/core/services/toolbar/buttons/SearchButtonHandler.d.ts +111 -0
  62. package/dist/core/services/toolbar/buttons/SimpleButtonHandler.d.ts +79 -0
  63. package/dist/core/services/toolbar/config.d.ts +7 -0
  64. package/dist/core/services/toolbar/index.d.ts +30 -0
  65. package/dist/core/services/toolbar/menus/BaseMenu.d.ts +99 -0
  66. package/dist/core/services/toolbar/menus/MeasureMenu.d.ts +44 -0
  67. package/dist/core/services/toolbar/types.d.ts +198 -0
  68. package/dist/core/types.d.ts +592 -0
  69. package/dist/i18n/en-US.d.ts +47 -0
  70. package/dist/i18n/index.d.ts +45 -2
  71. package/dist/i18n/zh-CN.d.ts +47 -0
  72. package/dist/index.d.ts +37 -42
  73. package/dist/index.es.js +6952 -9670
  74. package/dist/index.es.js.map +1 -1
  75. package/dist/libs/CesiumMapModel.d.ts +1 -172
  76. package/dist/libs/CesiumMapToolbar.d.ts +1 -1
  77. package/dist/libs/CesiumOverlayService.d.ts +9 -222
  78. package/dist/libs/config/CesiumMapConfig.d.ts +5 -12
  79. package/dist/libs/drawHelper/DrawHint.d.ts +15 -27
  80. package/dist/libs/drawHelper/index.d.ts +67 -6
  81. package/dist/libs/toolBar/CesiumMapController.d.ts +38 -64
  82. package/dist/libs/toolBar/MapLayersService.d.ts +10 -61
  83. package/dist/libs/toolBar/MapSearchService.d.ts +8 -29
  84. package/dist/libs/toolBar/MapToolBarConfig.d.ts +33 -5
  85. package/dist/libs/toolBar/MeasurementService.d.ts +13 -5
  86. package/dist/libs/toolBar/NotFlyZonesService.d.ts +6 -41
  87. package/dist/package.json +20 -6
  88. package/dist/styles/ComponentStyles.d.ts +82 -0
  89. package/dist/styles/StyleManager.d.ts +142 -0
  90. package/dist/styles/index.d.ts +128 -0
  91. package/dist/utils/common.d.ts +4 -0
  92. package/package.json +79 -73
  93. package/dist/hooks/toolBarConfig.d.ts +0 -75
  94. package/dist/hooks/useDrawHelper.d.ts +0 -24
  95. package/dist/hooks/useDynamicRing.d.ts +0 -44
  96. package/dist/hooks/useHeatmapHelper.d.ts +0 -18
  97. package/dist/hooks/useMap.d.ts +0 -14
  98. package/dist/hooks/useMapInit.d.ts +0 -14
  99. package/dist/hooks/useOverlayHelper.d.ts +0 -48
  100. package/dist/hooks/usePointClusterHelper.d.ts +0 -14
  101. package/dist/index.umd.js +0 -326
  102. package/dist/index.umd.js.map +0 -1
  103. package/dist/libs/drawHelper/BaseDraw.d.ts +0 -194
  104. package/dist/libs/drawHelper/DrawCircle.d.ts +0 -31
  105. package/dist/libs/drawHelper/DrawLine.d.ts +0 -49
  106. package/dist/libs/drawHelper/DrawPolgon.d.ts +0 -35
  107. package/dist/libs/drawHelper/DrawRectangle.d.ts +0 -24
  108. package/dist/libs/i18n/en-US.d.ts +0 -69
  109. package/dist/libs/i18n/index.d.ts +0 -25
  110. package/dist/libs/i18n/zh-CN.d.ts +0 -69
  111. package/dist/libs/overlay/MapCircle.d.ts +0 -130
  112. package/dist/libs/overlay/MapIcon.d.ts +0 -69
  113. package/dist/libs/overlay/MapInfoWindow.d.ts +0 -100
  114. package/dist/libs/overlay/MapLabel.d.ts +0 -73
  115. package/dist/libs/overlay/MapMarker.d.ts +0 -60
  116. package/dist/libs/overlay/MapPolygon.d.ts +0 -114
  117. package/dist/libs/overlay/MapPolyline.d.ts +0 -64
  118. package/dist/libs/overlay/MapRectangle.d.ts +0 -101
  119. package/dist/libs/overlay/MapRing.d.ts +0 -107
  120. package/dist/libs/overlay/MapSVG.d.ts +0 -73
  121. package/dist/libs/overlay/OverlayEditController.d.ts +0 -167
  122. package/dist/libs/overlay/OverlayEditHandles.d.ts +0 -101
  123. package/dist/libs/overlay/OverlayHighlight.d.ts +0 -40
  124. package/dist/libs/overlay/index.d.ts +0 -23
  125. package/dist/libs/overlay/primitives/CirclePrimitiveBatch.d.ts +0 -42
  126. package/dist/libs/overlay/primitives/CirclePrimitiveLayerStack.d.ts +0 -24
  127. package/dist/libs/overlay/primitives/PolygonPrimitiveBatch.d.ts +0 -43
  128. package/dist/libs/overlay/primitives/PolygonPrimitiveLayerStack.d.ts +0 -24
  129. package/dist/libs/overlay/primitives/RectanglePrimitiveBatch.d.ts +0 -41
  130. package/dist/libs/overlay/primitives/RectanglePrimitiveLayerStack.d.ts +0 -24
  131. package/dist/libs/overlay/types.d.ts +0 -121
  132. package/dist/z.const.d.ts +0 -24
  133. /package/dist/{libs → utils}/PickGovernor.d.ts +0 -0
package/README.md CHANGED
@@ -1,17 +1,6 @@
1
1
  # @xingm/vmap-cesium-toolbar
2
2
 
3
- 一个功能强大的 Cesium 地图工具栏组件,提供搜索、测量、绘制、2D/3D切换、图层管理等功能。
4
-
5
- ## 特性
6
-
7
- - 🗺️ **完整的地图工具栏** - 搜索、测量、绘制、图层切换等功能
8
- - 📏 **精确测量工具** - 支持距离、面积、高度测量
9
- - ✏️ **绘制功能** - 支持点、线、面绘制和编辑
10
- - 🔄 **2D/3D切换** - 无缝切换2D和3D视图模式
11
- - 🎨 **可定制样式** - 支持自定义按钮样式和布局
12
- - 📱 **响应式设计** - 适配不同屏幕尺寸
13
- - 🚀 **TypeScript支持** - 完整的类型定义
14
- - ⚡ **Vue 3兼容** - 原生支持Vue 3项目
3
+ 一个以 MapPlugin 为中心的 Cesium 地图工具库,重构后将 Viewer 生命周期、工具栏、覆盖物和绘制能力统一收敛到插件内核与服务层,并保留一层兼容适配器用于平滑迁移旧 API。
15
4
 
16
5
  ## 安装
17
6
 
@@ -19,258 +8,165 @@
19
8
  npm install @xingm/vmap-cesium-toolbar cesium
20
9
  ```
21
10
 
22
- ## 快速开始
23
-
24
- ### 基本使用
25
-
26
- ```javascript
27
- import { CesiumMapToolbar, initCesium } from '@xingm/vmap-cesium-toolbar';
28
- import '@xingm/vmap-cesium-toolbar/style';
29
-
30
- // 初始化Cesium
31
- (async () => {
32
- const { viewer } = await initCesium('cesiumContainer', {
33
- terrainProvider: Cesium.createWorldTerrain(),
34
- });
35
-
36
- // 创建工具栏
37
- const toolbar = new CesiumMapToolbar(viewer, document.getElementById('toolbar'));
38
- })();
39
- ```
40
-
41
- ### Vue 3 项目中使用
42
-
43
- ```vue
44
- <template>
45
- <div id="cesiumContainer"></div>
46
- <div id="toolbar"></div>
47
- </template>
48
-
49
- <script setup>
50
- import { onMounted } from 'vue';
51
- import { CesiumMapToolbar, initCesium } from '@xingm/vmap-cesium-toolbar';
52
- import '@xingm/vmap-cesium-toolbar/style';
53
-
54
- let viewer;
55
- let toolbar;
56
-
57
- onMounted(async () => {
58
- // 初始化Cesium
59
- const result = await initCesium('cesiumContainer', {
60
- terrainProvider: Cesium.createWorldTerrain(),
61
- });
62
- viewer = result.viewer;
63
-
64
- // 创建工具栏
65
- toolbar = new CesiumMapToolbar(viewer, document.getElementById('toolbar'));
11
+ ## 推荐入口
12
+
13
+ 新项目只推荐使用 createMapPlugin、MapPlugin 和服务层 API。
14
+
15
+ ```ts
16
+ import { createMapPlugin } from '@xingm/vmap-cesium-toolbar';
17
+
18
+ const mapPlugin = createMapPlugin('cesiumContainer', {
19
+ cesiumToken: 'your-cesium-ion-token',
20
+ camera: {
21
+ center: [116.3974, 39.9093, 1000],
22
+ pitch: -45,
23
+ heading: 0,
24
+ },
25
+ layers: {
26
+ type: 'tdt',
27
+ tdt: {
28
+ mapTypeId: 'img',
29
+ token: 'your-tianditu-token',
30
+ showLabel: true,
31
+ },
32
+ },
33
+ viewerOptions: {
34
+ animation: false,
35
+ timeline: false,
36
+ navigationHelpButton: false,
37
+ },
38
+ services: {
39
+ overlay: true,
40
+ draw: true,
41
+ toolbar: {
42
+ enabled: true,
43
+ callbacks: {
44
+ onSearch: async () => [],
45
+ },
46
+ },
47
+ },
66
48
  });
67
- </script>
68
- ```
69
-
70
- ## 主要组件
71
49
 
72
- ### CesiumMapToolbar
50
+ const viewer = await mapPlugin.initialize();
51
+ const toolbarService = mapPlugin.getToolbarService();
52
+ const overlayService = mapPlugin.getOverlayService();
53
+ const drawService = mapPlugin.getDrawService();
73
54
 
74
- 主要工具栏组件,提供完整的地图操作功能。
55
+ drawService.startDrawing('polygon');
75
56
 
76
- ```typescript
77
- const toolbar = new CesiumMapToolbar(
78
- viewer, // Cesium Viewer实例
79
- container, // 工具栏容器元素
80
- config, // 配置选项(可选)
81
- callbacks, // 回调函数(可选)
82
- initialCenter // 初始中心点(可选)
83
- );
57
+ mapPlugin.updateLayers({
58
+ type: 'tdt',
59
+ tdt: {
60
+ mapTypeId: 'vec',
61
+ token: 'your-tianditu-token',
62
+ showLabel: true,
63
+ },
64
+ });
84
65
  ```
85
66
 
86
- ### DrawHelper
67
+ ## 重构后的公开层次
87
68
 
88
- 绘制工具类(包的默认导出),提供线/面/矩形/圆等交互绘制能力。
69
+ ### 1. 新 API
89
70
 
90
- ```typescript
91
- import DrawHelper from '@xingm/vmap-cesium-toolbar';
71
+ - createMapPlugin
72
+ - MapPlugin
73
+ - ToolbarService
74
+ - OverlayService
75
+ - DrawService
76
+ - Marker、Label、Icon、SVG、InfoWindow、Polyline、Polygon、Rectangle、Circle、Ring
77
+ - HeatmapLayer、PointClusterLayer
92
78
 
93
- const drawHelper = new DrawHelper(viewer);
94
- drawHelper.startDrawingPolygon();
95
- ```
79
+ ### 2. 类型与样式能力
96
80
 
97
- ### initCesium
81
+ - MapPluginOptions、ToolbarConfig、LayersConfig 等统一从顶层导出
82
+ - i18n 与样式系统继续保留顶层导出,供组件与业务侧接入
98
83
 
99
- Cesium 初始化函数,简化 Viewer 创建、底图/地形与初始视角配置。
84
+ ### 3. 兼容 API
100
85
 
101
- ```typescript
102
- import { initCesium } from '@xingm/vmap-cesium-toolbar';
103
-
104
- const { viewer } = await initCesium('cesiumContainer', {
105
- cesiumToken: 'your_cesium_ion_token',
106
- });
107
-
108
- // 使用天地图时可指定底图类型(默认 imagery)
109
- const { viewer: tdtViewer } = await initCesium('cesiumContainer', {
110
- mapType: 'tiandi',
111
- tdtMapTypeId: 'terrain',
112
- token: 'your_tianditu_token',
113
- });
114
- ```
115
-
116
- ## 配置选项
117
-
118
- ### 工具栏配置
119
-
120
- ```typescript
121
- interface ToolbarConfig {
122
- position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
123
- buttonSize?: number; // 按钮大小 (默认40px)
124
- buttonSpacing?: number; // 按钮间距 (默认8px)
125
- backgroundColor?: string; // 背景色
126
- borderColor?: string; // 边框色
127
- borderRadius?: number; // 圆角半径
128
- showSearch?: boolean; // 显示搜索框
129
- showMeasurement?: boolean; // 显示测量工具
130
- showDrawing?: boolean; // 显示绘制工具
131
- showLayerControl?: boolean; // 显示图层控制
132
- show2D3DToggle?: boolean; // 显示2D/3D切换
133
- }
134
- ```
86
+ 以下导出仍保留,但定位是迁移适配层,不再是推荐入口:
135
87
 
136
- ### 回调函数
88
+ - initCesium
89
+ - CesiumMapToolbar
90
+ - CesiumOverlayService
91
+ - DrawHelper
137
92
 
138
- ```typescript
139
- interface ToolbarCallbacks {
140
- search?: (query: string) => void;
141
- measurement?: (type: string, result: any) => void;
142
- drawing?: (type: string, entity: Entity) => void;
143
- zoom?: (level: number) => void;
144
- }
145
- ```
93
+ ## 迁移建议
146
94
 
147
- ## 功能说明
95
+ 建议按下面顺序逐步迁移旧业务。
148
96
 
149
- ### 搜索功能
97
+ 1. 用 createMapPlugin(...).initialize() 替代 initCesium(...)
98
+ 2. 用 services.toolbar 或 mapPlugin.getToolbarService() 替代直接构造 CesiumMapToolbar
99
+ 3. 用 mapPlugin.getOverlayService() 替代直接维护 CesiumOverlayService 生命周期
100
+ 4. 用 mapPlugin.getDrawService() 替代 DrawHelper 的直接持有
101
+ 5. 仅在过渡窗口内保留 compat 导出
150
102
 
151
- 支持路网搜索和坐标定位:
103
+ ### 旧写法
152
104
 
153
- ```javascript
154
- // 搜索回调
155
- const callbacks = {
156
- search: (query) => {
157
- console.log('搜索:', query);
158
- // 实现搜索逻辑
159
- }
160
- };
105
+ ```ts
106
+ import { initCesium, CesiumMapToolbar } from '@xingm/vmap-cesium-toolbar';
161
107
  ```
162
108
 
163
- ### 测量工具
164
-
165
- 支持多种测量类型:
109
+ ### 新写法
166
110
 
167
- - **距离测量** - 测量两点间距离
168
- - **面积测量** - 测量多边形面积
169
- - **高度测量** - 测量点的高度信息
170
-
171
- ```javascript
172
- // 测量回调
173
- const callbacks = {
174
- measurement: (type, result) => {
175
- console.log('测量结果:', type, result);
176
- }
177
- };
111
+ ```ts
112
+ import { createMapPlugin } from '@xingm/vmap-cesium-toolbar';
178
113
  ```
179
114
 
180
- ### 绘制功能
115
+ ## Vue 3 示例
181
116
 
182
- 支持多种绘制类型:
117
+ ```vue
118
+ <template>
119
+ <div id="cesiumContainer" style="width: 100%; height: 100vh"></div>
120
+ </template>
183
121
 
184
- - **点绘制** - 在地图上标记点
185
- - **线绘制** - 绘制线条
186
- - **面绘制** - 绘制多边形区域
122
+ <script setup lang="ts">
123
+ import { onMounted, onBeforeUnmount } from 'vue';
124
+ import { createMapPlugin } from '@xingm/vmap-cesium-toolbar';
187
125
 
188
- ```javascript
189
- // 绘制回调
190
- const callbacks = {
191
- drawing: (type, entity) => {
192
- console.log('绘制完成:', type, entity);
193
- }
194
- };
195
- ```
126
+ let mapPlugin: ReturnType<typeof createMapPlugin> | null = null;
196
127
 
197
- ## 样式定制
128
+ onMounted(async () => {
129
+ mapPlugin = createMapPlugin('cesiumContainer', {
130
+ camera: {
131
+ center: [116.3974, 39.9093, 1000],
132
+ pitch: -45,
133
+ },
134
+ layers: {
135
+ type: 'tdt',
136
+ tdt: {
137
+ mapTypeId: 'img',
138
+ token: 'your-tianditu-token',
139
+ },
140
+ },
141
+ services: {
142
+ toolbar: { enabled: true },
143
+ overlay: true,
144
+ draw: true,
145
+ },
146
+ });
198
147
 
199
- 组件提供了完整的CSS变量支持,可以轻松定制样式:
148
+ await mapPlugin.initialize();
149
+ });
200
150
 
201
- ```css
202
- :root {
203
- --toolbar-bg-color: #ffffff;
204
- --toolbar-border-color: #e0e0e0;
205
- --toolbar-button-size: 40px;
206
- --toolbar-button-spacing: 8px;
207
- --toolbar-border-radius: 4px;
208
- }
151
+ onBeforeUnmount(() => {
152
+ mapPlugin?.destroy();
153
+ });
154
+ </script>
209
155
  ```
210
156
 
211
- ## 示例项目
157
+ ## 文档入口
212
158
 
213
- ### 基本使用示例
159
+ - 架构说明:doc/guide/Architecture.md
160
+ - 迁移指南:doc/guide/Migration_Guide.md
161
+ - API 目录:doc/api/index.md
214
162
 
215
- ```bash
216
- # 克隆项目
217
- git clone https://github.com/your-username/vmap-cesium-toolbar.git
218
- cd vmap-cesium-toolbar
219
-
220
- # 查看基本示例
221
- cd examples/basic-usage
222
- # 在浏览器中打开 index.html
223
- ```
163
+ 说明:当前文档站已优先切换为“新架构说明 + 兼容 API 参考”的组织方式,新的逐个 API 页面会继续补齐。
224
164
 
225
- ### Vue 3 示例
165
+ ## 开发命令
226
166
 
227
167
  ```bash
228
- cd examples/vue3-usage
229
- npm install
230
- npm run dev
168
+ pnpm run build:plugin
169
+ pnpm run type-check
170
+ pnpm run docs:dev
171
+ pnpm run docs:build
231
172
  ```
232
-
233
- ## API 文档
234
-
235
- 详细的API文档请参考:
236
-
237
- - [CesiumMapToolbar API](./doc/CesiumMapToolbar_API.md)
238
- - [CesiumMapHelper API](./doc/CesiumMapHelper_API.md)
239
- - [CesiumMapLoader API](./doc/CesiumMapLoader_API.md)
240
- - [CesiumOverlayService API](./doc/CesiumOverlayService_API.md)
241
-
242
- ## 依赖要求
243
-
244
- - **Cesium**: ^1.100.0
245
- - **Vue**: ^3.0.0 (可选,用于Vue项目)
246
-
247
- ## 浏览器支持
248
-
249
- - Chrome 60+
250
- - Firefox 55+
251
- - Safari 12+
252
- - Edge 79+
253
-
254
- ## 许可证
255
-
256
- MIT License
257
-
258
- ## 贡献
259
-
260
- 欢迎提交 Issue 和 Pull Request!
261
-
262
- ## 更新日志
263
-
264
- ### v0.0.1-beta.2
265
-
266
- - 新增高度测量功能
267
- - 优化标签显示逻辑
268
- - 修复3D模式下标签位置问题
269
- - 改进绘制工具的用户体验
270
-
271
- ### v0.0.1-beta.1
272
-
273
- - 初始版本发布
274
- - 基础工具栏功能
275
- - 搜索、测量、绘制功能
276
- - Vue 3 支持
package/dist/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # @xingm/vmap-cesium-toolbar
2
+
3
+ 一个以 MapPlugin 为中心的 Cesium 地图工具库,重构后将 Viewer 生命周期、工具栏、覆盖物和绘制能力统一收敛到插件内核与服务层,并保留一层兼容适配器用于平滑迁移旧 API。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @xingm/vmap-cesium-toolbar cesium
9
+ ```
10
+
11
+ ## 推荐入口
12
+
13
+ 新项目只推荐使用 createMapPlugin、MapPlugin 和服务层 API。
14
+
15
+ ```ts
16
+ import { createMapPlugin } from '@xingm/vmap-cesium-toolbar';
17
+
18
+ const mapPlugin = createMapPlugin('cesiumContainer', {
19
+ cesiumToken: 'your-cesium-ion-token',
20
+ camera: {
21
+ center: [116.3974, 39.9093, 1000],
22
+ pitch: -45,
23
+ heading: 0,
24
+ },
25
+ layers: {
26
+ type: 'tdt',
27
+ tdt: {
28
+ mapTypeId: 'img',
29
+ token: 'your-tianditu-token',
30
+ showLabel: true,
31
+ },
32
+ },
33
+ viewerOptions: {
34
+ animation: false,
35
+ timeline: false,
36
+ navigationHelpButton: false,
37
+ },
38
+ services: {
39
+ overlay: true,
40
+ draw: true,
41
+ toolbar: {
42
+ enabled: true,
43
+ callbacks: {
44
+ onSearch: async () => [],
45
+ },
46
+ },
47
+ },
48
+ });
49
+
50
+ const viewer = await mapPlugin.initialize();
51
+ const toolbarService = mapPlugin.getToolbarService();
52
+ const overlayService = mapPlugin.getOverlayService();
53
+ const drawService = mapPlugin.getDrawService();
54
+
55
+ drawService.startDrawing('polygon');
56
+
57
+ mapPlugin.updateLayers({
58
+ type: 'tdt',
59
+ tdt: {
60
+ mapTypeId: 'vec',
61
+ token: 'your-tianditu-token',
62
+ showLabel: true,
63
+ },
64
+ });
65
+ ```
66
+
67
+ ## 重构后的公开层次
68
+
69
+ ### 1. 新 API
70
+
71
+ - createMapPlugin
72
+ - MapPlugin
73
+ - ToolbarService
74
+ - OverlayService
75
+ - DrawService
76
+ - Marker、Label、Icon、SVG、InfoWindow、Polyline、Polygon、Rectangle、Circle、Ring
77
+ - HeatmapLayer、PointClusterLayer
78
+
79
+ ### 2. 类型与样式能力
80
+
81
+ - MapPluginOptions、ToolbarConfig、LayersConfig 等统一从顶层导出
82
+ - i18n 与样式系统继续保留顶层导出,供组件与业务侧接入
83
+
84
+ ### 3. 兼容 API
85
+
86
+ 以下导出仍保留,但定位是迁移适配层,不再是推荐入口:
87
+
88
+ - initCesium
89
+ - CesiumMapToolbar
90
+ - CesiumOverlayService
91
+ - DrawHelper
92
+
93
+ ## 迁移建议
94
+
95
+ 建议按下面顺序逐步迁移旧业务。
96
+
97
+ 1. 用 createMapPlugin(...).initialize() 替代 initCesium(...)
98
+ 2. 用 services.toolbar 或 mapPlugin.getToolbarService() 替代直接构造 CesiumMapToolbar
99
+ 3. 用 mapPlugin.getOverlayService() 替代直接维护 CesiumOverlayService 生命周期
100
+ 4. 用 mapPlugin.getDrawService() 替代 DrawHelper 的直接持有
101
+ 5. 仅在过渡窗口内保留 compat 导出
102
+
103
+ ### 旧写法
104
+
105
+ ```ts
106
+ import { initCesium, CesiumMapToolbar } from '@xingm/vmap-cesium-toolbar';
107
+ ```
108
+
109
+ ### 新写法
110
+
111
+ ```ts
112
+ import { createMapPlugin } from '@xingm/vmap-cesium-toolbar';
113
+ ```
114
+
115
+ ## Vue 3 示例
116
+
117
+ ```vue
118
+ <template>
119
+ <div id="cesiumContainer" style="width: 100%; height: 100vh"></div>
120
+ </template>
121
+
122
+ <script setup lang="ts">
123
+ import { onMounted, onBeforeUnmount } from 'vue';
124
+ import { createMapPlugin } from '@xingm/vmap-cesium-toolbar';
125
+
126
+ let mapPlugin: ReturnType<typeof createMapPlugin> | null = null;
127
+
128
+ onMounted(async () => {
129
+ mapPlugin = createMapPlugin('cesiumContainer', {
130
+ camera: {
131
+ center: [116.3974, 39.9093, 1000],
132
+ pitch: -45,
133
+ },
134
+ layers: {
135
+ type: 'tdt',
136
+ tdt: {
137
+ mapTypeId: 'img',
138
+ token: 'your-tianditu-token',
139
+ },
140
+ },
141
+ services: {
142
+ toolbar: { enabled: true },
143
+ overlay: true,
144
+ draw: true,
145
+ },
146
+ });
147
+
148
+ await mapPlugin.initialize();
149
+ });
150
+
151
+ onBeforeUnmount(() => {
152
+ mapPlugin?.destroy();
153
+ });
154
+ </script>
155
+ ```
156
+
157
+ ## 文档入口
158
+
159
+ - 架构说明:doc/guide/Architecture.md
160
+ - 迁移指南:doc/guide/Migration_Guide.md
161
+ - API 目录:doc/api/index.md
162
+
163
+ 说明:当前文档站已优先切换为“新架构说明 + 兼容 API 参考”的组织方式,新的逐个 API 页面会继续补齐。
164
+
165
+ ## 开发命令
166
+
167
+ ```bash
168
+ pnpm run build:plugin
169
+ pnpm run type-check
170
+ pnpm run docs:dev
171
+ pnpm run docs:build
172
+ ```