@xingm/vmap-cesium-toolbar 0.0.2-alpha.7 → 0.0.2-alpha.9

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,79 @@
1
+ import * as Cesium from "cesium";
2
+ export interface HeatPoint {
3
+ /** 经度(度) */
4
+ lon: number;
5
+ /** 纬度(度) */
6
+ lat: number;
7
+ /** 强度值,用于控制热度(0~maxValue) */
8
+ value: number;
9
+ }
10
+ export interface HeatmapGradient {
11
+ /**
12
+ * 0~1 的比例到颜色字符串的映射,例如:
13
+ * { 0.0: "#0000ff", 0.5: "#ffff00", 1.0: "#ff0000" }
14
+ */
15
+ [stop: number]: string;
16
+ }
17
+ export interface HeatmapOptions {
18
+ /** Canvas 分辨率,越大越清晰但开销越大 */
19
+ width?: number;
20
+ height?: number;
21
+ /** 单个点的影响半径(像素) */
22
+ radius?: number;
23
+ /** 最小/最大值,用于归一化 value,如果不传则自动根据数据计算 */
24
+ minValue?: number;
25
+ maxValue?: number;
26
+ /** 全局不透明度 0~1 */
27
+ opacity?: number;
28
+ /** 颜色梯度 */
29
+ gradient?: HeatmapGradient;
30
+ }
31
+ /**
32
+ * Cesium 热力图图层封装
33
+ * - 使用离屏 Canvas 绘制热力图
34
+ * - 通过 SingleTileImageryProvider 叠加到地球上
35
+ */
36
+ export default class CesiumHeatmapLayer {
37
+ private viewer;
38
+ private imageryLayer;
39
+ private rectangle;
40
+ private canvas;
41
+ private ctx;
42
+ private options;
43
+ private data;
44
+ private gradientLUT;
45
+ constructor(viewer: Cesium.Viewer, options?: HeatmapOptions);
46
+ /**
47
+ * 设置/替换热力图数据(度为单位)
48
+ */
49
+ setData(points: HeatPoint[]): void;
50
+ /**
51
+ * 更新调色板
52
+ */
53
+ setGradient(gradient: HeatmapGradient): void;
54
+ /**
55
+ * 设置透明度
56
+ */
57
+ setOpacity(opacity: number): void;
58
+ /**
59
+ * 显隐控制
60
+ */
61
+ setVisible(visible: boolean): void;
62
+ /**
63
+ * 销毁并移除图层
64
+ */
65
+ destroy(): void;
66
+ private clearLayer;
67
+ /**
68
+ * 构建颜色查找表(0-255 -> RGBA)
69
+ */
70
+ private buildGradientLUT;
71
+ /**
72
+ * 在离屏 canvas 上绘制热力图,并更新到 Cesium 图层
73
+ */
74
+ private renderHeatmap;
75
+ /**
76
+ * 将当前 canvas 映射为 Cesium 影像图层
77
+ */
78
+ private updateImageryLayer;
79
+ }
@@ -9,7 +9,6 @@ declare class DrawHelper {
9
9
  private viewer;
10
10
  private scene;
11
11
  private entities;
12
- private frustumPrimitives;
13
12
  private drawMode;
14
13
  private isDrawing;
15
14
  private tempPositions;
@@ -20,6 +19,8 @@ declare class DrawHelper {
20
19
  private finishedPointEntities;
21
20
  private publicEntities;
22
21
  private _doubleClickPending;
22
+ private lastPreviewPosition;
23
+ private static activeDrawingHelper;
23
24
  private drawLine;
24
25
  private drawPolygon;
25
26
  private drawRectangle;
@@ -86,11 +87,6 @@ declare class DrawHelper {
86
87
  * 删除最后一个添加的点及其相关的临时实体
87
88
  */
88
89
  private removeLastPoint;
89
- /**
90
- * 重新创建剩余的点实体和绘制实体
91
- * 用于右键删除点后的重建
92
- */
93
- private recreateRemainingEntities;
94
90
  /**
95
91
  * 更新预览线/面
96
92
  * @param currentMousePosition 当前鼠标位置世界坐标
@@ -114,6 +110,12 @@ declare class DrawHelper {
114
110
  * 公共方法:结束当前绘制(如果正在进行)
115
111
  */
116
112
  endDrawing(): void;
113
+ /**
114
+ * 公共方法:取消当前正在进行的绘制(不触发完成回调,不生成实体)
115
+ * 主要用于在外部开启新的绘制前,保证旧的未完成绘制被安全终止,
116
+ * 避免同时存在多个绘制事件处理器。
117
+ */
118
+ cancelDrawing(): void;
117
119
  /**
118
120
  * 销毁事件处理器
119
121
  */
@@ -142,15 +144,6 @@ declare class DrawHelper {
142
144
  * @returns 实体数组
143
145
  */
144
146
  getFinishedEntities(): Cesium.Entity[];
145
- /**
146
- * 使用 Canvas 绘制总长文本,生成用于 billboard 的图片
147
- */
148
- private createTotalLengthBillboardImage;
149
- /**
150
- * 使用 Canvas 绘制分段长度文本,生成用于 billboard 的图片
151
- * 样式与总长保持一致,便于统一视觉
152
- */
153
- private createSegmentLengthBillboardImage;
154
147
  onMeasureComplete(callback: (result: {
155
148
  type: "line" | "polygon" | "rectangle" | "circle";
156
149
  positions: Cesium.Cartesian3[];
@@ -40,6 +40,7 @@ interface InitOptions {
40
40
  terrainExaggeration?: number;
41
41
  maximumScreenSpaceError?: number;
42
42
  maximumNumberOfLoadedTiles?: number;
43
+ requestRenderMode?: boolean;
43
44
  token?: string;
44
45
  cesiumToken?: string;
45
46
  success?: () => void;
@@ -53,6 +54,8 @@ interface MapCenter {
53
54
  pitch?: number;
54
55
  heading?: number;
55
56
  }
57
+ export declare const setCameraView: (viewer: CesiumViewer, center: MapCenter) => void;
58
+ export declare const setCameraFlyTo: (viewer: CesiumViewer, center: MapCenter, options: InitOptions) => void;
56
59
  export declare function initCesium(containerId: string, options: InitOptions, mapCenterOrCesiumToken?: MapCenter | string, cesiumToken?: string): Promise<{
57
60
  viewer: CesiumViewer;
58
61
  initialCenter: MapCenter;
@@ -8,6 +8,7 @@ import { MapPolyline, PolylineOptions } from './overlay/MapPolyline';
8
8
  import { MapPolygon, PolygonOptions } from './overlay/MapPolygon';
9
9
  import { MapRectangle, RectangleOptions } from './overlay/MapRectangle';
10
10
  import { MapCircle, CircleOptions } from './overlay/MapCircle';
11
+ import { MapRing, RingOptions } from './overlay/MapRing';
11
12
  import { OverlayPosition } from './overlay/types';
12
13
  /**
13
14
  * Cesium 覆盖物服务类
@@ -27,6 +28,7 @@ export declare class CesiumOverlayService {
27
28
  readonly polygon: MapPolygon;
28
29
  readonly rectangle: MapRectangle;
29
30
  readonly circle: MapCircle;
31
+ readonly ring: MapRing;
30
32
  constructor(viewer: Viewer);
31
33
  /**
32
34
  * 初始化信息窗口容器
@@ -76,6 +78,10 @@ export declare class CesiumOverlayService {
76
78
  * 添加 Circle
77
79
  */
78
80
  addCircle(options: CircleOptions): Entity;
81
+ /**
82
+ * 添加 Ring
83
+ */
84
+ addRing(options: RingOptions): Entity;
79
85
  /**
80
86
  * 根据ID获取覆盖物
81
87
  */
@@ -15,10 +15,31 @@ export interface DrawResult {
15
15
  */
16
16
  export interface DrawCallbacks {
17
17
  onDrawStart?: () => void;
18
- onDrawEnd?: (entity: Entity | null) => void;
18
+ onDrawEnd?: (entity: Entity | null, result: DrawResult) => void;
19
19
  onEntityRemoved?: (entity: Entity) => void;
20
20
  onMeasureComplete?: (result: DrawResult) => void;
21
21
  }
22
+ /**
23
+ * 扩展后的绘制实体类型
24
+ * 用于在 Entity 上挂载绘图相关的元数据
25
+ */
26
+ export type DrawEntity = Entity & {
27
+ _drawType?: "line" | "polygon" | "rectangle" | "circle";
28
+ _drawOptions?: DrawOptions;
29
+ _groundPositions?: Cartesian3[];
30
+ _groundPosition?: Cartesian3;
31
+ _groundRectangle?: Cesium.Rectangle;
32
+ _radius?: number;
33
+ _borderEntity?: Entity;
34
+ _onClick?: (entity: Entity, ...args: any[]) => void;
35
+ _isSelected?: boolean;
36
+ _originalStyle?: {
37
+ material?: any;
38
+ width?: any;
39
+ outlineColor?: any;
40
+ outlineWidth?: any;
41
+ };
42
+ };
22
43
  /**
23
44
  * 绘制时可选的样式和事件回调
24
45
  */
@@ -58,16 +79,44 @@ export declare abstract class BaseDraw {
58
79
  protected finishedPointEntities: Cesium.Entity[];
59
80
  /** 当前绘制的选项(如果有) */
60
81
  protected drawOptions?: DrawOptions;
82
+ /**
83
+ * 公开只读访问当前临时数据,供调度器使用
84
+ */
85
+ getTempPositions(): Cartesian3[];
86
+ getTempEntities(): Entity[];
87
+ getTempLabelEntities(): Entity[];
88
+ getFinishedPointEntities(): Entity[];
89
+ /**
90
+ * 允许调度器安全地重建临时数据
91
+ */
92
+ setTempPositions(positions: Cartesian3[]): void;
93
+ setTempEntities(entities: Entity[]): void;
94
+ setTempLabelEntities(entities: Entity[]): void;
95
+ /**
96
+ * 供调度器调用的公开包装方法
97
+ */
98
+ addPointForHelper(position: Cartesian3): void;
99
+ clearTempEntitiesForHelper(): void;
100
+ /**
101
+ * 清除当前绘制过程中的临时点实体
102
+ * 仅删除带有 point 组件的临时实体,保留其它临时线/面实体
103
+ */
104
+ clearTempPointEntitiesForHelper(): void;
105
+ /**
106
+ * 删除最后一个点并根据剩余点重建预览实体
107
+ * 供调度器在右键删除点时调用,具体重建逻辑仍由各子类的 updateDrawingEntity 实现
108
+ */
109
+ removeLastPointAndRedraw(): void;
61
110
  /**
62
111
  * 将任意颜色输入解析为 Cesium.Color
63
112
  */
64
113
  protected resolveColor(input?: Cesium.Color | string): Cesium.Color;
65
114
  /**
66
- * 应用选中样式(可切换)
115
+ * 应用/切换选中样式(统一逻辑,供调度器和子类共用)
67
116
  */
68
117
  protected applySelectedStyleToEntity(entity: Entity): void;
69
118
  /**
70
- * 恢复原始样式
119
+ * 恢复原始样式(兼容旧接口,内部仍走统一逻辑)
71
120
  */
72
121
  protected restoreOriginalStyleForEntity(entity: Entity): void;
73
122
  abstract updateDrawingEntity(previewPoint?: Cesium.Cartesian3): void;
@@ -114,3 +163,8 @@ export declare abstract class BaseDraw {
114
163
  */
115
164
  protected clearTempEntities(): void;
116
165
  }
166
+ /**
167
+ * 静态工具方法:切换实体的选中样式
168
+ * 用于避免在多个模块中重复实现相同逻辑
169
+ */
170
+ export declare function toggleSelectedStyle(entity: DrawEntity): void;
@@ -18,6 +18,10 @@ export declare class DrawPolygon extends BaseDraw {
18
18
  * 完成绘制
19
19
  */
20
20
  finishDrawing(): DrawResult | null;
21
+ /**
22
+ * 清理所有绘制相关的实体
23
+ */
24
+ clear(): void;
21
25
  /**
22
26
  * 获取绘制类型
23
27
  */
@@ -1,4 +1,4 @@
1
- export { BaseDraw, type DrawResult, type DrawCallbacks, type DrawOptions } from './BaseDraw';
1
+ export { BaseDraw, type DrawResult, type DrawCallbacks, type DrawOptions, type DrawEntity, toggleSelectedStyle } from './BaseDraw';
2
2
  export { DrawLine } from './DrawLine';
3
3
  export { DrawPolygon } from './DrawPolgon';
4
4
  export { DrawRectangle } from './DrawRectangle';
@@ -0,0 +1,95 @@
1
+ import { Viewer, Entity, Color } from '../../../node_modules/cesium';
2
+ import { OverlayPosition } from './types';
3
+ /**
4
+ * Ring(边缘发光圆环)选项
5
+ */
6
+ export interface RingOptions {
7
+ /** 中心点(经纬度/高度 或 Cartesian3) */
8
+ position: OverlayPosition;
9
+ /** 半径(米) */
10
+ radius: number;
11
+ /** 边缘发光颜色 */
12
+ color?: Color | string;
13
+ /** 是否绘制内层线(默认 true)。关闭可去掉“白色芯子” */
14
+ showInnerLine?: boolean;
15
+ /** 实线颜色 */
16
+ lineColor?: Color | string;
17
+ /** 内层线型:实线/虚线(默认 solid) */
18
+ lineStyle?: "solid" | "dashed";
19
+ /** 虚线材质方案:stripe(默认) / dash */
20
+ lineMaterialMode?: "stripe" | "dash";
21
+ /** stripe 模式:条纹重复次数(默认 32) */
22
+ stripeRepeat?: number;
23
+ /** 虚线长度(像素,默认 16) */
24
+ dashLength?: number;
25
+ /** 虚线模式(16bit pattern,可选) */
26
+ dashPattern?: number;
27
+ /** 虚线间隙颜色(默认透明) */
28
+ gapColor?: Color | string;
29
+ /** 线宽(像素) */
30
+ width?: number;
31
+ /** 外层发光线宽(像素)。优先于 width */
32
+ glowWidth?: number;
33
+ /** 内层实线线宽(像素)。不传则使用自动计算 */
34
+ lineWidth?: number;
35
+ /** 发光强度(0-1),越大越“亮/粗” */
36
+ glowPower?: number;
37
+ /** 是否贴地(默认 true) */
38
+ clampToGround?: boolean;
39
+ /** 圆环分段数(默认 128),越大越圆滑 */
40
+ segments?: number;
41
+ /** 覆盖物点击回调 */
42
+ onClick?: (entity: Entity) => void;
43
+ id?: string;
44
+ }
45
+ /**
46
+ * Ring 工具类:使用 polyline + PolylineGlowMaterialProperty 实现发光圆环
47
+ */
48
+ export declare class MapRing {
49
+ private viewer;
50
+ private entities;
51
+ constructor(viewer: Viewer);
52
+ /**
53
+ * 转换位置为 Cartesian3
54
+ */
55
+ private convertPosition;
56
+ /**
57
+ * 转换颜色
58
+ */
59
+ private resolveColor;
60
+ private resolveLineMaterial;
61
+ private resolveGlowMaterial;
62
+ private getInnerWidth;
63
+ private addInnerEntity;
64
+ private removeInnerEntity;
65
+ private rebuildRingPositions;
66
+ /**
67
+ * 生成近似圆顶点(Cartesian3 数组)。segments 越大越平滑。
68
+ * 这里沿用 MapCircle 的大圆航线近似,保证在经纬度空间更稳定。
69
+ */
70
+ private generateCirclePositions;
71
+ /**
72
+ * 添加 Ring(边缘发光圆环)
73
+ */
74
+ add(options: RingOptions): Entity;
75
+ /**
76
+ * 更新 Ring 中心
77
+ */
78
+ updatePosition(entity: Entity, position: OverlayPosition): void;
79
+ /**
80
+ * 更新 Ring 半径
81
+ */
82
+ updateRadius(entity: Entity, radius: number): void;
83
+ /**
84
+ * 更新 Ring 样式
85
+ */
86
+ updateStyle(entity: Entity, options: Partial<Pick<RingOptions, "color" | "showInnerLine" | "lineColor" | "lineStyle" | "lineMaterialMode" | "stripeRepeat" | "dashLength" | "dashPattern" | "gapColor" | "width" | "glowWidth" | "lineWidth" | "glowPower" | "clampToGround" | "segments">>): void;
87
+ /**
88
+ * 显示/隐藏 Ring
89
+ */
90
+ setVisible(entity: Entity, visible: boolean): void;
91
+ /**
92
+ * 移除 Ring(通过实体或实体 id)
93
+ */
94
+ remove(entityOrId: Entity | string): boolean;
95
+ }
@@ -8,6 +8,7 @@ export { MapPolyline } from './MapPolyline';
8
8
  export { MapPolygon } from './MapPolygon';
9
9
  export { MapRectangle } from './MapRectangle';
10
10
  export { MapCircle } from './MapCircle';
11
+ export { MapRing } from './MapRing';
11
12
  export type { OverlayPosition } from './types';
12
13
  export type { MarkerOptions } from './MapMarker';
13
14
  export type { LabelOptions } from './MapLabel';
@@ -18,3 +19,4 @@ export type { PolylineOptions } from './MapPolyline';
18
19
  export type { PolygonOptions } from './MapPolygon';
19
20
  export type { RectangleOptions } from './MapRectangle';
20
21
  export type { CircleOptions } from './MapCircle';
22
+ export type { RingOptions } from './MapRing';
@@ -1,5 +1,41 @@
1
- import { Cartesian3 } from '../../../node_modules/cesium';
1
+ import { Cartesian3, Entity, Color, MaterialProperty, Rectangle, Cartographic } from '../../../node_modules/cesium';
2
2
  /**
3
3
  * 覆盖物位置类型
4
4
  */
5
5
  export type OverlayPosition = Cartesian3 | [number, number] | [number, number, number];
6
+ /**
7
+ * 覆盖物扩展实体类型
8
+ * 用于在 Cesium.Entity 上挂载覆盖物相关的元数据
9
+ */
10
+ export interface OverlayEntity extends Entity {
11
+ /** 覆盖物点击回调(由各 Map* 工具类设置) */
12
+ _onClick?: (entity: Entity) => void;
13
+ /** 覆盖物类型标识(用于 CesiumOverlayService 做差异化更新/删除) */
14
+ _overlayType?: string;
15
+ /** 信息窗口根 DOM(由 MapInfoWindow / CesiumOverlayService 使用) */
16
+ _infoWindow?: HTMLElement;
17
+ /** 复合图形的内层实体或边框实体等关联引用 */
18
+ _borderEntity?: Entity;
19
+ _innerEntity?: Entity;
20
+ /** 粗边框 / 环形等形状相关元数据 */
21
+ _isThickOutline?: boolean;
22
+ _outlineWidth?: number;
23
+ _isRing?: boolean;
24
+ _ringThickness?: number;
25
+ _ringSegments?: number;
26
+ _ringGlowPower?: number;
27
+ _ringLineColor?: Color | string;
28
+ _ringLineStyle?: 'solid' | 'dashed';
29
+ _ringLineMaterialMode?: 'stripe' | 'dash';
30
+ _ringStripeRepeat?: number;
31
+ _ringDashLength?: number;
32
+ _ringDashPattern?: number;
33
+ _ringGapColor?: Color | string;
34
+ _ringShowInnerLine?: boolean;
35
+ _fillMaterial?: MaterialProperty | Color | string;
36
+ _ringHeightEpsilon?: number;
37
+ _centerCartographic?: Cartographic;
38
+ _outerRadius?: number;
39
+ _innerRadius?: number;
40
+ _outerRectangle?: Rectangle;
41
+ }
@@ -27,6 +27,7 @@ export declare class MapLayersService {
27
27
  * 更新配置
28
28
  */
29
29
  updateConfig(config: Partial<MapLayersServiceConfig>): void;
30
+ adjustMenuPosition: (menu: HTMLElement) => void;
30
31
  /**
31
32
  * 切换图层菜单
32
33
  */
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingm/vmap-cesium-toolbar",
3
- "version": "0.0.2-alpha.6",
3
+ "version": "0.0.2-alpha.9",
4
4
  "description": "A powerful Cesium map toolbar plugin with drawing, measurement, and interaction features",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,24 @@
1
+ export declare const defaultHeatmapData: ({
2
+ lon: string;
3
+ lat: string;
4
+ height: string;
5
+ appearTime: number;
6
+ lng?: undefined;
7
+ } | {
8
+ lng: string;
9
+ lat: string;
10
+ height: string;
11
+ appearTime: number;
12
+ lon?: undefined;
13
+ })[][];
14
+ export declare const defaultHeatmapColors: {
15
+ 0: string;
16
+ 40: string;
17
+ 60: string;
18
+ 90: string;
19
+ 110: string;
20
+ };
21
+ export declare const defaultHeatmapOpacity: {
22
+ 0: number;
23
+ 0.5: number;
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingm/vmap-cesium-toolbar",
3
- "version": "0.0.2-alpha.7",
3
+ "version": "0.0.2-alpha.9",
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",