|
@@ -0,0 +1,160 @@
|
|
|
+/* 引入Cesium */
|
|
|
+// import * as Cesium from 'Cesium';
|
|
|
+
|
|
|
+import {
|
|
|
+ setSessionid
|
|
|
+} from "./common/common.js";
|
|
|
+
|
|
|
+/**
|
|
|
+ *流动纹理
|
|
|
+ */
|
|
|
+import CircleMaterialProperty from "./CircleObject/CircleMaterialProperty.js";
|
|
|
+import CircleRippleMaterialProperty from "./CircleObject/CircleRippleMaterialProperty.js";
|
|
|
+
|
|
|
+/**
|
|
|
+ * 墙体对象
|
|
|
+ */
|
|
|
+class CircleObject {
|
|
|
+ /**
|
|
|
+ * 默认初始化
|
|
|
+ */
|
|
|
+ constructor(viewer) {
|
|
|
+ if (!viewer) throw new Cesium.DeveloperError('no viewer object!');
|
|
|
+ this._viewer = viewer;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 通用对外公开函数
|
|
|
+ */
|
|
|
+Object.assign(CircleObject.prototype, /** @lends CircleObject.prototype */ {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 绘制动态圆
|
|
|
+ * @param {String} centerPoint 圆心坐标
|
|
|
+ * @param {String} radius 圆半径
|
|
|
+ * @param {Object} [options] 圆的样式,具有以下属性:
|
|
|
+ * @param {Number} [options.id] 用于移除
|
|
|
+ * @param {Number} [options.clampToGround=true] 是否贴地
|
|
|
+ * @param {String} [options.color="#FF0000"] 指定圆的颜色
|
|
|
+
|
|
|
+ * @param {String} [options.outlineColor="#FFFF00"] 指定点轮廓的颜色
|
|
|
+ * @param {Number} [options.outlineWidth=0] 指定点轮廓的宽度
|
|
|
+ *
|
|
|
+ * @param {Number} [options.CircleType='ColorCircle'] ColorCircle / DynamicCircle
|
|
|
+ * @param {Number} [options.duration=3000] 持续时间 毫秒,越小越快
|
|
|
+ * @param {Number} [options.count=1] 重复次数
|
|
|
+ */
|
|
|
+ drawCircle: function(centerPoint, radius, options) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let _self = this;
|
|
|
+ let viewer = this._viewer;
|
|
|
+
|
|
|
+ if (!Cesium.defined(centerPoint)) {
|
|
|
+ throw new Cesium.DeveloperError("centerPoint is required.");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Cesium.defined(radius)) {
|
|
|
+ throw new Cesium.DeveloperError("radius is required.");
|
|
|
+ }
|
|
|
+
|
|
|
+ //坐标位置
|
|
|
+ let position;
|
|
|
+ if (centerPoint instanceof Cesium.Cartesian3) {
|
|
|
+ position = centerPoint;
|
|
|
+ } else {
|
|
|
+ position = Cesium.Cartesian3.fromDegrees(centerPoint[0], centerPoint[1], centerPoint[2] || 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ //半径
|
|
|
+ if (typeof radius === 'number' && radius > 0) {
|
|
|
+ radius = radius;
|
|
|
+ } else {
|
|
|
+ radius = 100
|
|
|
+ }
|
|
|
+
|
|
|
+ options = options || {};
|
|
|
+ options.id = options.id || setSessionid();
|
|
|
+ options.clampToGround = Cesium.defaultValue(options.clampToGround, true);
|
|
|
+ options.CircleType = Cesium.defaultValue(options.CircleType, 'ColorCircle');
|
|
|
+
|
|
|
+ options.duration = Cesium.defaultValue(options.duration, 3000);
|
|
|
+ options.count = Cesium.defaultValue(options.count, 1);
|
|
|
+
|
|
|
+ if (options.color) {
|
|
|
+ if (options.color instanceof Array) {
|
|
|
+ options.color = new Cesium.Color(options.color[0] / 255, options.color[1] / 255, options.color[2] / 255, options.color[3]);
|
|
|
+ } else if (typeof(options.color) === 'string') {
|
|
|
+ options.color = new Cesium.Color.fromCssColorString(options.color);
|
|
|
+ } else {
|
|
|
+ options.color = new Cesium.Color.fromCssColorString("#FFFF00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.outlineColor) {
|
|
|
+ if (options.outlineColor instanceof Array) {
|
|
|
+ options.outlineColor = new Cesium.Color(options.outlineColor[0] / 255, options.outlineColor[1] / 255, options.outlineColor[2] / 255, options.outlineColor[3]);
|
|
|
+ } else if (typeof(options.outlineColor) === 'string') {
|
|
|
+ options.outlineColor = new Cesium.Color.fromCssColorString(options.outlineColor);
|
|
|
+ } else {
|
|
|
+ options.outlineColor = new Cesium.Color.fromCssColorString("#FFFF00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ options.outlineWidth = Cesium.defaultValue(options.outlineWidth, 0);
|
|
|
+
|
|
|
+
|
|
|
+ /* 创建面材质 */
|
|
|
+ let polygonMaterial = options.color;
|
|
|
+ /* 创建线材质 */
|
|
|
+ // let outlineMaterial = new Cesium.PolylineDashMaterialProperty({//虚线
|
|
|
+ // dashLength: 16,
|
|
|
+ // color: options.outlineColor
|
|
|
+ // });
|
|
|
+ let outlineMaterial = options.outlineColor;
|
|
|
+
|
|
|
+ if (options.CircleType === 'DynamicCircle') {
|
|
|
+ // polygonMaterial = new CircleMaterialProperty({
|
|
|
+ // viewer: viewer,
|
|
|
+ // duration: options.duration,
|
|
|
+ // color: options.color,
|
|
|
+ // count: options.count,
|
|
|
+ // });
|
|
|
+
|
|
|
+ polygonMaterial = new Cesium.CircleRippleMaterialProperty({
|
|
|
+ color: options.color,
|
|
|
+ speed: options.duration/1000,
|
|
|
+ count: options.count,
|
|
|
+ gradient: 0.2
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ let entity = new Cesium.Entity({
|
|
|
+ id: options.id,
|
|
|
+ //位置
|
|
|
+ position: position,
|
|
|
+ //椭圆
|
|
|
+ ellipse: {
|
|
|
+ //半短轴(画圆:半短轴和半长轴一致即可)
|
|
|
+ semiMinorAxis: radius,
|
|
|
+ // 半长轴
|
|
|
+ semiMajorAxis: radius,
|
|
|
+ // 填充色
|
|
|
+ material: polygonMaterial,
|
|
|
+ // 是否有边框
|
|
|
+ outline: true,
|
|
|
+ // 边框颜色
|
|
|
+ outlineColor: options.outlineColor,
|
|
|
+ // 边框宽度
|
|
|
+ outlineWidth: options.outlineWidth
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ let flyEntity = viewer.entities.add(entity);
|
|
|
+
|
|
|
+ resolve(entity, flyEntity)
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+export default CircleObject;
|