@xingm/vmap-cesium-toolbar 0.0.1-beta.6 → 0.0.1-beta.7

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,13 @@
1
+ import { Viewer } from '../../node_modules/cesium';
2
+ import { default as DrawHelper } from './CesiumMapHelper';
3
+ import { MapType, ToolbarConfig, SearchCallback, MeasurementCallback, ZoomCallback } from './CesiumMapModel';
4
+ export interface CesiumMapConfig {
5
+ viewer?: Viewer;
6
+ drawHelper?: DrawHelper;
7
+ toolbar?: ToolbarConfig;
8
+ search?: SearchCallback;
9
+ measurement?: MeasurementCallback;
10
+ zoom?: ZoomCallback;
11
+ mapTypes?: MapType[];
12
+ }
13
+ export declare const TDTMapTypes: MapType[];
@@ -0,0 +1,180 @@
1
+ import * as Cesium from "cesium";
2
+ /**
3
+ * Cesium 绘图辅助工具类
4
+ * 支持绘制点、线、多边形、矩形,并提供编辑和删除功能
5
+ * 适用于 Cesium 1.132.0
6
+ */
7
+ declare class DrawHelper {
8
+ private viewer;
9
+ private scene;
10
+ private entities;
11
+ private frustumPrimitives;
12
+ private drawMode;
13
+ private isDrawing;
14
+ private tempPositions;
15
+ private tempEntities;
16
+ private tempLabelEntities;
17
+ private finishedEntities;
18
+ private finishedLabelEntities;
19
+ private finishedPointEntities;
20
+ private publicEntities;
21
+ private _doubleClickPending;
22
+ private screenSpaceEventHandler;
23
+ private onDrawStartCallback;
24
+ private onDrawEndCallback;
25
+ private onEntityRemovedCallback;
26
+ private offsetHeight;
27
+ /**
28
+ * 构造函数
29
+ * @param viewer Cesium Viewer 实例
30
+ */
31
+ constructor(viewer: Cesium.Viewer);
32
+ /**
33
+ * 根据场景模式更新偏移高度
34
+ */
35
+ private updateOffsetHeight;
36
+ /**
37
+ * 开始绘制线条
38
+ */
39
+ startDrawingLine(): void;
40
+ /**
41
+ * 开始绘制多边形(仅边线)
42
+ */
43
+ startDrawingPolygon(): void;
44
+ /**
45
+ * 开始绘制矩形
46
+ */
47
+ startDrawingRectangle(): void;
48
+ /**
49
+ * 内部统一的开始绘制方法
50
+ * @param mode 绘制模式
51
+ */
52
+ private startDrawing;
53
+ /**
54
+ * 激活屏幕空间事件处理器
55
+ */
56
+ private activateDrawingHandlers;
57
+ /**
58
+ * 拾取地形或椭球体上的位置
59
+ * @param windowPosition 屏幕坐标
60
+ * @returns 世界坐标 Cartesian3 或 null
61
+ */
62
+ private pickGlobePosition;
63
+ /**
64
+ * 添加一个点到临时位置数组并创建点实体
65
+ * @param position 世界坐标
66
+ */
67
+ private addPoint;
68
+ /**
69
+ * 删除最后一个添加的点及其相关的临时实体
70
+ */
71
+ private removeLastPoint;
72
+ /**
73
+ * 重新创建剩余的点实体和绘制实体
74
+ * 用于右键删除点后的重建
75
+ */
76
+ private recreateRemainingEntities;
77
+ /**
78
+ * 更新预览线/面
79
+ * @param currentMousePosition 当前鼠标位置世界坐标
80
+ */
81
+ private updatePreview;
82
+ /**
83
+ * 核心方法:根据当前点序列更新或创建临时的线/面实体
84
+ * @param previewPoint 可选的预览点,用于显示动态效果
85
+ */
86
+ private updateDrawingEntity;
87
+ /**
88
+ * 完成当前绘制操作
89
+ */
90
+ private finishDrawing;
91
+ /**
92
+ * 内部方法:重置绘图状态和清理临时数据
93
+ * @param resetMode 是否重置绘图模式和状态标志
94
+ */
95
+ private endDrawingInternal;
96
+ /**
97
+ * 公共方法:结束当前绘制(如果正在进行)
98
+ */
99
+ endDrawing(): void;
100
+ /**
101
+ * 销毁事件处理器
102
+ */
103
+ private deactivateDrawingHandlers;
104
+ /**
105
+ * 清除所有已绘制的实体
106
+ */
107
+ clearAll(): void;
108
+ /**
109
+ * 清除所有实体(包括未跟踪的实体)
110
+ * 这是一个更彻底的清理方法,会清除场景中的所有实体
111
+ */
112
+ clearAllEntities(): void;
113
+ /**
114
+ * 强制清除所有点实体
115
+ * 用于解决点实体无法删除的问题
116
+ */
117
+ clearAllPoints(): void;
118
+ /**
119
+ * 删除一个指定的已完成实体
120
+ * @param entity 要删除的实体
121
+ */
122
+ removeEntity(entity: Cesium.Entity): void;
123
+ /**
124
+ * 获取所有已完成的实体
125
+ * @returns 实体数组
126
+ */
127
+ getFinishedEntities(): Cesium.Entity[];
128
+ private calculateRectangle;
129
+ private calculateRectangleArea;
130
+ private calculatePolygonArea;
131
+ private calculatePolygonCenter;
132
+ /**
133
+ * 设置开始绘制时的回调函数
134
+ * @param callback 回调函数
135
+ */
136
+ onDrawStart(callback: () => void): void;
137
+ /**
138
+ * 设置结束绘制时的回调函数
139
+ * @param callback 回调函数,参数为完成的实体或null
140
+ */
141
+ onDrawEnd(callback: (entity: Cesium.Entity | null) => void): void;
142
+ /**
143
+ * 设置实体被移除时的回调函数
144
+ * @param callback 回调函数,参数为被移除的实体
145
+ */
146
+ onEntityRemoved(callback: (entity: Cesium.Entity) => void): void;
147
+ /**
148
+ * 绘制监控圆形区域
149
+ * @param longitude 经度
150
+ * @param latitude 纬度
151
+ * @param height 高度
152
+ * @param radius 监控范围半径(米)
153
+ * @param options 可选配置
154
+ */
155
+ drawMonitoringCircle(longitude: number, latitude: number, height: number, radius: number, options?: {
156
+ borderColor?: string;
157
+ fillColor?: string;
158
+ borderWidth?: number;
159
+ name?: string;
160
+ }): Cesium.Entity;
161
+ /**
162
+ * 绘制垂直线条
163
+ * @param longitude 经度
164
+ * @param latitude 纬度
165
+ * @param height 高度
166
+ * @param options 可选配置
167
+ */
168
+ drawVerticalLine(longitude: number, latitude: number, height: number, options?: {
169
+ color?: string;
170
+ width?: number;
171
+ dashPattern?: number;
172
+ name?: string;
173
+ groundHeight?: number;
174
+ }): Cesium.Entity;
175
+ /**
176
+ * 销毁工具,清理所有事件监听器
177
+ */
178
+ destroy(): void;
179
+ }
180
+ export default DrawHelper;
@@ -0,0 +1,53 @@
1
+ import { Terrain, TerrainProvider, Viewer as CesiumViewer } from '../../node_modules/cesium';
2
+ import * as Cesium from 'cesium';
3
+ interface InitOptions {
4
+ terrain?: Terrain;
5
+ terrainProvider?: TerrainProvider;
6
+ mapType?: string;
7
+ imageryProvider?: Cesium.UrlTemplateImageryProvider;
8
+ imageryLayers?: Cesium.ImageryLayerCollection;
9
+ terrainShadows?: Cesium.ShadowMode;
10
+ contextOptions?: Cesium.ContextOptions;
11
+ scene3DOnly?: boolean;
12
+ selectionIndicator?: boolean;
13
+ navigationHelpButton?: boolean;
14
+ fullscreenButton?: boolean;
15
+ geocoder?: boolean;
16
+ homeButton?: boolean;
17
+ infoBox?: boolean;
18
+ vrButton?: boolean;
19
+ sceneModePicker?: boolean;
20
+ timeline?: boolean;
21
+ animation?: boolean;
22
+ baseLayerPicker?: boolean;
23
+ navigationInstructionsInitiallyVisible?: boolean;
24
+ clock?: Cesium.Clock;
25
+ sceneMode?: Cesium.SceneMode;
26
+ screenSpaceEventHandler?: Cesium.ScreenSpaceEventHandler;
27
+ useDefaultRenderLoop?: boolean;
28
+ targetFrameRate?: number;
29
+ showRenderLoopErrors?: boolean;
30
+ automaticallyTrackDataSourceClocks?: boolean;
31
+ dataSources?: Cesium.DataSourceCollection;
32
+ creationTime?: number;
33
+ useBrowserRecommendedResolution?: boolean;
34
+ resolutionScale?: number;
35
+ orderIndependentTransparency?: boolean;
36
+ shadows?: boolean;
37
+ terrainExaggeration?: number;
38
+ maximumScreenSpaceError?: number;
39
+ maximumNumberOfLoadedTiles?: number;
40
+ token?: string;
41
+ }
42
+ interface MapCenter {
43
+ latitude: number;
44
+ longitude: number;
45
+ height: number;
46
+ pitch?: number;
47
+ heading?: number;
48
+ }
49
+ export declare function initCesium(containerId: string, options: InitOptions, mapCenter?: MapCenter): Promise<{
50
+ viewer: CesiumViewer;
51
+ initialCenter: MapCenter;
52
+ }>;
53
+ export {};
@@ -0,0 +1,154 @@
1
+ import { Cartesian3, Cartographic, Color } from '../../node_modules/cesium';
2
+ import * as Cesium from 'cesium';
3
+ export interface ToolbarConfig {
4
+ position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
5
+ buttonSize?: number;
6
+ buttonSpacing?: number;
7
+ backgroundColor?: string;
8
+ borderColor?: string;
9
+ borderRadius?: number;
10
+ borderWidth?: number;
11
+ boxShadow?: string;
12
+ zIndex?: number;
13
+ buttons?: CustomButtonConfig[];
14
+ }
15
+ export interface ButtonConfig {
16
+ id: string;
17
+ icon: string;
18
+ title: string;
19
+ size?: number;
20
+ color?: string;
21
+ borderColor?: string;
22
+ borderWidth?: number;
23
+ borderStyle?: string;
24
+ hoverColor?: string;
25
+ activeColor?: string;
26
+ backgroundColor?: string;
27
+ callback?: () => void;
28
+ activeIcon?: string | HTMLElement;
29
+ }
30
+ export interface CustomButtonConfig {
31
+ id: string;
32
+ icon: string | HTMLElement | false;
33
+ title: string;
34
+ enabled?: boolean;
35
+ visible?: boolean;
36
+ size?: number;
37
+ color?: string;
38
+ borderColor?: string;
39
+ borderWidth?: number;
40
+ borderStyle?: string;
41
+ padding?: string;
42
+ hoverColor?: string;
43
+ activeColor?: string;
44
+ backgroundColor?: string;
45
+ activeIcon?: string | HTMLElement | false;
46
+ onClick?: (buttonId: string, buttonElement: HTMLElement) => void;
47
+ }
48
+ export interface SearchCallback {
49
+ onSearch?: (query: string) => Promise<SearchResult[]>;
50
+ onSelect?: (result: SearchResult) => void;
51
+ onSearchInput?: (query: string, container: HTMLElement) => void;
52
+ onSearchResults?: (results: SearchResult[], container: HTMLElement) => void;
53
+ }
54
+ export interface SearchResult {
55
+ name: string;
56
+ address: string;
57
+ longitude: number;
58
+ latitude: number;
59
+ height?: number;
60
+ }
61
+ export interface MeasurementCallback {
62
+ onDistanceComplete?: (positions: Cartesian3[], distance: number) => void;
63
+ onAreaComplete?: (positions: Cartesian3[], area: number) => void;
64
+ onClear?: () => void;
65
+ }
66
+ export interface ZoomCallback {
67
+ onZoomIn?: (beforeLevel: number, afterLevel: number) => void;
68
+ onZoomOut?: (beforeLevel: number, afterLevel: number) => void;
69
+ }
70
+ export interface MapType {
71
+ id: string;
72
+ name: string;
73
+ thumbnail: string;
74
+ provider: (token: string) => Cesium.ImageryProvider[];
75
+ }
76
+ export interface MapToolsConfig {
77
+ containerId: string;
78
+ viewerOptions?: Cesium.Viewer.ConstructorOptions;
79
+ mapCenter?: {
80
+ longitude: number;
81
+ latitude: number;
82
+ height: number;
83
+ pitch?: number;
84
+ heading?: number;
85
+ };
86
+ zoomLevels?: number[];
87
+ defaultZoom?: number;
88
+ }
89
+ /**
90
+ * 点位绘制选项
91
+ */
92
+ export interface PointOptions {
93
+ pixelSize?: number;
94
+ color?: Color;
95
+ outlineColor?: Color;
96
+ outlineWidth?: number;
97
+ showLabel?: boolean;
98
+ labelText?: string;
99
+ onClick?: (position: Cartesian3, cartographic: Cartographic) => void;
100
+ }
101
+ /**
102
+ * 线条绘制选项
103
+ */
104
+ export interface LineOptions {
105
+ width?: number;
106
+ material?: Cesium.MaterialProperty | Color;
107
+ showDistance?: boolean;
108
+ dashPattern?: number;
109
+ onClick?: (positions: Cartesian3[], distance: number) => void;
110
+ }
111
+ /**
112
+ * 多边形绘制选项
113
+ */
114
+ export interface PolygonOptions {
115
+ material?: Cesium.MaterialProperty | Color;
116
+ outline?: boolean;
117
+ outlineColor?: Color;
118
+ outlineWidth?: number;
119
+ showArea?: boolean;
120
+ dashPattern?: number;
121
+ onClick?: (positions: Cartesian3[], area: number) => void;
122
+ }
123
+ export interface OverlayOptions {
124
+ position: Cartesian3;
125
+ type: 'point' | 'label' | 'billboard' | 'model' | 'cylinder';
126
+ point?: {
127
+ pixelSize?: number;
128
+ color?: Color;
129
+ outlineColor?: Color;
130
+ outlineWidth?: number;
131
+ };
132
+ label?: {
133
+ text: string;
134
+ font?: string;
135
+ fillColor?: Color;
136
+ outlineColor?: Color;
137
+ outlineWidth?: number;
138
+ };
139
+ billboard?: {
140
+ image: string;
141
+ scale?: number;
142
+ };
143
+ model?: {
144
+ uri: string;
145
+ scale?: number;
146
+ };
147
+ cylinder?: {
148
+ length: number;
149
+ topRadius: number;
150
+ bottomRadius: number;
151
+ material?: Color;
152
+ };
153
+ }
154
+ export * as Cesium from '../../node_modules/cesium';
@@ -0,0 +1,180 @@
1
+ import { Viewer } from '../../node_modules/cesium';
2
+ import { MapType, ToolbarConfig, SearchCallback, MeasurementCallback, ZoomCallback, CustomButtonConfig } from './CesiumMapModel';
3
+ /**
4
+ * Cesium地图工具栏类
5
+ * 提供搜索、测量、2D/3D切换、图层切换、定位、缩放、全屏等功能
6
+ */
7
+ export declare class CesiumMapToolbar {
8
+ private viewer;
9
+ private drawHelper;
10
+ private container;
11
+ private toolbarElement;
12
+ private config;
13
+ private searchCallback?;
14
+ private measurementCallback?;
15
+ private zoomCallback?;
16
+ private initialCenter?;
17
+ private isFullscreen;
18
+ private currentMapType;
19
+ TD_Token: string;
20
+ mapTypes: MapType[];
21
+ constructor(viewer: Viewer, container: HTMLElement, config?: ToolbarConfig, callbacks?: {
22
+ search?: SearchCallback;
23
+ measurement?: MeasurementCallback;
24
+ zoom?: ZoomCallback;
25
+ }, initialCenter?: {
26
+ longitude: number;
27
+ latitude: number;
28
+ height: number;
29
+ });
30
+ setMapTypes(mapTypes: MapType[]): void;
31
+ setTDToken(TD_Token: string): void;
32
+ /**
33
+ * 设置初始中心点
34
+ */
35
+ setInitialCenter(center: {
36
+ longitude: number;
37
+ latitude: number;
38
+ height: number;
39
+ }): void;
40
+ /**
41
+ * 获取初始中心点
42
+ */
43
+ getInitialCenter(): {
44
+ longitude: number;
45
+ latitude: number;
46
+ height: number;
47
+ } | undefined;
48
+ /**
49
+ * 复位到初始位置(公共方法)
50
+ */
51
+ resetToInitialLocation(): void;
52
+ /**
53
+ * 更新按钮配置
54
+ */
55
+ updateButtonConfig(buttonId: string, config: Partial<CustomButtonConfig>): void;
56
+ /**
57
+ * 添加自定义按钮
58
+ */
59
+ addCustomButton(config: CustomButtonConfig): void;
60
+ /**
61
+ * 移除按钮
62
+ */
63
+ removeButton(buttonId: string): void;
64
+ /**
65
+ * 获取按钮元素
66
+ */
67
+ getButtonElement(buttonId: string): HTMLElement | null;
68
+ /**
69
+ * 设置绘图助手回调
70
+ */
71
+ private setupDrawHelperCallbacks;
72
+ /**
73
+ * 计算多边形面积
74
+ */
75
+ private calculatePolygonArea;
76
+ /**
77
+ * 创建工具栏
78
+ */
79
+ private createToolbar;
80
+ /**
81
+ * 获取按钮配置
82
+ */
83
+ private getButtonConfigs;
84
+ /**
85
+ * 创建按钮
86
+ */
87
+ private createButton;
88
+ /**
89
+ * 设置按钮图标
90
+ */
91
+ private setButtonIcon;
92
+ /**
93
+ * 判断是否为图片路径
94
+ */
95
+ private isImagePath;
96
+ /**
97
+ * 加载图片图标
98
+ */
99
+ private loadImageIcon;
100
+ /**
101
+ * 设置默认图标(当图片加载失败时)
102
+ */
103
+ private setDefaultIcon;
104
+ /**
105
+ * 设置按钮事件
106
+ */
107
+ private setupButtonEvents;
108
+ /**
109
+ * 按钮鼠标离开时关闭菜单
110
+ */
111
+ private closeMenuOnButtonLeave;
112
+ /**
113
+ * 处理按钮点击
114
+ */
115
+ private handleButtonClick;
116
+ /**
117
+ * 切换搜索功能
118
+ */
119
+ private toggleSearch;
120
+ /**
121
+ * 显示搜索结果
122
+ */
123
+ private displaySearchResults;
124
+ /**
125
+ * 选择搜索结果
126
+ */
127
+ private selectSearchResult;
128
+ /**
129
+ * 默认搜索逻辑
130
+ */
131
+ private performDefaultSearch;
132
+ /**
133
+ * 切换测量功能
134
+ */
135
+ private toggleMeasurement;
136
+ /**
137
+ * 处理测量操作
138
+ */
139
+ private handleMeasurementAction;
140
+ /**
141
+ * 切换2D/3D视图
142
+ */
143
+ private toggle2D3D;
144
+ /**
145
+ * 切换图层
146
+ */
147
+ private toggleLayers;
148
+ /**
149
+ * 切换地图类型
150
+ */
151
+ private switchMapType;
152
+ /**
153
+ * 复位到初始位置
154
+ */
155
+ private resetLocation;
156
+ /**
157
+ * 放大
158
+ */
159
+ private zoomIn;
160
+ /**
161
+ * 缩小
162
+ */
163
+ private zoomOut;
164
+ /**
165
+ * 切换全屏
166
+ */
167
+ private toggleFullscreen;
168
+ /**
169
+ * 进入全屏
170
+ */
171
+ private enterFullscreen;
172
+ /**
173
+ * 退出全屏
174
+ */
175
+ private exitFullscreen;
176
+ /**
177
+ * 销毁工具栏
178
+ */
179
+ destroy(): void;
180
+ }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingm/vmap-cesium-toolbar",
3
- "version": "0.0.1-beta.5",
3
+ "version": "0.0.1-beta.7",
4
4
  "description": "A powerful Cesium map toolbar plugin with drawing, measurement, and interaction features",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingm/vmap-cesium-toolbar",
3
- "version": "0.0.1-beta.6",
3
+ "version": "0.0.1-beta.7",
4
4
  "description": "A powerful Cesium map toolbar plugin with drawing, measurement, and interaction features",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -41,6 +41,7 @@
41
41
  "rollup-plugin-dts": "^6.1.0",
42
42
  "vite": "^7.1.2",
43
43
  "vite-plugin-cesium": "^1.2.23",
44
+ "vite-plugin-dts": "^4.5.4",
44
45
  "vite-plugin-static-copy": "^3.1.2",
45
46
  "vue-tsc": "^3.0.5"
46
47
  },