From 1a2c1d005bf7de2528f73638fb24d31da812aad5 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Tue, 22 Jun 2021 17:40:13 +0800
Subject: [PATCH] 增加模型
---
widgets/LeftNavigationBar/Widget.js | 431 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 288 insertions(+), 143 deletions(-)
diff --git a/widgets/LeftNavigationBar/Widget.js b/widgets/LeftNavigationBar/Widget.js
index 737ff9e..d12bce2 100644
--- a/widgets/LeftNavigationBar/Widget.js
+++ b/widgets/LeftNavigationBar/Widget.js
@@ -27,6 +27,7 @@
baseClass: 'jimu-widget-LeftNavigationBar',
name: 'LeftNavigationBar',
layers: {},
+ dataAllArray: [],
startup: function () {
// 暴露在外的接口
// this.begin(this.data);
@@ -36,7 +37,7 @@
$('.left-navigation-bar-but').click(() => {
this.changeImg = !this.changeImg;
if (this.changeImg) {
- $('.l-n-b-b-img').attr("src", "../../images/addL/xzuo.png"); //打开
+ $('.l-n-b-b-img').attr("src", "./images/addL/xzuo.png"); //打开
$('.jimu-widget-LeftNavigationBar').css({
'left': '0px'
});
@@ -44,7 +45,7 @@
'left': '260px'
});
} else {
- $('.l-n-b-b-img').attr("src", "../../images/addL/xyou.png"); //关闭
+ $('.l-n-b-b-img').attr("src", "./images/addL/xyou.png"); //关闭
$('.jimu-widget-LeftNavigationBar').css({
'left': '-250px'
});
@@ -58,12 +59,50 @@
$('.jimu-widget-instructions').css({
'left': '260px'
});
+
$('#left-navigation-bar-main-search').click(() => { //搜索事件
+ leftSearchItemLayer()
+ })
+
+ $(".jimu-widget-LeftNavigationBar input[type='search']").bind('input propertychange', function () {
+ //做一些事情
+ var val = $(this).val();
+
+ if (val == '') {
+ that.changeData(that.dataAllArray, val); //重写数据
+ layui.use('tree', function () {
+ layui.tree.reload('demoId1', {
+ data: that.data
+ });
+
+ var jqDom = $("#left-tree-list > .layui-tree > div");
+
+ for (var i = 0; i < jqDom.length; i++) {
+
+ var textList = $(jqDom[i]).find('.layui-tree-txt');
+
+ for (var j = 0; j < textList.length; j++) {
+ $(textList[j]).attr('title', $(textList[j]).text())
+
+ }
+
+ }
+ })
+ }
+
+ })
+
+ $(".jimu-widget-LeftNavigationBar input[type='search']").keyup(function (e) {
+ if (e.keyCode == 13) {
+ leftSearchItemLayer()
+ }
+ })
+
+ function leftSearchItemLayer() {
var val = $('#left-navigation-bar-main-input').val();
- if (val) {
+ if (val != '') {
var clearOur = () => {
let dom = $(`[data-id]`);
- // console.log(dom);
dom.removeClass('layui-tree-spread');
let domDiv = dom.find('.layui-tree-pack');
domDiv.css({
@@ -75,12 +114,11 @@
if (d[k].who == 'father') {
that.father = d[k].id;
}
- if (d[k].title.indexOf(val) != -1) { //选中id
+ if (d[k].title && d[k].title.indexOf(val) != -1) { //选中id
a = '' + d[k].id;
// var b = a.split('');
// for (var i in b) {
let id = that.father; //选中项的所有父级id
- // // console.log(id)
let dom = $(`[data-id='${id}']`);
dom.addClass('layui-tree-spread');
let domDiv = dom.find('.layui-tree-pack').eq(0);
@@ -88,23 +126,37 @@
'display': 'block'
})
// }
- console.log(a, that.father)
}
- if (d[k].children) {
+ if (d[k].children && d[k].children.length > 0) {
useit(d[k].children);
}
}
};
- clearOur();
- useit(that.data);
- } else {
+
+ that.changeData(that.dataAllArray, val); //重写数据
+ layui.use('tree', function () {
+ layui.tree.reload('demoId1', {
+ data: that.data
+ });
+ var jqDom = $("#left-tree-list > .layui-tree > div");
+
+ for (var i = 0; i < jqDom.length; i++) {
+
+ var textList = $(jqDom[i]).find('.layui-tree-txt');
+
+ for (var j = 0; j < textList.length; j++) {
+ $(textList[j]).attr('title', $(textList[j]).text())
+
+ }
+
+ }
+
+ clearOur();
+ useit(that.data);
+ })
}
- })
-
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity .close").click(function () {
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity").stop().hide();
- })
+ }
},
closeToolBox: function (item) {},
@@ -130,6 +182,7 @@
},
getData: function () {
+ var that = this;
var url = 'http://171.34.76.171:8880/pyh-wetResource/GeoData/queryGeoDataTree',
that = this;
@@ -139,17 +192,21 @@
}
}).then((res) => {
if (res.data.code == '200') {
- console.log(res, 'open', 898998)
- that.changeData(res.data.data); //重写数据
+ that.dataAllArray = res.data.data;
+ that.changeData(res.data.data, ''); //重写数据
+ that.begin(this.data);
}
})
},
- changeData: function (val) { //重写数据
+ changeData: function (val, type) { //重写数据
+ var that = this;
var data = [],
i = 1,
inits = (d, childData) => {
var b = childData || [];
for (var k in d) {
+
+
let a = {
title: d[k].name,
@@ -160,10 +217,15 @@
src: d[k].serviceUrl,
id: d[k].id,
serviceName: d[k].serviceName,
- alpha: 1
+ alpha: 1,
+ checked: d[k].menuStatus
}
- if (d[k].serviceUrl.indexOf('.openrealspace') != -1) {
+ if (that[d[k].id]) {
+ a.alpha = that[d[k].id].alpha
+ }
+
+ if (d[k].serviceUrl && d[k].serviceUrl.length > 0 && d[k].serviceUrl.indexOf('.openrealspace') != -1) {
a.model = true
}
@@ -171,10 +233,21 @@
a.model = true
}
+ if (a.model) {
+
+ if (that[a.id]) {
+ Cesium.when(that[a.id], function (layer) {
+ that.map.scene.layers.remove(layer[0].name)
+ })
+ }
+
+ }
+
+
b.push(a);
i++;
- if (d[k].children.length != 0) {
+ if (d[k].children && d[k].children.length > 0) {
b[k].children = [];
b[k].who = 'father';
inits(d[k].children, b[k].children)
@@ -183,23 +256,94 @@
};
inits(val, data);
- // console.log(data)
- // var i = 0,
- // ccinit = (a) => {
- // i++;
- // for (let k in a) {
- // if (a[k].children) {
- // a[k].who = i;
- // // console.log(a[k].id)
- // ccinit(a[k].children)
- // }
- // }
- // };
- // ccinit(this.data);
- // console.log(this.data)
+ if (type != '') {
+
+ for (var i = 0; i < data.length; i++) {
+
+ if (data[i].children && data[i].children.length > 0) {
+
+ deWeight()
+
+ function deWeight() {
+ for (var j = 0; j < data[i].children.length; j++) {
+
+ if (data[i].children[j].checked == true) {
+ var small = data[i].children[j];
+ if (small.model) {
+ that.map.scene.globe.depthTestAgainstTerrain = false;
+ var host = that.returnStr(small.src).host;
+ var scene = that.map.scene;
+ var partOfUrl = that.returnStr(small.src).partOfUrl;
+ //添加S3M图层服务
+ that[small.id] = scene.open(host + partOfUrl);
+ }
+ }
+
+ if (data[i].children[j].title && data[i].children[j].title.indexOf(type) == -1) {
+ data[i].children.splice(j, 1);
+ deWeight();
+ break;
+
+ }
+
+ }
+ }
+
+ }
+
+
+
+
+
+ }
+ deParentWeight()
+
+ function deParentWeight() {
+ for (var i = 0; i < data.length; i++) {
+
+ if (data[i].children && data[i].children.length == 0) {
+ data.splice(i, 1)
+ deParentWeight();
+ break;
+ }
+
+ if (data[i].children == undefined && data[i].title.indexOf(type) == -1) {
+ data.splice(i, 1)
+ deParentWeight();
+ break;
+
+ }
+
+ }
+ }
+
+ }
+
+ var keyId = this.getUrlKeyId("serviceId");
+
+ if (keyId && keyId != "") {
+ for (var i = 0; i < data.length; i++) {
+
+ if (data[i].id == keyId) {
+ data[i].checked = true
+ }
+
+ for (var j = 0; j < data[i].children.length; j++) {
+
+ if (data[i].children[j].id == keyId) {
+ data[i].children[j].checked = true
+ }
+
+ }
+ }
+ }
+
+
+
this.data = data;
- this.begin(this.data);
+
+
},
begin: function (data) {
var that = this;
@@ -223,7 +367,6 @@
click: function (obj) {
var data = obj.data; //获取当前点击的节点数据
// layer.msg('状态:' + obj.state + '<br>节点数据:' + JSON.stringify(data));
- console.log(obj);
// 树点击三角形样式修改
// var ot = $('.layui-tree-iconArrow');
// ot.removeClass("left-navigation-bar-main-down");
@@ -237,9 +380,8 @@
},
showLine: false, //是否开启连接线
oncheck: function (obj) {
- console.log(obj.data.id, '--', obj.checked, obj); //得到当前点击的节点数据
- // console.log(obj.checked); //得到当前节点的展开状态:open、close、normal
- // console.log(obj.elem); //得到当前节点元素
+
+ var keyId = that.getUrlKeyId("serviceId");
if (obj.data.children && obj.data.children.length > 0) {
@@ -286,20 +428,38 @@
});
});
} else {
- obj.data.children.forEach(item => {
- $.ajax({
- url: item.src + '/maps.json',
- type: 'get',
- dataType: 'JSON',
- success: function (res) {
- that[item.id] = that.map.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
- url: res[0].path,
- }));
- that[obj.data.id].alpha = item.alpha
- }
- })
+ obj.data.children.forEach(item => {
+
+ if (that[item.id]) {
+ that[item.id].show = true
+ topic.publish('appendItem', 'Layermanagement', item, that[item.id]);
+ } else {
+ $.ajax({
+ url: item.src + '/maps.json',
+ type: 'get',
+ dataType: 'JSON',
+ success: function (res) {
+
+
+ that[item.id] = that.map.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
+ url: res[0].path,
+ }));
+ topic.publish('appendItem', 'Layermanagement', item, that[item.id]);
+ that[item.id].alpha = item.alpha
+
+ if (keyId && keyId != "") {
+ that[item.id].getViewableRectangle().then(function (rectangle) {
+ return that.map.camera.flyTo({
+ destination: rectangle
+ });
+ });
+ }
+ }
+ })
+ }
});
+
}
@@ -317,7 +477,10 @@
});
} else {
obj.data.children.forEach(item => {
- if (that[item.id]) that.map.imageryLayers.remove(that[item.id]);
+ if (that[item.id]) {
+ topic.publish('removeItem', 'Layermanagement', item);
+ that[item.id].show = false;
+ }
});
}
@@ -333,12 +496,14 @@
if (obj.checked == true) {
if (obj.data.model) {
+ that.map.scene.globe.depthTestAgainstTerrain = false;
var host = that.returnStr(obj.data.src).host;
var scene = that.map.scene;
var partOfUrl = that.returnStr(obj.data.src).partOfUrl;
//添加S3M图层服务
that[obj.data.id] = scene.open(host + partOfUrl);
//定位到场景
+
Cesium.loadJson(host + partOfUrl + '/scenes.json').then(function (scenes) {
// var sname = scenes[0].name;
// Cesium.loadJson(host + partOfUrl + '/scenes/' + sname + '.json').then(function (jsonData) {
@@ -368,19 +533,37 @@
} else {
- $.ajax({
- url: obj.data.src + '/maps.json',
- type: 'get',
- dataType: 'JSON',
- success: function (res) {
- console.log(res, 123)
+ if (that[obj.data.id]) {
+ that[obj.data.id].show = true;
+ topic.publish('appendItem', 'Layermanagement', obj.data, that[obj.data.id]);
+ } else {
+ $.ajax({
+ url: obj.data.src + '/maps.json',
+ type: 'get',
+ dataType: 'JSON',
+ success: function (res) {
- that[obj.data.id] = that.map.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
- url: res[0].path,
- }));
- that[obj.data.id].alpha = obj.data.alpha
- }
- })
+
+ that[obj.data.id] = that.map.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
+ url: res[0].path,
+ }));
+
+ topic.publish('appendItem', 'Layermanagement', obj.data, that[obj.data.id]);
+
+ that[obj.data.id].alpha = obj.data.alpha
+
+ if (keyId && keyId != "") {
+ that[obj.data.id].getViewableRectangle().then(function (rectangle) {
+ return that.map.camera.flyTo({
+ destination: rectangle
+ });
+ });
+ }
+ }
+ })
+ }
+
+
}
@@ -393,7 +576,11 @@
})
} else {
- that.map.imageryLayers.remove(that[obj.data.id]);
+
+ if (that[obj.data.id]) {
+ topic.publish('removeItem', 'Layermanagement', obj.data);
+ that[obj.data.id].show = false;
+ }
}
@@ -403,100 +590,53 @@
}
+
+ for (var i = 0; i < that.dataAllArray.length; i++) {
+
+ if (obj.data.id == that.dataAllArray[i].id) {
+ that.dataAllArray[i].menuStatus = 1;
+ break
+ }
+
+ if (that.dataAllArray[i].children && that.dataAllArray[i].children.length > 0) {
+
+ for (var j = 0; j < that.dataAllArray[i].children.length; j++) {
+
+ if (obj.data.id == that.dataAllArray[i].children[j].id) {
+ that.dataAllArray[i].children[j].menuStatus = 1;
+ break
+ }
+
+ }
+ }
+
+ }
},
- edit: ['add'],
operate: function (obj) {
var type = obj.type; //得到操作类型: add、edit、 del
var data = obj.data; //得到当前节点的数据
var elem = obj.elem; //得到当前节点元素var deptId = data.id;//得到节点索引var parentId = data.parentId;l/父节点
var depId = data.id;
var parentId = data.parentId;
- if (type == 'add') {
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity ul").empty();
-
-
-
- console.log(type, data, elem, depId, parentId)
-
- if (data.children) {
-
- data.children.forEach(item => {
- var liC = `<li>
- <div title="${item.title}">
- ${item.title}
- </div>
- <div id="${item.id + 'Layer'}">
-
- </div>
- </li>`;
-
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity ul").append(liC)
-
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity").stop().show();
- slider.render({
- elem: '#' + item.id + 'Layer',
- min: 0,
- max: 10,
- value: item.alpha * 10,
- step: 1,
- theme: '#1E9FFF',
- showstep: true,
- change: function (value) {
- item.alpha = value / 10
- if (that[item.id]) {
- that[item.id].alpha = item.alpha
- }
- }
- });
- })
-
- } else {
- var liC = `<li>
- <div title="${data.title}">
- ${data.title}
- </div>
- <div id="${data.id + 'Layer'}">
-
- </div>
- </li>`;
-
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity ul").append(liC)
-
- $(".jimu-widget-LeftNavigationBar .tree-layer-opcity").stop().show();
- slider.render({
- elem: '#' + data.id + 'Layer',
- min: 0,
- max: 10,
- value: data.alpha * 10,
- step: 1,
- theme: '#1E9FFF',
- showstep: true,
- change: function (value) {
- data.alpha = value / 10
- if (that[data.id]) {
- that[data.id].alpha = data.alpha
- }
- }
- });
-
-
- }
-
-
- }
}
});
- console.log($("#left-tree-list > .layui-tree > div"))
var jqDom = $("#left-tree-list > .layui-tree > div");
for (var i = 0; i < jqDom.length; i++) {
if ($(jqDom[i]).text().indexOf("三维倾斜数据") != -1) {
$(jqDom[i]).find('.layui-btn-group').remove()
+ }
+
+ var textList = $(jqDom[i]).find('.layui-tree-txt');
+
+ for (var j = 0; j < textList.length; j++) {
+ $(textList[j]).attr('title', $(textList[j]).text())
}
+
}
@@ -509,7 +649,6 @@
layer.alert(JSON.stringify(checkedData), {
shade: 0
});
- console.log(checkedData);
},
setChecked: function () {
tree.setChecked('demoId1', [12, 114]); //勾选指定节点
@@ -823,6 +962,12 @@
}]
}],
}],
+ getUrlKeyId: function (name) {
+ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
+ var r = window.location.search.substr(1).match(reg);
+ if (r != null) return decodeURI(r[2]);
+ return null;
+ },
destroy: function () {
//销毁的时候触发
//todo
--
Gitblit v1.9.3