define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/_base/array',
'dojo/_base/html',
"dojo/topic",
'jimu/BaseWidget',
'dojo/on',
'jimu/dijit/Popup',
'./GeologicalDisasterPanel'
],
function (declare,
lang,
array,
html,
topic,
BaseWidget,
on,
Popup,
GeologicalDisasterPanel
) {
return declare([BaseWidget], {
baseClass: 'jimu-widget-PathShow',
name: 'PathShow',
shidiLayer: null,
datas: null,
polyline: null,
layer: null,
startup: function () {
this.inherited(arguments);
var self = this;
$.ajax({
url: 'widgets/PathShow/jddatas.json',
type: "POST",
dataType: "json",
success: function success(data) {
self.datas = data.data;
self.createList(data.data);
}
});
//添加地图点击事件
this.addHandler();
},
onMinimize: function () {
// this.resize();
},
onMaximize: function () {
// this.resize();
},
onOpen: function () {
//面板打开的时候触发,添加标签到地图上
var self = this;
window.openAudioName = this.name;
self.map.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(115.737419, 28.747867, 32000)
});
},
onClose: function () {
//面板打开的时候触发,删除地图上标签
var self = this;
self.map.entities.removeAll();
self._controlSendAll(false);
$('#chosePage').attr('style', 'display:block;');
$('#intro').attr('style', 'display:none');
$('#PathShow_qj').attr('src', '');
$("#PathShow_bgMusic").attr('src', '');
for (var i = 0; i < this.datas.length; i++) {
clearTimeout(this.datas[i].settimeoutId);
}
},
// resize: function() {
// },
destroy: function () {
this.inherited(arguments);
},
//关键字过滤
query: function () {
var text = this.keyNode.value;
if (text != "" && text.length > 0) {
var list = array.filter(this.datas, function (g) {
if (g.name.indexOf(text) > -1) {
return true;
} else {
return false;
}
}, this);
$('.jimu-widget-PathShow ul li').remove();
this.createList(list);
} else {
$('.jimu-widget-PathShow ul li').remove();
this.createList(this.datas);
}
},
createList: function (dataList) {
var self = this;
dataList.forEach(function (element, index) {
$(".jimu-widget-PathShow .PathShow-listul").append("
" + (index + 1) + "、" +
element.name + "
");
}, this);
//添加li点击事件,地图定位
$('.jimu-widget-PathShow .PathShow-listul li span').click(function () {
$(".jimu-widget-PathShow .PathShow-listul li span").removeClass("bck_color");
$(this).addClass("bck_color");
});
//添加li点击事件,地图定位
$('.jimu-widget-PathShow .PathShow-listul li').click(function () {
let selectItem = this.innerText.trim();
selectItem = selectItem.split("、")[1];
var ids = $(this).attr("id");
var ar = dataList.find(function (elem) {
return elem.name == selectItem && elem.id == ids;
});
//清除地图点
self.map.entities.removeAll();
self.addPoint(ar);
$.ajax({
url: 'widgets/PathShow/datas.json',
type: "POST",
dataType: "json",
success: function success(res) {
for (var i = 0; i < res.features.length; i++) {
if (res.features[i].attributes.Name == selectItem) {
self.addLines(res.features[i]);
self.map.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(res.features[i].attributes.x, res.features[i].attributes.y, res.features[i].attributes.height)
});
}
}
}
});
});
},
loadChirden: function (item) {
//切换显示
$('#chosePage').attr('style', 'display:none');
$('#intro').attr('style', 'display:block');
$(".hudong-head").stop().hide();
//添加图片
$('.jimu-widget-PathShow .PathShow-enlarge-img .PathShow-enlarge-main .PathShow-enlarge-content ul').empty();
$('.jimu-widget-PathShow .PathShow-child-text div .PathShow-child-img-main .PathShow-child-img-content ul').empty();
// 单张图片的处理方式
$(".jimu-widget-PathShow .PathShow-enlarge-img .PathShow-enlarge-main .PathShow-enlarge-left").stop().hide();
$(".jimu-widget-PathShow .PathShow-enlarge-img .PathShow-enlarge-main .PathShow-enlarge-right").stop().hide();
$(".jimu-widget-PathShow .PathShow-child-text div .PathShow-child-img-main .PathShow-child-img-left").stop().hide();
$(".jimu-widget-PathShow .PathShow-child-text div .PathShow-child-img-main .PathShow-child-img-right").stop().hide();
$('.jimu-widget-PathShow .PathShow-enlarge-img .PathShow-enlarge-main .PathShow-enlarge-content ul').append("
");
$('.jimu-widget-PathShow .PathShow-child-text div .PathShow-child-img-main .PathShow-child-img-content ul').append("
");
},
addHandler: function () {
var handler = new Cesium.ScreenSpaceEventHandler(this.map.scene.canvas);
handler.setInputAction(lang.hitch(this, this.clickHandler), Cesium.ScreenSpaceEventType.LEFT_CLICK);
},
clickHandler: function (movement) {
var self = this;
var pickedObjects = self.map.scene.drillPick(movement.position);
if (Cesium.defined(pickedObjects)) {
for (var i = 0; i < pickedObjects.length; ++i) {
var obj = pickedObjects[i].id;
for (var j = 0; j < self.datas.length; j++) {
if (obj.id.split("path")[1] == self.datas[j].id) {
self.openWindow(obj.id.split("path")[0], self.datas[j]);
return;
}
}
}
}
},
addLines: function (result) {
var res = result.geometry.paths[0];
var id = result.OBJECTID;
var self = this;
if (self.polyline != null) {
self.layer.remove(self.polyline);
}
var positions = '';
for (var i = 0; i < res.length; i++) {
if (i != res.length - 1) {
positions += res[i][0] + ',' + res[i][1] + ';';
} else {
positions += res[i][0] + ',' + res[i][1];
}
}
self.layer = new DC.VectorLayer('layer')
window.dcViewer.addLayer(self.layer)
self.polyline = new DC.Polyline(positions);
self.polyline.setStyle({
width: 10,
material: new DC.PolylineImageTrailMaterialProperty({
speed: 20,
image: './images/arrow.png',
repeat: {x: 40, y: 1}
}),
clampToGround: true
});
self.layer.addOverlay(self.polyline);
let position = new DC.Position(115.70683949300007, 28.80868520100006);
let circle = new DC.Circle(position, 2000)
circle.setStyle({
material: new DC.ImageMaterialProperty({
image: './images/circle_bg.png'
})
})
circle.rotateAmount = 0.01
let model = new DC.Model(position, './images/zhui.glb')
model.setStyle({
scale: 100
})
model.rotateAmount = 4
self.layer.addOverlay(model).addOverlay(circle)
},
addPoint: function (res) {
var result = res.lx;
var self = this;
for (var i = 0; i < result.length; i++) {
var imgs = "";
imgs = "./widgets/PathShow/img/viewpoint.png";
self.map.entities.add({
id: result[i].id + "path" + res.id,
position: Cesium.Cartesian3.fromDegrees(Number(result[i].x), Number(result[i].y), 200),
label: {
text: result[i].title,
font: "700 16px '黑体'",
fillColor: Cesium.Color.PALETURQUOISE,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 2,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
horizontalOrigin: Cesium.HorizontalOrigin.TOP,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
pixelOffset: new Cesium.Cartesian2(0, -9),
pixelOffsetScaleByDistance: new Cesium.NearFarScalar(1.5e2, 3.0, 1.5e7, 0.5)
},
billboard: {
image: imgs,
scale: 0.8,
width: 30,
height: 35,
pixelOffset: new Cesium.Cartesian2(0, 0),
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
}
});
}
},
// 点击弹出面板;
openWindow: function (id, item) {
for (var i = 0; i < item.lx.length; i++) {
if (id == item.lx[i].id) {
var xb = i;
layer.open({
title: item.lx[xb].title,
type: 2,
shadeClose: true,
shade: false,
maxmin: false, //开启最大化最小化按钮
area: ['802px', '526px'],
content: "./widgets/Scenic/popup/popup.html",
id: "popup",
closeBtn: 1,
success: function (layero, index) {
// 传递index给子页面
//var iframe = window['layui-layer-iframe' + index];
//iframe.child(item.lx[xb]);
}
});
}
}
},
});
});