cesium标绘插件
Go to file
2024-03-23 18:45:05 +08:00
debug To incorporate double-arrow animation. 2024-03-23 18:45:05 +08:00
src To incorporate double-arrow animation. 2024-03-23 18:45:05 +08:00
.eslintrc.js Enhancing TypeScript Type Checking 2023-08-22 20:07:59 +08:00
.gitignore init 2023-08-08 15:41:52 +08:00
.prettierrc.cjs draw a fineArrow 2023-08-09 17:55:29 +08:00
CHANGELOG.md add changelog 2024-03-17 10:49:53 +08:00
index.html To incorporate double-arrow animation. 2024-03-23 18:45:05 +08:00
LICENSE Update LICENSE 2023-08-04 18:17:50 +08:00
package-lock.json show or hide with animation 2024-03-16 22:03:36 +08:00
package.json show or hide with animation 2024-03-16 22:03:36 +08:00
README.md Unified display and hidden control method 2024-03-17 10:10:52 +08:00
tsconfig.json Adjusting the introduction of cesium 2024-02-23 15:41:39 +08:00
tsconfig.node.json Adjusting the introduction of cesium 2024-02-23 15:41:39 +08:00
vite.config.ts Add export es module 2024-03-15 17:42:36 +08:00

cesium-plot-js

cesium 军事标绘插件,支持绘制多边形、曲线、箭头等图形

image

在线示例demo

CDN

  1. 引入文件
<script src="https://unpkg.com/cesium-plot-js"></script>
  1. 调用绘制 api
  new CesiumPlot.FineArrow(Cesium, viewer);

NPM

  1. install
npm i cesium-plot-js
  1. import
import CesiumPlot from 'cesium-plot-js';
  1. 调用绘制 api
  new CesiumPlot.FineArrow(Cesium, viewer);

Classes

每个图形为独立的类,绑定事件或其他操作通过类的实例来实现

类名 类型 描述
Polygon 'polygon' 多边形
Reactangle 'polygon' 矩形
Triangle 'polygon' 三角形
Circle 'polygon' 圆形
StraightArrow 'line' 细直箭头
CurvedArrow 'line' 曲线箭头
FineArrow 'polygon' 直箭头
AttackArrow 'polygon' 进攻方向箭头
SwallowtailAttackArrow 'polygon' 燕尾进攻方向箭头
SquadCombat 'polygon' 分队战斗方向
SwallowtailSquadCombat 'polygon' 燕尾分队战斗方向
AssaultDirection 'polygon' 突击方向
DoubleArrow 'polygon' 双箭头
FreehandLine 'line' 自由线
FreehandPolygon 'polygon' 自由面
Curve 'line' 曲线
Ellipse 'polygon' 椭圆
Lune 'polygon' 半月面

构造函数

所有图形的构造函数:

<类名>(cesium: Cesium, viewer: Cesium.Viewer, style?: PolygonStyle | LineStyle)

PolygonStyle类型
{
  material?: Cesium.MaterialProperty;
  outlineWidth?: number;
  outlineMaterial?: Cesium.MaterialProperty;
};
LineStyle类型
{
  material?: Cesium.Color;
  lineWidth?: number;
};

示例

// 初始化viewer
const viewer = new Cesium.Viewer('cesiumContainer');
// 抗锯齿
viewer.scene.postProcessStages.fxaa.enabled = true;
// 设置自定义样式
const geometry = new CesiumPlot.FineArrow(Cesium, viewer, {
  material: Cesium.Color.fromCssColorString('rgba(59, 178, 208, 0.5)'),
  outlineMaterial: Cesium.Color.fromCssColorString('rgba(59, 178, 208, 1)'),
  outlineWidth: 3,
});

类的实例方法

方法名 参数 描述
hide options?: VisibleAnimationOpts 隐藏options 可配置过度动画,参数缺省时,不显示动画
show options?: VisibleAnimationOpts 显示options 可配置过度动画,参数缺省时,不显示动画
remove 删除
on (event: EventType, listener: (eventData?: any) => void) 绑定事件
off (event: EventType) 解绑事件
VisibleAnimationOpts类型
{
  duration?: number;      // 动画持续时间ms,默认1000
  delay?: number;         // 动画延迟启动时间ms默认0
  callback?: (() => void) // 动画结束回调
};
// 隐藏图形
const geometry = new CesiumPlot.Reactangle(Cesium, viewer);
geometry.hide();
// 绑定事件
const geometry = new CesiumPlot.Reactangle(Cesium, viewer);
geometry.on('drawEnd', (data)=>{
  console.log(data)
});

Events

  • drawStart

绘制开始

  • drawUpdate

绘制过程中点位更新,回调事件返回更新的 Cartesian3 点位

  • drawEnd

绘制结束,回调事件返回图形的关键点位

geometry.on('drawEnd', (data) => {
  console.log(data);
});
  • editStart

编辑开始

  • editEnd

编辑结束,回调事件返回图形的关键点位