@xingm/vmap-cesium-toolbar 0.0.1-beta.2 → 0.0.1-beta.3

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/dist/README.md DELETED
@@ -1,585 +0,0 @@
1
- # VMap Cesium Toolbar Plugin
2
-
3
- 一个功能强大的 Cesium 地图工具栏插件,提供搜索、测量、绘制、图层切换等功能。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install vmap-cesium-toolbar
9
- # 或
10
- yarn add vmap-cesium-toolbar
11
- # 或
12
- pnpm add vmap-cesium-toolbar
13
- ```
14
-
15
- ## 依赖要求
16
-
17
- - Vue 3.0+
18
- - Cesium 1.100.0+
19
-
20
- ## 快速开始
21
-
22
- ### 1. 基本使用
23
-
24
- ```typescript
25
- import { createApp } from 'vue';
26
- import { CesiumMapToolbar, initCesium } from 'vmap-cesium-toolbar';
27
- import 'vmap-cesium-toolbar/style';
28
-
29
- // 设置 Cesium Token
30
- Cesium.Ion.defaultAccessToken = 'your-cesium-token';
31
-
32
- const app = createApp({
33
- async mounted() {
34
- // 初始化 Cesium 地图
35
- const { viewer, initialCenter } = await initCesium('cesiumContainer', {
36
- terrain: Cesium.Terrain.fromWorldTerrain(),
37
- animation: false,
38
- baseLayerPicker: false,
39
- fullscreenButton: false,
40
- geocoder: false,
41
- homeButton: false,
42
- infoBox: false,
43
- sceneModePicker: false,
44
- selectionIndicator: false,
45
- timeline: false,
46
- navigationHelpButton: false,
47
- scene3DOnly: false,
48
- });
49
-
50
- // 创建工具栏
51
- const container = document.getElementById('cesiumContainer');
52
- const toolbar = new CesiumMapToolbar(
53
- viewer,
54
- container,
55
- {
56
- position: 'bottom-right',
57
- buttonSize: 40,
58
- buttonSpacing: 8,
59
- backgroundColor: 'rgba(255, 255, 255, 0.95)',
60
- borderColor: '#e0e0e0',
61
- borderRadius: 6,
62
- zIndex: 1000,
63
- },
64
- {
65
- search: {
66
- onSearch: async (query: string) => {
67
- // 实现搜索逻辑
68
- return await searchAPI(query);
69
- },
70
- onSelect: (result) => {
71
- console.log('定位到:', result.name);
72
- }
73
- },
74
- measurement: {
75
- onDistanceComplete: (positions, distance) => {
76
- console.log(`测距完成,总距离: ${distance.toFixed(2)} 米`);
77
- },
78
- onAreaComplete: (positions, area) => {
79
- console.log(`测面积完成,面积: ${area.toFixed(2)} 平方公里`);
80
- },
81
- onClear: () => {
82
- console.log('清除测量');
83
- }
84
- },
85
- zoom: {
86
- onZoomIn: (beforeLevel, afterLevel) => {
87
- console.log(`放大: ${beforeLevel.toFixed(0)} -> ${afterLevel.toFixed(0)}`);
88
- },
89
- onZoomOut: (beforeLevel, afterLevel) => {
90
- console.log(`缩小: ${beforeLevel.toFixed(0)} -> ${afterLevel.toFixed(0)}`);
91
- }
92
- }
93
- },
94
- initialCenter
95
- );
96
- }
97
- });
98
-
99
- app.mount('#app');
100
- ```
101
-
102
- ### 2. 在 Vue 组件中使用
103
-
104
- ```vue
105
- <template>
106
- <div class="map-container">
107
- <div id="cesiumContainer" ref="cesiumContainer"></div>
108
- </div>
109
- </template>
110
-
111
- <script setup lang="ts">
112
- import { onMounted, onBeforeUnmount, ref } from 'vue';
113
- import { CesiumMapToolbar, initCesium } from 'vmap-cesium-toolbar';
114
- import 'vmap-cesium-toolbar/style';
115
-
116
- const cesiumContainer = ref<HTMLElement>();
117
- let viewer: any;
118
- let toolbar: CesiumMapToolbar | null = null;
119
-
120
- onMounted(async () => {
121
- // 初始化地图
122
- const { viewer: cesiumViewer, initialCenter } = await initCesium('cesiumContainer', {
123
- terrain: Cesium.Terrain.fromWorldTerrain(),
124
- animation: false,
125
- baseLayerPicker: false,
126
- fullscreenButton: false,
127
- geocoder: false,
128
- homeButton: false,
129
- infoBox: false,
130
- sceneModePicker: false,
131
- selectionIndicator: false,
132
- timeline: false,
133
- navigationHelpButton: false,
134
- scene3DOnly: false,
135
- });
136
-
137
- viewer = cesiumViewer;
138
-
139
- // 创建工具栏
140
- const container = document.getElementById('cesiumContainer');
141
- if (container) {
142
- toolbar = new CesiumMapToolbar(
143
- viewer,
144
- container,
145
- {
146
- position: 'bottom-right',
147
- buttonSize: 45,
148
- buttonSpacing: 10,
149
- backgroundColor: 'rgba(255, 255, 255, 0.95)',
150
- borderColor: '#4285f4',
151
- borderRadius: 8,
152
- zIndex: 1000,
153
- },
154
- {
155
- search: {
156
- onSearch: async (query: string) => {
157
- // 实现搜索逻辑
158
- return [];
159
- },
160
- onSelect: (result) => {
161
- console.log('定位到:', result.name);
162
- }
163
- },
164
- measurement: {
165
- onDistanceComplete: (positions, distance) => {
166
- console.log(`测距完成,总距离: ${distance.toFixed(2)} 米`);
167
- },
168
- onAreaComplete: (positions, area) => {
169
- console.log(`测面积完成,面积: ${area.toFixed(2)} 平方公里`);
170
- },
171
- onClear: () => {
172
- console.log('清除测量');
173
- }
174
- }
175
- },
176
- initialCenter
177
- );
178
- }
179
- });
180
-
181
- onBeforeUnmount(() => {
182
- if (toolbar) {
183
- toolbar.destroy();
184
- }
185
- });
186
- </script>
187
-
188
- <style scoped>
189
- .map-container {
190
- width: 100%;
191
- height: 100vh;
192
- position: relative;
193
- }
194
-
195
- #cesiumContainer {
196
- width: 100%;
197
- height: 100%;
198
- }
199
- </style>
200
- ```
201
-
202
- ## API 文档
203
-
204
- ### CesiumMapToolbar
205
-
206
- #### 构造函数
207
-
208
- ```typescript
209
- new CesiumMapToolbar(
210
- viewer: Viewer,
211
- container: HTMLElement,
212
- config?: ToolbarConfig,
213
- callbacks?: {
214
- search?: SearchCallback;
215
- measurement?: MeasurementCallback;
216
- zoom?: ZoomCallback;
217
- },
218
- initialCenter?: { longitude: number; latitude: number; height: number }
219
- )
220
- ```
221
-
222
- #### 主要方法
223
-
224
- ##### setInitialCenter(center)
225
-
226
- 设置初始中心点
227
-
228
- ```typescript
229
- toolbar.setInitialCenter({
230
- longitude: 116.3974,
231
- latitude: 39.9093,
232
- height: 1000
233
- });
234
- ```
235
-
236
- ##### getInitialCenter()
237
-
238
- 获取初始中心点
239
-
240
- ```typescript
241
- const center = toolbar.getInitialCenter();
242
- ```
243
-
244
- ##### resetToInitialLocation()
245
-
246
- 复位到初始位置
247
-
248
- ```typescript
249
- toolbar.resetToInitialLocation();
250
- ```
251
-
252
- ##### drawMonitoringCircle(longitude, latitude, height, radius, options)
253
-
254
- 绘制监控圆形区域(代理到 DrawHelper)
255
-
256
- ```typescript
257
- const circle = toolbar.drawMonitoringCircle(
258
- 120.16, // 经度
259
- 30.28, // 纬度
260
- 100, // 高度
261
- 500, // 半径500米
262
- {
263
- borderColor: '#0062FF',
264
- fillColor: '#0062FF',
265
- borderWidth: 2,
266
- name: '监控区域'
267
- }
268
- );
269
- ```
270
-
271
- ##### drawVerticalLine(longitude, latitude, height, options)
272
-
273
- 绘制垂直线条(代理到 DrawHelper)
274
-
275
- ```typescript
276
- const line = toolbar.drawVerticalLine(
277
- 120.15, // 经度
278
- 30.25, // 纬度
279
- 1000, // 高度1000米
280
- {
281
- color: '#0062FF',
282
- width: 3,
283
- dashPattern: 0x00FF00FF,
284
- name: '垂直线',
285
- groundHeight: 0
286
- }
287
- );
288
- ```
289
-
290
- ##### destroy()
291
-
292
- 销毁工具栏
293
-
294
- ```typescript
295
- toolbar.destroy();
296
- ```
297
-
298
- ### DrawHelper
299
-
300
- #### 构造函数
301
-
302
- ```typescript
303
- new DrawHelper(viewer: Viewer)
304
- ```
305
-
306
- #### 主要方法
307
-
308
- ##### startDrawingLine()
309
-
310
- 开始绘制线条
311
-
312
- ```typescript
313
- drawHelper.startDrawingLine();
314
- ```
315
-
316
- ##### startDrawingPolygon()
317
-
318
- 开始绘制多边形
319
-
320
- ```typescript
321
- drawHelper.startDrawingPolygon();
322
- ```
323
-
324
- ##### startDrawingRectangle()
325
-
326
- 开始绘制矩形
327
-
328
- ```typescript
329
- drawHelper.startDrawingRectangle();
330
- ```
331
-
332
- ##### drawFrustum(options)
333
-
334
- 绘制视锥体
335
-
336
- ```typescript
337
- drawHelper.drawFrustum({
338
- position: cameraPosition,
339
- orientation: cameraOrientation,
340
- fov: 60,
341
- aspectRatio: 1.5,
342
- near: 10,
343
- far: 2000,
344
- fillColor: Cesium.Color.BLUE.withAlpha(0.3),
345
- outlineColor: Cesium.Color.WHITE,
346
- onRightClick: (pos) => {
347
- console.log('视锥体被右键点击:', pos);
348
- }
349
- });
350
- ```
351
-
352
- ##### clearAll()
353
-
354
- 清除所有绘制内容
355
-
356
- ```typescript
357
- drawHelper.clearAll();
358
- ```
359
-
360
- ##### clearFrustum()
361
-
362
- 清除视锥体
363
-
364
- ```typescript
365
- drawHelper.clearFrustum();
366
- ```
367
-
368
- ##### drawMonitoringCircle(longitude, latitude, height, radius, options?)
369
-
370
- 绘制监控圆形区域
371
-
372
- ```typescript
373
- const circle = drawHelper.drawMonitoringCircle(
374
- 120.16, // 经度
375
- 30.28, // 纬度
376
- 100, // 高度
377
- 500, // 半径(米)
378
- {
379
- borderColor: '#0062FF',
380
- fillColor: '#0062FF',
381
- borderWidth: 2,
382
- name: '监控区域'
383
- }
384
- );
385
- ```
386
-
387
- ##### drawVerticalLine(longitude, latitude, height, options?)
388
-
389
- 绘制垂直线条
390
-
391
- ```typescript
392
- const line = drawHelper.drawVerticalLine(
393
- 120.15, // 经度
394
- 30.25, // 纬度
395
- 1000, // 高度
396
- {
397
- color: '#0062FF',
398
- width: 3,
399
- dashPattern: 0x00FF00FF,
400
- name: '垂直线条',
401
- groundHeight: 0
402
- }
403
- );
404
- ```
405
-
406
- ### initCesium
407
-
408
- #### 函数签名
409
-
410
- ```typescript
411
- async function initCesium(
412
- containerId: string,
413
- options: InitOptions,
414
- mapCenter?: MapCenter
415
- ): Promise<{ viewer: Viewer; initialCenter: MapCenter }>
416
- ```
417
-
418
- #### 使用示例
419
-
420
- ```typescript
421
- const { viewer, initialCenter } = await initCesium('cesiumContainer', {
422
- terrain: Cesium.Terrain.fromWorldTerrain(),
423
- animation: false,
424
- baseLayerPicker: false,
425
- fullscreenButton: false,
426
- geocoder: false,
427
- homeButton: false,
428
- infoBox: false,
429
- sceneModePicker: false,
430
- selectionIndicator: false,
431
- timeline: false,
432
- navigationHelpButton: false,
433
- scene3DOnly: false,
434
- }, {
435
- longitude: 120.2052342,
436
- latitude: 30.2489634,
437
- height: 1000,
438
- pitch: -60,
439
- heading: 0
440
- });
441
- ```
442
-
443
- ## 配置选项
444
-
445
- ### ToolbarConfig
446
-
447
- ```typescript
448
- interface ToolbarConfig {
449
- position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
450
- buttonSize?: number; // 按钮大小 (默认40px)
451
- buttonSpacing?: number; // 按钮间距 (默认8px)
452
- backgroundColor?: string; // 背景色
453
- borderColor?: string; // 边框色
454
- borderRadius?: number; // 圆角半径
455
- borderWidth?: number; // 边框宽度
456
- boxShadow?: string; // 阴影
457
- zIndex?: number; // 层级
458
- }
459
- ```
460
-
461
- ### SearchCallback
462
-
463
- ```typescript
464
- interface SearchCallback {
465
- onSearch?: (query: string) => Promise<SearchResult[]>;
466
- onSelect?: (result: SearchResult) => void;
467
- }
468
- ```
469
-
470
- ### MeasurementCallback
471
-
472
- ```typescript
473
- interface MeasurementCallback {
474
- onDistanceComplete?: (positions: Cartesian3[], distance: number) => void;
475
- onAreaComplete?: (positions: Cartesian3[], area: number) => void;
476
- onClear?: () => void;
477
- }
478
- ```
479
-
480
- ### ZoomCallback
481
-
482
- ```typescript
483
- interface ZoomCallback {
484
- onZoomIn?: (beforeLevel: number, afterLevel: number) => void;
485
- onZoomOut?: (beforeLevel: number, afterLevel: number) => void;
486
- }
487
- ```
488
-
489
- ## 工具栏功能
490
-
491
- ### 1. 搜索功能 🔍
492
-
493
- - 鼠标悬停显示搜索框
494
- - 支持地址搜索
495
- - 点击搜索结果自动定位
496
-
497
- ### 2. 测量功能 📏
498
-
499
- - 测距:支持多点折线,显示每段距离和总距离
500
- - 测面积:绘制淡绿色填充多边形,显示面积
501
- - 清除:清除所有测量内容
502
-
503
- ### 3. 2D/3D切换 🔄
504
-
505
- - 一键切换2D和3D视角
506
- - 按钮文本自动更新
507
-
508
- ### 4. 图层切换 📚
509
-
510
- - 支持天地图的普通、三维、影像、地形四种类型
511
- - 单选模式,默认影像图
512
-
513
- ### 5. 定位功能 🎯
514
-
515
- - 复位到地图初始中心点
516
- - 平滑飞行动画
517
-
518
- ### 6. 缩放功能 🔍+/🔍-
519
-
520
- - 地图放大/缩小
521
- - 支持缩放回调
522
-
523
- ### 7. 全屏功能 ⛶
524
-
525
- - 进入/退出全屏模式
526
- - 自动检测全屏状态
527
-
528
- ## 样式定制
529
-
530
- ### CSS 变量
531
-
532
- ```css
533
- :root {
534
- --toolbar-bg: rgba(255, 255, 255, 0.95);
535
- --toolbar-border: #e0e0e0;
536
- --toolbar-radius: 6px;
537
- --button-bg: rgba(66, 133, 244, 0.4);
538
- --button-hover-bg: rgba(51, 103, 214, 0.9);
539
- --button-color: white;
540
- }
541
- ```
542
-
543
- ### 自定义样式
544
-
545
- ```css
546
- /* 自定义工具栏样式 */
547
- .cesium-map-toolbar {
548
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
549
- border: 2px solid #fff !important;
550
- }
551
-
552
- .cesium-toolbar-button {
553
- background: rgba(255, 255, 255, 0.2) !important;
554
- color: #fff !important;
555
- border: 1px solid rgba(255, 255, 255, 0.3) !important;
556
- }
557
-
558
- .cesium-toolbar-button:hover {
559
- background: rgba(255, 255, 255, 0.3) !important;
560
- transform: scale(1.1) !important;
561
- }
562
- ```
563
-
564
- ## 注意事项
565
-
566
- 1. **Cesium Token**:使用世界地形需要有效的 Cesium Ion Token
567
- 2. **网络连接**:确保网络连接正常,能够访问 Cesium 服务
568
- 3. **浏览器兼容性**:确保浏览器支持 WebGL
569
- 4. **内存管理**:记得在组件销毁时调用 `destroy()` 方法
570
- 5. **事件冲突**:工具栏会管理自己的事件处理器,避免与其他组件冲突
571
-
572
- ## 许可证
573
-
574
- MIT License
575
-
576
- ## 更新日志
577
-
578
- ### v1.0.0
579
-
580
- - 初始版本发布
581
- - 支持完整的工具栏功能(搜索、测量、2D/3D切换、图层切换、定位、缩放、全屏)
582
- - 支持完整的绘图功能(点、线、多边形、矩形、视锥体)
583
- - 完整的回调系统和事件处理
584
- - 可配置的样式选项
585
- - 完善的错误处理和资源管理