shuishen
2021-06-25 0b0ba7a298364d60567d1c2fbe30c2f2a9000def
widgets/throughSee/Widget.js
@@ -67,27 +67,27 @@
                var widget = viewer.cesiumWidget;
                // try {
                var promise = scene.open(window.MYURL_CONFIG.SCENE_CBD);
                Cesium.when.all(promise, function (layer) {
                    scene.camera.setView({
                        destination: new Cesium.Cartesian3.fromDegrees(116.44621857300415, 39.899281526734555, 216.7793905027196),
                        orientation: {
                            heading: 0.41348036210986194,
                            pitch: -0.13636490404291735,
                            roll: 6.283185307179563
                        }
                    });
                    for (var i = 0; i < layer.length; i++) {
                        layer[i].selectEnabled = false;
                    }
                // var promise = scene.open(window.MYURL_CONFIG.SCENE_CBD);
                // Cesium.when.all(promise, function (layer) {
                // scene.camera.setView({
                //     destination: new Cesium.Cartesian3.fromDegrees(116.44621857300415, 39.899281526734555, 216.7793905027196),
                //     orientation: {
                //         heading: 0.41348036210986194,
                //         pitch: -0.13636490404291735,
                //         roll: 6.283185307179563
                //     }
                // });
                // for (var i = 0; i < layer.length; i++) {
                //     layer[i].selectEnabled = false;
                // }
                    sightline.build();
                }, function (e) {
                    if (widget._showRenderLoopErrors) {
                        var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                        widget.showErrorPanel(title, undefined, e);
                    }
                });
                sightline.build();
                // }, function (e) {
                //     if (widget._showRenderLoopErrors) {
                //         var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                //         widget.showErrorPanel(title, undefined, e);
                //     }
                // });
                // } catch (e) {
                //     if (widget._showRenderLoopErrors) {
                //         var title = '渲染时发生错误,已停止渲染。';
@@ -102,8 +102,8 @@
                var tf = false;//当前点击状态是否是 添加目标点
                var num = 0;//添加的目标点的点号
                var couldRemove = false;//是否能移除目标点
                var tooltip = window.MYcreateTooltip(viewer._element)
                that.couldRemove = false;//是否能移除目标点
                that.tooltip = window.MYcreateTooltip(viewer._element)
                var handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
                handlerPoint.drawEvt.addEventListener(function (result) {
                    //添加观察点
@@ -125,7 +125,7 @@
                var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
                that.handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
                document.getElementById("addViewPointthroughSee").onclick = function () {
                    if (tf == false) {
@@ -135,11 +135,11 @@
                            return;
                        }
                        viewer.entities.removeAll();
                        if (couldRemove) {
                        if (that.couldRemove) {
                            sightline.removeAllTargetPoint();
                        }
                        handlerPoint.activate();
                        handler.setInputAction(function (evt) {
                        that.handler.setInputAction(function (evt) {
                            //鼠标移动,更新最后一次添加的目标点的位置
                            var position = scene.pickPosition(evt.endPosition);
@@ -152,16 +152,16 @@
                            $('body').removeClass('drawCur').addClass('drawCur');
                        }
                        //鼠标移动事件,更新点
                        handler.setInputAction(function (evt) {
                            tooltip.showAt(evt.endPosition, '<p>点击确定观察点</p>');
                        that.handler.setInputAction(function (evt) {
                            that.tooltip.showAt(evt.endPosition, '<p>点击确定观察点</p>');
                        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        //鼠标点击事件,添加点
                        handler.setInputAction(function (e) {
                        that.handler.setInputAction(function (e) {
                            $('body').removeClass('drawCur');
                            mv = true;
                            tooltip.setVisible(false);
                            handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                            handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                            that.tooltip.setVisible(false);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    } else {
                        layer.tips('正在添加目标点,请先右键关闭', $('#addViewPointthroughSee'), { tips: [1, 'red'] });
@@ -181,13 +181,13 @@
                        }
                        //鼠标点击事件,添加点
                        handler.setInputAction(function (e) {
                        that.handler.setInputAction(function (e) {
                            var position = scene.pickPosition(e.position);
                            addTarget(position);
                        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
                        //鼠标移动事件,更新点
                        handler.setInputAction(function (evt) {
                        that.handler.setInputAction(function (evt) {
                            //鼠标移动,更新最后一次添加的目标点的位置
                            var position = scene.pickPosition(evt.endPosition);
@@ -202,16 +202,16 @@
                                    name: "point0"
                                });
                            }
                            tooltip.showAt(evt.endPosition, '<p>点击确定目标点右键结束</p>');
                            that.tooltip.showAt(evt.endPosition, '<p>点击确定目标点右键结束</p>');
                        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        //鼠标右键事件,结束
                        handler.setInputAction(function () {
                        that.handler.setInputAction(function () {
                            viewer.enableCursorStyle = true;
                            $('body').removeClass('drawCur');
                            tooltip.setVisible(false);
                            handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                            handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                            that.tooltip.setVisible(false);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                            tf = false;
                        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
                    } else {
@@ -226,15 +226,17 @@
                        mv = false;
                        tf = false;
                        handlerPoint.clear();
                        that.tooltip.setVisible(false);
                        viewer.entities.removeAll();
                        if (couldRemove) {
                        that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        if (that.couldRemove) {
                            sightline.removeAllTargetPoint();
                            couldRemove = false;
                            that.couldRemove = false;
                        }
                        viewer.enableCursorStyle = true;
                        $('body').removeClass('drawCur');
                    } else {
                        layer.tips('正在添加目标点,请先右键关闭', $('#addViewPointthroughSee'), { tips: [1, 'red'] });
                        layer.tips('正在添加目标点,请先右键关闭', $('#clearthroughSee'), { tips: [1, 'red'] });
                    }
                }
@@ -254,7 +256,7 @@
                            position: cartographic,
                            name: name
                        });
                        couldRemove = true;
                        that.couldRemove = true;
                    }
                }
@@ -268,32 +270,47 @@
                    return [longitude, latitude, height];
                }
                that.promise = promise;
                // that.promise = promise;
                that.addViewFlag = addViewFlag;
                that.addTargetFlag = addTargetFlag;
                that.handlerPoint = handlerPoint;
                that.sightline = sightline;
            },
            promise: '',
            // promise: '',
            addViewFlag: '',
            addTargetFlag: '',
            couldRemove: '',
            sightline: '',
            tooltip: '',
            handler: '',
            handlerPoint: '',
            closesthroughSee: function (froms) {
                console.log(`${this.name}--guanbi`);
                that = this;
                Cesium.when.all(that.promise, function (layer) {
                    for (var i = 0; i < layer.length; i++) {
                        that.map.scene.layers.remove(layer[i].name)
                    }
                })
                // Cesium.when.all(that.promise, function (layer) {
                //     for (var i = 0; i < layer.length; i++) {
                //         that.map.scene.layers.remove(layer[i].name)
                //     }
                // })
                if (that.handler.removeInputAction) {
                    that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                }
                if (that.tooltip.setVisible) {
                    that.tooltip.setVisible(false);
                }
                if (that.handlerPoint.clear) {
                    that.handlerPoint.clear();
                }
                that.addViewFlag = false;
                that.addTargetFlag = false;
                that.handlerPoint.clear();
                that.map.entities.removeAll();
                if (couldRemove) {
                    sightline.removeAllTargetPoint();
                    couldRemove = false;
                if (that.couldRemove) {
                    that.sightline.removeAllTargetPoint();
                    that.couldRemove = false;
                }
                that.map.enableCursorStyle = true;
                $('body').removeClass('drawCur');