shuishen
2021-06-25 da0872bd7b0056b0cd35b90dff8f8cfce2024aba
widgets/spatialAnalysis/Widget.js
@@ -31,52 +31,9 @@
            var that = this;
            // 暴露在外的接口
                topic.subscribe("closeOnceUse", lang.hitch(this, this.closeOnceUse));
            topic.subscribe("closeOnceUse", lang.hitch(this, this.closeOnceUse));
            function createTooltip(frameDiv) {//抄录createTooltip函数
               var tooltip = function (frameDiv) {
                  var div = document.createElement('DIV');
                  div.className = "twipsy right";
                  var arrow = document.createElement('DIV');
                  arrow.className = "twipsy-arrow";
                  div.appendChild(arrow);
                  var title = document.createElement('DIV');
                  title.className = "twipsy-inner";
                  div.appendChild(title);
                  this._div = div;
                  this._title = title;
                  this.message = '';
                  // add to frame div and display coordinates
                  frameDiv.appendChild(div);
                  var that = this;
                  div.onmousemove = function (evt) {
                     that.showAt({ x: evt.clientX, y: evt.clientY }, that.message);
                  };
               };
               tooltip.prototype.setVisible = function (visible) {
                  this._div.style.display = visible ? 'block' : 'none';
               };
               tooltip.prototype.showAt = function (position, message) {
                  if (position && message) {
                     this.setVisible(true);
                     this._title.innerHTML = message;
                     this._div.style.left = position.x + 10 + "px";
                     this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
                     this.message = message;
                  }
               };
               return new tooltip(frameDiv);
            }
            window.MYcreateTooltip = createTooltip;//全局使用
            var domHtmls = [//默认
               {
@@ -88,11 +45,11 @@
                  classs: 'profileAnalysis-tool',
                  img: './images/addL/剖面分析.png'
               }
               // , {//做好静态,
               //    name: '建造实体',
               //    classs: 'modelDiagram-tool',
               //    img: './images/addL/pdpx.png'
               // }
               , {//做好静态,
                  name: '建造实体',
                  classs: 'modelDiagram-tool',
                  img: './images/addL/pdpx.png'
               }
               // , {//https://blog.csdn.net/supermapsupport/article/details/100134590
               //    //需要iServer发布成三维服务
               //    name: '坡度分析',
@@ -109,15 +66,28 @@
                  classs: 'digTheEarth-tool',
                  img: './images/addL/pdpx.png'
               }
               // , {//方量分析//做好
               //    name: '方量分析',
               //    classs: 'volumeAnalysis-tool',
               //    img: './images/addL/pdpx.png'
               // }
               , {//方量分析//做好
                  name: '方量分析',
                  classs: 'volumeAnalysis-tool',
                  img: './images/addL/pdpx.png'
               },
               {//通视分析
                  name: '通视分析',
                  classs: 'throughSee-tool',
                  img: './images/addL/pdpx.png'
               },
               {//平面裁剪
                  name: '平面裁剪',
                  classs: 'clippingPlanes-tool',
                  img: './images/addL/pdpx.png'
               }
            ];
            that.beginSpatialAnalysis(domHtmls);
            var isit = false;
            $('.ccslius').click(() => {
               isit = false;
            })
            $('.ccsliu').dblclick(() => {//测试开关 点击图例其他的图片
               if (isit) {
@@ -156,6 +126,26 @@
                        classs: 'volumeAnalysis-tool',
                        img: './images/addL/pdpx.png'
                     }
                     , {//空间查询
                        name: '空间查询',
                        classs: 'spatialQuery-tool',
                        img: './images/addL/pdpx.png'
                     }
                     , {//多边形裁剪
                        name: '多边形裁剪',
                        classs: 'polygonClipping-tool',
                        img: './images/addL/pdpx.png'
                     },
                     {//通视分析
                        name: '通视分析',
                        classs: 'throughSee-tool',
                        img: './images/addL/pdpx.png'
                     },
                     {//平面裁剪
                        name: '平面裁剪',
                        classs: 'clippingPlanes-tool',
                        img: './images/addL/pdpx.png'
                     }
                     ,
                     {//建造模型
                        name: '建造模型',
@@ -173,7 +163,7 @@
                  var promise = false;
                  $('.modesssssllll').click(() => {
                     var URL_CONFIG = {
                        SCENE_CBD: 'http://www.supermapol.com/realspace/services/3D-CBDCache20200416/rest/realspace',
                        SCENE_CBD: 'http://www.supermapol.com/realspace/services/3D-niaochao/rest/realspace',
                     }
                     promise = this.map.scene.open(URL_CONFIG.SCENE_CBD);
                  })
@@ -193,6 +183,7 @@
            })
         },
         promise: 'NODATA',
         beginSpatialAnalysis: function (domHtmls) {
            var that = this;
            var domHtmls = domHtmls;
@@ -263,7 +254,250 @@
               topic.publish('beginVolumeAnalysis', 'beginVolumeAnalysis');
            })
            //空间查询
            $('.spatialQuery-tool').click(function () {
               that.closeOnceUse();
               $(".jimu-widget-spatialQuery").show();
               topic.publish('beginSpatialQuery', 'beginSpatialQuery');
            })
            //多边形裁剪
            $('.polygonClipping-tool').click(function () {
               that.closeOnceUse();
               $(".jimu-widget-polygonClipping").show();
               topic.publish('beginpolygonClipping', 'beginpolygonClipping');
            })
            //通视分析
            $('.throughSee-tool').click(function () {
               that.closeOnceUse();
               $(".jimu-widget-throughSee").show();
               topic.publish('beginthroughSee', 'beginthroughSee');
            })
            //平面裁剪
            $('.clippingPlanes-tool').click(function () {
               that.closeOnceUse();
               // console.log(that.promise, 22222222222)
               if (that.promise == 'NODATA') {
                  layer.tips('请选择三维倾斜数据中的图层支持!', '.SelectLayerTool', {
                     tips: [3, 'red']
                  });
               } else {
                  $(".jimu-widget-clippingPlanes").show();
                  topic.publish('beginclippingPlanes', that.promise);
               }
            })
            $('.SelectLayerTool').click(() => {
               $('#SelectLayerToolItem').toggle();
            })
            //参照Layemanagement
            topic.subscribe("appendItemS", lang.hitch(this, this.appendItemS));
            topic.subscribe("removeItemS", lang.hitch(this, this.removeItemS));
            topic.subscribe("appendTiltS", lang.hitch(this, this.appendTiltS));
            topic.subscribe("removeTiltS", lang.hitch(this, this.removeTiltS));
            this.liClick('默认:天地图影像', '默认:天地图影像');
         },
         morenliClick: (itemid, name) => {
            var dom = $('.SelectLayerTool');
            dom.empty();
            var str = `${name} <i class="layui-icon layui-icon-down layui-font-12"></i>`
            dom.append(str);
            // console.log('数据错误默认')
            this.promise = 'NODATA';
            //关闭平面裁剪
            if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏
               $(".jimu-widget-clippingPlanes").hide();
               topic.publish('closesclippingPlanes');
            }
         },
         liClick: function (itemid, name, ourdata = 1) {//点击事件
            var that = this;
            var liList = $(`[itemid='${itemid}s']`);
            // console.log(liList);
            liList.click(() => {
               // console.log(itemid)
               var dom = $('.SelectLayerTool');
               layer.tips('选择了:' + name, dom, { tips: [1, '#5FB878'] });
               dom.empty();
               var str = `${name} <i class="layui-icon layui-icon-down layui-font-12"></i>`
               dom.append(str);
               dom.attr("title", name);
               $('#SelectLayerToolItem').hide();
               // console.log(ourdata);
               // 定位
               // console.log(name)
               if (ourdata != 1) {
                  //    console.log('data')
                  if (ourdata.lon) {
                     that.map.camera.flyTo({
                        destination: Cesium.Cartesian3.fromDegrees(Number(ourdata.lon), Number(ourdata.lat), Number(ourdata.height * 50))
                     });
                  }
                  if (ourdata.src.indexOf('.openrealspace') != -1) {
                     // console.log('数据正确');
                     //关闭平面裁剪
                     if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏
                        $(".jimu-widget-clippingPlanes").hide();
                        topic.publish('closesclippingPlanes');
                     }
                     that.promise = {
                        src: ourdata.src,
                        name: ourdata.serviceName
                     };
                  } else {
                     // console.log('数据错误');
                     that.promise = 'NODATA';
                     //关闭平面裁剪
                     if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏
                        $(".jimu-widget-clippingPlanes").hide();
                        topic.publish('closesclippingPlanes');
                     }
                  }
               } else {
                  // console.log('数据错误没有data');
                  that.promise = 'NODATA';
                  //关闭平面裁剪
                  if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏
                     $(".jimu-widget-clippingPlanes").hide();
                     topic.publish('closesclippingPlanes');
                  }
               }
            })
         },
         appendItemS: function (item, obj, layer) {
            // console.log('a1')
            var that = this;
            if (item == this.name) {
               // $("#SelectLayerToolItemTitle .no-data").stop().hide();
               var flag = true;
               var liList = $("#SelectLayerToolItemTitle li");
               // console.log(liList)
               // console.log($('#SelectLayerToolItemTitle'))
               for (var i = 0; i < liList.length; i++) {
                  if ($(liList[i]).attr('itemid') && $(liList[i]).attr('itemid') == obj.id + 's') {
                     flag = false
                  }
               }
               if (flag == true) {
                  var liItem = $("<li itemid='" + obj.id + "s' itemtitle='" + obj.title + "'> <div>" +
                     "<span title='" + obj.title + "'>" +
                     obj.title +
                     "</span>" +
                     "</div> </li>");
                  that[obj.id] = layer;
                  $("#SelectLayerToolItemTitle").append(liItem);
               }
               that.liClick(obj.id, obj.title, obj);
            }
         },
         removeItemS: function (item, obj) {
            // console.log(obj, 'r1')
            var that = this;
            if (item == this.name) {
               var liList = $("#SelectLayerToolItemTitle li");
               for (var i = 0; i < liList.length; i++) {
                  if ($(liList[i]).attr('itemid') && $(liList[i]).attr('itemid') == obj.id + 's') {
                     $(liList[i]).remove();
                     var dom = $('.SelectLayerTool').attr("title");
                     // console.log(dom == obj.title, this.liClick)
                     if (dom == obj.title) {
                        that.morenliClick('默认:天地图影像', '默认:天地图影像');
                        that.promise = 'NODATA';
                     }
                  }
               }
               if ($("#SelectLayerToolItemTitle li").length == 1 && $("#SelectLayerToolItemTitle li").length == 0) {
                  $("#SelectLayerToolItemTitle .no-data").stop().show();
                  $(".jimu-widget-spatialAnalysis .tree-layer-opcity").stop().hide();
               }
            }
            // this.liClick();
         },
         appendTiltS: function (item, obj, layer) {
            // console.log('a2')
            var that = this;
            if (item == this.name) {
               // $("#SelectLayerToolItemTitle .no-data").stop().hide();
               var flag = true;
               var liList = $("#SelectLayerToolItemTitle li");
               for (var i = 0; i < liList.length; i++) {
                  if ($(liList[i]).attr('itemid') && $(liList[i]).attr('itemid') == obj.id + 's') {
                     flag = false
                  }
               }
               if (flag == true) {
                  var liItem = $("<li itemid='" + obj.id + "s' itemtitle='" + obj.title + "'> <div>" +
                     "<span title='" + obj.title + "'>" +
                     obj.title +
                     "</span>" +
                     "</div> </li>");
                  $("#SelectLayerToolItemTitle").append(liItem);
               }
               that.liClick(obj.id, obj.title, obj);
            }
         },
         removeTiltS: function (item, obj) {
            // console.log(obj, 'r2')
            // console.log('r2')
            var that = this;
            if (item == this.name) {
               var liList = $("#SelectLayerToolItemTitle li");
               for (var i = 0; i < liList.length; i++) {
                  if ($(liList[i]).attr('itemid') && $(liList[i]).attr('itemid') == obj.id + 's') {
                     $(liList[i]).remove();
                     var dom = $('.SelectLayerTool').attr("title");
                     if (dom == obj.title) {
                        that.morenliClick('默认:天地图影像', '默认:天地图影像');
                        that.promise = 'NODATA';
                     }
                  }
               }
               if ($("#SelectLayerToolItemTitle li").length == 1 && $("#SelectLayerToolItemTitle li").length == 0) {
                  // $("#SelectLayerToolItemTitle .no-data").stop().show();
                  // $(".jimu-widget-spatialAnalysis .tree-layer-opcity").stop().hide();
               }
            }
         },
         // beginRool: function (data) {
         //    //选择图层Layui
         //    layui.use(['dropdown', 'util', 'layer', 'table'], function () {
         //       var dropdown = layui.dropdown
         //          , layer = layui.layer;
         //       dropdown.render({
         //          elem: '.SelectLayerTool'
         //          , data: data
         //          , click: function (obj) {
         //             layer.tips('选择了:' + obj.title, this.elem, { tips: [1, '#5FB878'] });
         //             var dom = $('.SelectLayerTool');
         //             dom.empty();
         //             var str = `${obj.title} <i class="layui-icon layui-icon-down layui-font-12"></i>`
         //             dom.append(str);
         //          }
         //       });
         //    });
         // },
         closeToolBox: function (item) {
            if (item != this.name) {
               $('.tool-y-box').hide();
@@ -307,36 +541,34 @@
               $(".jimu-widget-digTheEarth").hide();
               topic.publish('closesDigTheEarth');
            }
            //关闭方量贩分析
            if ($(".jimu-widget-volumeAnalysis").is(":visible")) {//判断是否隐藏
               $(".jimu-widget-volumeAnalysis").hide();
               topic.publish('closesVolumeAnalysis');
            }
            //关闭空间查询
            if ($(".jimu-widget-spatialQuery").is(":visible")) {//判断是否隐藏
               $(".jimu-widget-spatialQuery").hide();
               topic.publish('closesSpatialQuery');
            }
            //关闭多边形裁剪
            if ($(".jimu-widget-polygonClipping").is(":visible")) {//判断是否隐藏
               $(".jimu-widget-polygonClipping").hide();
               topic.publish('closespolygonClipping');
            }
            //关闭通视分析
            if ($(".jimu-widget-throughSee").is(":visible")) {//判断是否隐藏
               $(".jimu-widget-throughSee").hide();
               topic.publish('closesthroughSee');
            }
            //关闭平面裁剪
            if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏
               $(".jimu-widget-clippingPlanes").hide();
               topic.publish('closesclippingPlanes');
            }
         },
         onOpen: function () {
            //面板打开的时候触发 (when open this panel trigger)
            // var domHtmls = [
            //    {
            //       name: '可视分析',
            //       classs: 'visibleArea-tool'
            //    }, {
            //       name: '剖面分析',
            //       classs: 'profileAnalysis-tool'
            //    }, {
            //       name: '坡度分析',
            //       classs: 'slope-tool'
            //    },
            // ];
            // var dom = $('#spatialAnalysis-main');
            // var str = '';
            // for (var k in domHtmls) {
            //    str += `<li class="${domHtmls[k].classs}"><i></i> <span>${domHtmls[k].name}</span></li>`
            // }
            // dom.replaceWith(str);
         },
         onClose: function () {