|
@@ -100,7 +100,7 @@ class SightLine {
|
|
|
buttonDiv.style.position = 'absolute';
|
|
|
buttonDiv.style.bottom = '150px';
|
|
|
buttonDiv.style.right = '10px';
|
|
|
-
|
|
|
+
|
|
|
// let btnUndo = document.createElement('button');
|
|
|
// btnUndo.id = "btnDrawBackout";
|
|
|
// btnUndo.style.height = '30px';
|
|
@@ -113,7 +113,7 @@ class SightLine {
|
|
|
// btnUndo.style.fontSize = '13px';
|
|
|
// btnUndo.style.cursor = 'pointer';
|
|
|
// buttonDiv.appendChild(btnUndo);
|
|
|
-
|
|
|
+
|
|
|
let btnCompletion = document.createElement('button');
|
|
|
btnCompletion.id = "btnDrawComplete";
|
|
|
btnCompletion.style.height = '30px';
|
|
@@ -125,7 +125,7 @@ class SightLine {
|
|
|
btnCompletion.style.fontSize = '13px';
|
|
|
btnCompletion.style.cursor = 'pointer';
|
|
|
buttonDiv.appendChild(btnCompletion);
|
|
|
-
|
|
|
+
|
|
|
/* 加入到页面 */
|
|
|
document.body.appendChild(buttonDiv);
|
|
|
}
|
|
@@ -208,151 +208,154 @@ Object.assign(SightLine.prototype, /** @lends SightLine.prototype */ {
|
|
|
|
|
|
_self.handler = new Cesium.ScreenSpaceEventHandler(_self._viewer.canvas);
|
|
|
_self.handler.setInputAction((event) => {
|
|
|
- let cartesian = CoordTransform.getCatesian3FromPX(_self._viewer, event.position);
|
|
|
+ let loc = CoordTransform._transfromFromScreenPoint(_self._viewer, event.position);
|
|
|
toolTip = "左键创建视角终点,右键结束通视分析";
|
|
|
if (this._isRuntimeApp()) {
|
|
|
toolTip = "再次单击创建视角终点";
|
|
|
_self._showTooltipMessage(toolTip);
|
|
|
}
|
|
|
|
|
|
- if (cartesian) {
|
|
|
- if (!_self._resultObject.viewPoint) {
|
|
|
- _self._resultObject.viewPoint = cartesian;
|
|
|
- let pointEntity = _self._viewer.entities.add({
|
|
|
- position: cartesian,
|
|
|
- point: {
|
|
|
- color: Cesium.Color.YELLOW,
|
|
|
- pixelSize: 5,
|
|
|
- },
|
|
|
- //文字标签
|
|
|
- label: {
|
|
|
- text: "观察位置",
|
|
|
- font: '12px sans-serif',
|
|
|
- fillColor: new Cesium.Color(255/255, 255/255, 255/255, 1.0),
|
|
|
- outlineColor: new Cesium.Color(0, 154/255, 94/255, 1.0),
|
|
|
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
|
- outlineWidth: 1.0,
|
|
|
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
|
- pixelOffset: new Cesium.Cartesian2(0, -28),
|
|
|
- showBackground: true,
|
|
|
- backgroundColor: new Cesium.Color(0, 0, 0, 0.6),
|
|
|
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
|
- },
|
|
|
- });
|
|
|
- _self._resultObject.objectExclude.push(pointEntity);
|
|
|
- _self._resultObject.entities.push(pointEntity);
|
|
|
- } else {
|
|
|
- _self._resultObject.targetPoint = cartesian;
|
|
|
- let pointEntity = _self._viewer.entities.add({
|
|
|
- position: cartesian,
|
|
|
- point: {
|
|
|
- color: Cesium.Color.YELLOW,
|
|
|
- pixelSize: 5,
|
|
|
- },
|
|
|
- //文字标签
|
|
|
- label: {
|
|
|
- text: "目标位置",
|
|
|
- font: '12px sans-serif',
|
|
|
- fillColor: new Cesium.Color(255/255, 255/255, 255/255, 1.0),
|
|
|
- outlineColor: new Cesium.Color(0, 154/255, 94/255, 1.0),
|
|
|
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
|
- outlineWidth: 1.0,
|
|
|
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
|
- pixelOffset: new Cesium.Cartesian2(0, -28),
|
|
|
- showBackground: true,
|
|
|
- backgroundColor: new Cesium.Color(0, 0, 0, 0.6),
|
|
|
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
|
- },
|
|
|
- });
|
|
|
- _self._resultObject.objectExclude.push(pointEntity);
|
|
|
- _self._resultObject.entities.push(pointEntity);
|
|
|
- let direction = Cesium.Cartesian3.normalize(
|
|
|
- Cesium.Cartesian3.subtract(
|
|
|
- _self._resultObject.targetPoint,
|
|
|
- _self._resultObject.viewPoint,
|
|
|
- new Cesium.Cartesian3()
|
|
|
- ),
|
|
|
+ if (!Cesium.defined(loc.sLocation)) return;
|
|
|
+
|
|
|
+ let cartesian = loc.sLocation;
|
|
|
+
|
|
|
+ if (!_self._resultObject.viewPoint) {
|
|
|
+ _self._resultObject.viewPoint = cartesian;
|
|
|
+ let pointEntity = _self._viewer.entities.add({
|
|
|
+ position: cartesian,
|
|
|
+ point: {
|
|
|
+ color: Cesium.Color.YELLOW,
|
|
|
+ pixelSize: 5,
|
|
|
+ },
|
|
|
+ //文字标签
|
|
|
+ label: {
|
|
|
+ text: "观察位置",
|
|
|
+ font: '12px sans-serif',
|
|
|
+ fillColor: new Cesium.Color(255 / 255, 255 / 255, 255 / 255, 1.0),
|
|
|
+ outlineColor: new Cesium.Color(0, 154 / 255, 94 / 255, 1.0),
|
|
|
+ style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
|
+ outlineWidth: 1.0,
|
|
|
+ verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
|
+ pixelOffset: new Cesium.Cartesian2(0, -28),
|
|
|
+ showBackground: true,
|
|
|
+ backgroundColor: new Cesium.Color(0, 0, 0, 0.6),
|
|
|
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ _self._resultObject.objectExclude.push(pointEntity);
|
|
|
+ _self._resultObject.entities.push(pointEntity);
|
|
|
+ } else {
|
|
|
+ _self._resultObject.targetPoint = cartesian;
|
|
|
+ let pointEntity = _self._viewer.entities.add({
|
|
|
+ position: cartesian,
|
|
|
+ point: {
|
|
|
+ color: Cesium.Color.YELLOW,
|
|
|
+ pixelSize: 5,
|
|
|
+ },
|
|
|
+ //文字标签
|
|
|
+ label: {
|
|
|
+ text: "目标位置",
|
|
|
+ font: '12px sans-serif',
|
|
|
+ fillColor: new Cesium.Color(255 / 255, 255 / 255, 255 / 255, 1.0),
|
|
|
+ outlineColor: new Cesium.Color(0, 154 / 255, 94 / 255, 1.0),
|
|
|
+ style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
|
+ outlineWidth: 1.0,
|
|
|
+ verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
|
+ pixelOffset: new Cesium.Cartesian2(0, -28),
|
|
|
+ showBackground: true,
|
|
|
+ backgroundColor: new Cesium.Color(0, 0, 0, 0.6),
|
|
|
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ _self._resultObject.objectExclude.push(pointEntity);
|
|
|
+ _self._resultObject.entities.push(pointEntity);
|
|
|
+ let direction = Cesium.Cartesian3.normalize(
|
|
|
+ Cesium.Cartesian3.subtract(
|
|
|
+ _self._resultObject.targetPoint,
|
|
|
+ _self._resultObject.viewPoint,
|
|
|
new Cesium.Cartesian3()
|
|
|
- );
|
|
|
+ ),
|
|
|
+ new Cesium.Cartesian3()
|
|
|
+ );
|
|
|
|
|
|
- let ray = new Cesium.Ray(_self._resultObject.viewPoint, direction);
|
|
|
- let result = _self._viewer.scene.pickFromRay(ray, _self._resultObject.objectExclude); // 计算交互点,返回第一个
|
|
|
- if (result) {
|
|
|
- let dis0 = _self._distance(
|
|
|
- _self._resultObject.viewPoint,
|
|
|
- _self._resultObject.targetPoint
|
|
|
- );
|
|
|
- let dis1 = _self._distance(
|
|
|
- _self._resultObject.viewPoint,
|
|
|
- result.position
|
|
|
- );
|
|
|
- let dis2 = _self._distance(
|
|
|
- result.position,
|
|
|
- _self._resultObject.targetPoint
|
|
|
- );
|
|
|
- console.log(dis0, dis1, dis2);
|
|
|
- if (dis0 > dis1) {
|
|
|
- let _poly0 = _self._viewer.entities.add({
|
|
|
- polyline: {
|
|
|
- positions: [_self._resultObject.viewPoint, result.position],
|
|
|
- material: Cesium.Color.GREEN,
|
|
|
- width: 3,
|
|
|
- },
|
|
|
- });
|
|
|
- _self._resultObject.entities.push(_poly0);
|
|
|
- let _poly1 = _self._viewer.entities.add({
|
|
|
- polyline: {
|
|
|
- positions: [result.position, _self._resultObject.targetPoint],
|
|
|
- material: Cesium.Color.RED,
|
|
|
- width: 3,
|
|
|
- },
|
|
|
- });
|
|
|
- _self._resultObject.entities.push(_poly1);
|
|
|
- _self._resultObject.targetPoints.push({
|
|
|
- targetPoint: cartesian,
|
|
|
- visual: false, //如果dis2足够小,其实他是可视的
|
|
|
- distance: [dis0, dis1, dis2], //[初始点和终点,初始点和交点,交点和终点]
|
|
|
- });
|
|
|
- } else {
|
|
|
- let _poly2 = _self._viewer.entities.add({
|
|
|
- polyline: {
|
|
|
- positions: [
|
|
|
- _self._resultObject.viewPoint,
|
|
|
- _self._resultObject.targetPoint,
|
|
|
- ],
|
|
|
- material: Cesium.Color.GREEN,
|
|
|
- width: 3,
|
|
|
- },
|
|
|
- });
|
|
|
- _self._resultObject.entities.push(_poly2);
|
|
|
- _self._resultObject.targetPoints.push({
|
|
|
- targetPoint: cartesian,
|
|
|
- visual: true, //如果dis2足够小,其实他是可视的
|
|
|
- distance: [dis0, dis1, dis2], //[初始点和终点,初始点和交点,交点和终点]
|
|
|
- });
|
|
|
- }
|
|
|
+ let ray = new Cesium.Ray(_self._resultObject.viewPoint, direction);
|
|
|
+ let result = _self._viewer.scene.pickFromRay(ray, _self._resultObject.objectExclude); // 计算交互点,返回第一个
|
|
|
+ if (result) {
|
|
|
+ let dis0 = _self._distance(
|
|
|
+ _self._resultObject.viewPoint,
|
|
|
+ _self._resultObject.targetPoint
|
|
|
+ );
|
|
|
+ let dis1 = _self._distance(
|
|
|
+ _self._resultObject.viewPoint,
|
|
|
+ result.position
|
|
|
+ );
|
|
|
+ let dis2 = _self._distance(
|
|
|
+ result.position,
|
|
|
+ _self._resultObject.targetPoint
|
|
|
+ );
|
|
|
+ console.log(dis0, dis1, dis2);
|
|
|
+ if (dis0 > dis1) {
|
|
|
+ let _poly0 = _self._viewer.entities.add({
|
|
|
+ polyline: {
|
|
|
+ positions: [_self._resultObject.viewPoint, result.position],
|
|
|
+ material: Cesium.Color.GREEN,
|
|
|
+ width: 3,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ _self._resultObject.entities.push(_poly0);
|
|
|
+ let _poly1 = _self._viewer.entities.add({
|
|
|
+ polyline: {
|
|
|
+ positions: [result.position, _self._resultObject.targetPoint],
|
|
|
+ material: Cesium.Color.RED,
|
|
|
+ width: 3,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ _self._resultObject.entities.push(_poly1);
|
|
|
+ _self._resultObject.targetPoints.push({
|
|
|
+ targetPoint: cartesian,
|
|
|
+ visual: false, //如果dis2足够小,其实他是可视的
|
|
|
+ distance: [dis0, dis1, dis2], //[初始点和终点,初始点和交点,交点和终点]
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ let _poly2 = _self._viewer.entities.add({
|
|
|
+ polyline: {
|
|
|
+ positions: [
|
|
|
+ _self._resultObject.viewPoint,
|
|
|
+ _self._resultObject.targetPoint,
|
|
|
+ ],
|
|
|
+ material: Cesium.Color.GREEN,
|
|
|
+ width: 3,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ _self._resultObject.entities.push(_poly2);
|
|
|
+ _self._resultObject.targetPoints.push({
|
|
|
+ targetPoint: cartesian,
|
|
|
+ visual: true, //如果dis2足够小,其实他是可视的
|
|
|
+ distance: [dis0, dis1, dis2], //[初始点和终点,初始点和交点,交点和终点]
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (_self._resultObject.objectExclude.length === 2) {
|
|
|
- if (this._isRuntimeApp()) {
|
|
|
- //创建按钮
|
|
|
- _self._createOperationMainDom();
|
|
|
-
|
|
|
- //完成绘制
|
|
|
- document.getElementById("btnDrawComplete").onclick = () => {
|
|
|
- CreateRemindertip(toolTip, event.endPosition, false);
|
|
|
- _self.handler.destroy();
|
|
|
-
|
|
|
- let buttonDiv = document.getElementById("drawButtonDiv");
|
|
|
- if (buttonDiv) {
|
|
|
- //从页面移除
|
|
|
- document.body.removeChild(buttonDiv);
|
|
|
- }
|
|
|
+ if (_self._resultObject.objectExclude.length === 2) {
|
|
|
+ if (this._isRuntimeApp()) {
|
|
|
+ //创建按钮
|
|
|
+ _self._createOperationMainDom();
|
|
|
+
|
|
|
+ //完成绘制
|
|
|
+ document.getElementById("btnDrawComplete").onclick = () => {
|
|
|
+ CreateRemindertip(toolTip, event.endPosition, false);
|
|
|
+ _self.handler.destroy();
|
|
|
+
|
|
|
+ let buttonDiv = document.getElementById("drawButtonDiv");
|
|
|
+ if (buttonDiv) {
|
|
|
+ //从页面移除
|
|
|
+ document.body.removeChild(buttonDiv);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
|
|
|
|
_self.handler.setInputAction(function(move) {
|