|
@@ -2,7 +2,7 @@
|
|
* 创建者:王成
|
|
* 创建者:王成
|
|
* 操作系统:MAC
|
|
* 操作系统:MAC
|
|
* 创建日期:2022年11月14日
|
|
* 创建日期:2022年11月14日
|
|
- * 描述:工具类
|
|
|
|
|
|
+ * 描述:工具类 提供绘制工具和查询工具模型
|
|
*/
|
|
*/
|
|
|
|
|
|
/* 引入Cesium */
|
|
/* 引入Cesium */
|
|
@@ -26,11 +26,14 @@ class CommonTools {
|
|
constructor(viewer, options) {
|
|
constructor(viewer, options) {
|
|
this._viewer = viewer;
|
|
this._viewer = viewer;
|
|
this._sketchViewModel = new SketchViewModel(viewer, {
|
|
this._sketchViewModel = new SketchViewModel(viewer, {
|
|
- iconType: SketchViewModel.SketchIconType.Blue,
|
|
|
|
|
|
+ iconType: SketchViewModel.SketchIconType.Green,
|
|
isDrawPoint: true,
|
|
isDrawPoint: true,
|
|
isRetainDrawPoint: true,
|
|
isRetainDrawPoint: true,
|
|
});
|
|
});
|
|
if (options && options.isClear) this._isClear = options.isClear;
|
|
if (options && options.isClear) this._isClear = options.isClear;
|
|
|
|
+ /* 获取画布的宽度和高度 */
|
|
|
|
+ this._canvasWidth = this._viewer.scene.canvas.width;
|
|
|
|
+ this._canvasHeight = this._viewer.scene.canvas.height;
|
|
/* 初始化 */
|
|
/* 初始化 */
|
|
this._init();
|
|
this._init();
|
|
}
|
|
}
|
|
@@ -67,23 +70,7 @@ class CommonTools {
|
|
* @param {string} entityName 实体名称
|
|
* @param {string} entityName 实体名称
|
|
*/
|
|
*/
|
|
_removeEntityByName(entityName) {
|
|
_removeEntityByName(entityName) {
|
|
- /* 获取实体集合 */
|
|
|
|
- let entities = this._entities;
|
|
|
|
- /* 如果不存在实体集合或集合中没有数据 则返回 */
|
|
|
|
- if (!entities || !entities.values) return;
|
|
|
|
- let delEntitys = [];
|
|
|
|
- /* 循环获取当前集合中的所有实体 */
|
|
|
|
- for (let i = 0; i < entities.values.length; i++) {
|
|
|
|
- if (entities.values[i].name == entityName) {
|
|
|
|
- delEntitys.push(entities.values[i]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /* 删除符合条件的所有实体 */
|
|
|
|
- for (let i = 0; i < delEntitys.length; i++) {
|
|
|
|
- entities.remove(delEntitys[i]);
|
|
|
|
- }
|
|
|
|
- /* 更新场景 */
|
|
|
|
- this._updateScene();
|
|
|
|
|
|
+ this._sketchViewModel.removeEntityByName(entityName);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -157,7 +144,7 @@ class CommonTools {
|
|
name: _self._measureEntityName,
|
|
name: _self._measureEntityName,
|
|
position: coord,
|
|
position: coord,
|
|
billboard: {
|
|
billboard: {
|
|
- image: _self._iconBlue,
|
|
|
|
|
|
+ image: _self._iconGreen,
|
|
horizontalOrigin: Cesium.HorizontalOrigin.center,
|
|
horizontalOrigin: Cesium.HorizontalOrigin.center,
|
|
verticalOrigin: Cesium.VerticalOrigin.bottom,
|
|
verticalOrigin: Cesium.VerticalOrigin.bottom,
|
|
scale: 0.5,
|
|
scale: 0.5,
|
|
@@ -182,7 +169,6 @@ class CommonTools {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this._entities.add(entity);
|
|
this._entities.add(entity);
|
|
- this._updateScene();
|
|
|
|
return entity;
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -215,7 +201,6 @@ class CommonTools {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
this._entities.add(entity);
|
|
this._entities.add(entity);
|
|
- this._updateScene();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -245,7 +230,6 @@ class CommonTools {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
this._entities.add(this._altitudeDynamicLabel);
|
|
this._entities.add(this._altitudeDynamicLabel);
|
|
- this._updateScene();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -384,7 +368,7 @@ class CommonTools {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 设置鼠标为柿子样式
|
|
|
|
|
|
+ * 设置鼠标为十字样式
|
|
*/
|
|
*/
|
|
_setMousePointerStyle() {
|
|
_setMousePointerStyle() {
|
|
document.querySelector('body').style.cursor = 'crosshair';
|
|
document.querySelector('body').style.cursor = 'crosshair';
|
|
@@ -435,8 +419,16 @@ Object.assign(CommonTools.prototype, {
|
|
if (text != undefined) tooltipObj.innerHTML = text;
|
|
if (text != undefined) tooltipObj.innerHTML = text;
|
|
/* 挂接鼠标移动事件 */
|
|
/* 挂接鼠标移动事件 */
|
|
document.onmousemove = function(event) {
|
|
document.onmousemove = function(event) {
|
|
- tooltipObj.style.left = (event.clientX + 10) + 'px';
|
|
|
|
- tooltipObj.style.top = (event.clientY - tooltipObj.offsetHeight / 2) + 'px';
|
|
|
|
|
|
+ if (tooltipObj === null) return;
|
|
|
|
+ if (event.clientX < 100 || event.clientX > _self._canvasWidth - 100 || event.clientY <
|
|
|
|
+ 100 ||
|
|
|
|
+ event.clientY > _self._canvasHeight - 100) {
|
|
|
|
+ tooltipObj.style.display = 'none';
|
|
|
|
+ } else {
|
|
|
|
+ tooltipObj.style.display = 'flex';
|
|
|
|
+ tooltipObj.style.left = (event.clientX + 10) + 'px';
|
|
|
|
+ tooltipObj.style.top = (event.clientY - tooltipObj.offsetHeight / 2) + 'px';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -462,8 +454,9 @@ Object.assign(CommonTools.prototype, {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 通用对外公开函数
|
|
|
|
|
|
+ * 测量类对外公开函数
|
|
*/
|
|
*/
|
|
Object.assign(CommonTools.prototype, {
|
|
Object.assign(CommonTools.prototype, {
|
|
/**
|
|
/**
|
|
@@ -472,72 +465,66 @@ Object.assign(CommonTools.prototype, {
|
|
clear: function() {
|
|
clear: function() {
|
|
/* 清理资源 */
|
|
/* 清理资源 */
|
|
this._clear(true);
|
|
this._clear(true);
|
|
- }
|
|
|
|
-})
|
|
|
|
|
|
+ },
|
|
|
|
|
|
-/**
|
|
|
|
- * 测量类对外公开函数
|
|
|
|
- */
|
|
|
|
-Object.assign(CommonTools.prototype, {
|
|
|
|
/**
|
|
/**
|
|
* 测量长度
|
|
* 测量长度
|
|
*/
|
|
*/
|
|
measureLength: function() {
|
|
measureLength: function() {
|
|
- // let _self = this;
|
|
|
|
- // /* 临时创建的实体 */
|
|
|
|
- // this._tempEntitys = [];
|
|
|
|
- // /* 清理资源 */
|
|
|
|
- // this._clear(this._isClear);
|
|
|
|
- // /* 设置鼠标样式 */
|
|
|
|
- // this._setMousePointerStyle();
|
|
|
|
- // /* 设置鼠标跟随 */
|
|
|
|
- // this._tooltipInit('点击开始测量');
|
|
|
|
- // /* 调用草图开始绘制 */
|
|
|
|
- // this._sketchViewModel.sketchTools(SketchViewModel.SketchType.Line, {
|
|
|
|
- // /**
|
|
|
|
- // * 添加点回调
|
|
|
|
- // * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
- // * @param {Array<JSON>} gPoints 球面坐标系点集合
|
|
|
|
- // */
|
|
|
|
- // onAdded: function(cPoints, gPoints) {
|
|
|
|
- // if (cPoints.length === 1) {
|
|
|
|
- // _self._createPoint(cPoints[0], '起点');
|
|
|
|
- // } else {
|
|
|
|
- // let distince = _self._measureDistance(cPoints);
|
|
|
|
- // /* 追加中间距离 */
|
|
|
|
- // let tempPoints = [cPoints[cPoints.length - 2], cPoints[cPoints.length - 1]];
|
|
|
|
- // distince += ' +' + _self._measureDistance(tempPoints);
|
|
|
|
- // _self._tempEntitys.push(_self._createPoint(cPoints[cPoints.length - 1],
|
|
|
|
- // distince));
|
|
|
|
- // }
|
|
|
|
- // },
|
|
|
|
- // /**
|
|
|
|
- // * 撤销回调
|
|
|
|
- // */
|
|
|
|
- // onUndo: function() {
|
|
|
|
- // _self._viewer.entities.remove(_self._tempEntitys[_self._tempEntitys.length -
|
|
|
|
- // 1]);
|
|
|
|
- // _self._tempEntitys.pop();
|
|
|
|
- // },
|
|
|
|
- // /**
|
|
|
|
- // * 移动回调
|
|
|
|
- // * @param {Cesium.Cartesian3} cPoint
|
|
|
|
- // * @param {JSON} scPoint 屏幕点
|
|
|
|
- // */
|
|
|
|
- // onMoving: function(cPoint, scPoint) {
|
|
|
|
- // _self._tooltipSetText('右键单击回退<br>左键双击结束绘制');
|
|
|
|
- // },
|
|
|
|
- // /**
|
|
|
|
- // * 完成回调
|
|
|
|
- // * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
- // * @param {Array<JSON>} gPoints 球面坐标系点集合
|
|
|
|
- // */
|
|
|
|
- // onComplete: function(cPoints, gPoints) {
|
|
|
|
- // _self._initMousePointerStyle();
|
|
|
|
- // _self._tooltipRemove();
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
- this._sketchViewModel.sketchCreateEditPolyline();
|
|
|
|
|
|
+ let _self = this;
|
|
|
|
+ /* 临时创建的实体 */
|
|
|
|
+ this._tempEntitys = [];
|
|
|
|
+ /* 清理资源 */
|
|
|
|
+ this._clear(this._isClear);
|
|
|
|
+ /* 设置鼠标样式 */
|
|
|
|
+ this._setMousePointerStyle();
|
|
|
|
+ /* 设置鼠标跟随 */
|
|
|
|
+ this._tooltipInit('点击开始测量');
|
|
|
|
+ /* 调用草图开始绘制 */
|
|
|
|
+ this._sketchViewModel.sketchTools(SketchViewModel.SketchType.Line, {
|
|
|
|
+ /**
|
|
|
|
+ * 添加点回调
|
|
|
|
+ * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
+ * @param {Array<JSON>} gPoints 球面坐标系点集合
|
|
|
|
+ */
|
|
|
|
+ onAdded: function(cPoints, gPoints) {
|
|
|
|
+ if (cPoints.length === 1) {
|
|
|
|
+ _self._createPoint(cPoints[0], '起点');
|
|
|
|
+ } else {
|
|
|
|
+ let distince = _self._measureDistance(cPoints);
|
|
|
|
+ /* 追加中间距离 */
|
|
|
|
+ let tempPoints = [cPoints[cPoints.length - 2], cPoints[cPoints.length - 1]];
|
|
|
|
+ distince += ' +' + _self._measureDistance(tempPoints);
|
|
|
|
+ _self._tempEntitys.push(_self._createPoint(cPoints[cPoints.length - 1],
|
|
|
|
+ distince));
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ /**
|
|
|
|
+ * 撤销回调
|
|
|
|
+ */
|
|
|
|
+ onUndo: function() {
|
|
|
|
+ _self._viewer.entities.remove(_self._tempEntitys[_self._tempEntitys.length -
|
|
|
|
+ 1]);
|
|
|
|
+ _self._tempEntitys.pop();
|
|
|
|
+ },
|
|
|
|
+ /**
|
|
|
|
+ * 移动回调
|
|
|
|
+ * @param {Cesium.Cartesian3} cPoint
|
|
|
|
+ * @param {JSON} scPoint 屏幕点
|
|
|
|
+ */
|
|
|
|
+ onMoving: function(cPoint, scPoint) {
|
|
|
|
+ _self._tooltipSetText('右键单击回退<br>左键双击结束绘制');
|
|
|
|
+ },
|
|
|
|
+ /**
|
|
|
|
+ * 完成回调
|
|
|
|
+ * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
+ * @param {Array<JSON>} gPoints 球面坐标系点集合
|
|
|
|
+ */
|
|
|
|
+ onComplete: function(cPoints, gPoints) {
|
|
|
|
+ _self._initMousePointerStyle();
|
|
|
|
+ _self._tooltipRemove();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -598,7 +585,7 @@ Object.assign(CommonTools.prototype, {
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 测量面积
|
|
|
|
|
|
+ * 面积测量
|
|
*/
|
|
*/
|
|
measureArea: function() {
|
|
measureArea: function() {
|
|
let _self = this;
|
|
let _self = this;
|
|
@@ -660,6 +647,8 @@ Object.assign(CommonTools.prototype, {
|
|
onComplete: function(cPoints, gPoints) {
|
|
onComplete: function(cPoints, gPoints) {
|
|
_self._initMousePointerStyle();
|
|
_self._initMousePointerStyle();
|
|
_self._tooltipRemove();
|
|
_self._tooltipRemove();
|
|
|
|
+ _self._areaLabelEntity.label.text = _self._areaLabel;
|
|
|
|
+ _self._areaLabelEntity = undefined;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -1036,62 +1025,6 @@ Object.assign(CommonTools.prototype, {
|
|
* 绘制相关
|
|
* 绘制相关
|
|
*/
|
|
*/
|
|
Object.assign(CommonTools.prototype, {
|
|
Object.assign(CommonTools.prototype, {
|
|
- /**
|
|
|
|
- * 绘制面拉伸体
|
|
|
|
- * @param {String} callComplete 成功回调callComplete()
|
|
|
|
- */
|
|
|
|
- drawPolygonBody: function(callComplete) {
|
|
|
|
- let _self = this;
|
|
|
|
- /* 清理资源 */
|
|
|
|
- this._clear(this._isClear);
|
|
|
|
- /* 设置鼠标样式 */
|
|
|
|
- this._setMousePointerStyle();
|
|
|
|
- /* 设置提示标签 */
|
|
|
|
- this._tooltipInit('点击开始绘制');
|
|
|
|
- /* 调用草图开始绘制 */
|
|
|
|
- this._sketchViewModel.sketchTools(SketchViewModel.SketchType.PolygonBody, {
|
|
|
|
- /**
|
|
|
|
- * 添加点回调
|
|
|
|
- * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
- * @param {Array<JSON>} gPoints 球面坐标系点集合
|
|
|
|
- */
|
|
|
|
- onAdded: function(cPoints, gPoints) {
|
|
|
|
- if (cPoints.length === 0) {
|
|
|
|
- _self._tooltipInit('点击开始绘制');
|
|
|
|
- } else if (cPoints.length < 3) {
|
|
|
|
- _self._tooltipInit('右键单击回退');
|
|
|
|
- } else {
|
|
|
|
- _self._tooltipInit('右键单击回退<br>左键双击结束绘制');
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- /**
|
|
|
|
- * 撤销回调
|
|
|
|
- * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
- */
|
|
|
|
- onUndo: function(cPoints) {
|
|
|
|
- if (cPoints.length === 0) {
|
|
|
|
- _self._tooltipInit('点击开始绘制');
|
|
|
|
- } else if (cPoints.length < 3) {
|
|
|
|
- _self._tooltipInit('右键单击回退');
|
|
|
|
- } else {
|
|
|
|
- _self._tooltipInit('右键单击回退<br>左键双击结束绘制');
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- /**
|
|
|
|
- * 完成回调
|
|
|
|
- * @param {Array<JSON>} cPoints 世界坐标系点集合
|
|
|
|
- * @param {Array<JSON>} gPoints 球面坐标系点集合
|
|
|
|
- */
|
|
|
|
- onComplete: function(cPoints, gPoints) {
|
|
|
|
- /* 恢复鼠标样式 */
|
|
|
|
- _self._initMousePointerStyle();
|
|
|
|
- /* 移除提示标签 */
|
|
|
|
- _self._tooltipRemove();
|
|
|
|
- /* 回调 */
|
|
|
|
- if (callComplete) callComplete();
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Array<Number>} points 经纬度点集合
|
|
* @param {Array<Number>} points 经纬度点集合
|
|
@@ -1159,49 +1092,5 @@ Object.assign(CommonTools.prototype, {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-/* 其他工具 */
|
|
|
|
-Object.assign(CommonTools.prototype, {
|
|
|
|
- /**
|
|
|
|
- * 拾取通过面对象拉伸绘制的体
|
|
|
|
- * @param {Function} callComplete 完成回调callComplete({color:height})拾取失败或者未拾取则返回undefined
|
|
|
|
- */
|
|
|
|
- pickPolygonBody: function(callComplete) {
|
|
|
|
- let _self = this;
|
|
|
|
- this._sketchViewModel.sketchPick(function(options) {
|
|
|
|
- if (options === undefined) {
|
|
|
|
- if (callComplete) callComplete(undefined);
|
|
|
|
- } else {
|
|
|
|
- if (callComplete) callComplete({
|
|
|
|
- color: options.color,
|
|
|
|
- height: options.height,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 设置拾取的体对象样式及高度
|
|
|
|
- * @@param {JSON} options 配置项
|
|
|
|
- * @param {Array<Number>} options.color 颜色[0~~255,0~255,0~255,0~1]
|
|
|
|
- * @param {Number} options.height 高度
|
|
|
|
- * @param {Function} options.onComplete(message) 完成回调,如果message为undefined则代表成功,否则为失败消息
|
|
|
|
- */
|
|
|
|
- setPolygonBody: function(options) {
|
|
|
|
- this._sketchViewModel.sketchEditPickPolygonBody({
|
|
|
|
- color: options.color,
|
|
|
|
- height: options.height,
|
|
|
|
- onComplete: options.onComplete
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 移除拾取的体对象
|
|
|
|
- * @param {Function} onComplete(message) 完成回调,message为undifined为成功,否则为失败消息
|
|
|
|
- */
|
|
|
|
- removePolygonBody: function(onComplete) {
|
|
|
|
- this._sketchViewModel.sketchRemovePickPolygonBody(onComplete);
|
|
|
|
- }
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
/* 输出 */
|
|
/* 输出 */
|
|
export default CommonTools
|
|
export default CommonTools
|