// 开场动画
function startAnimation() {
map.flyHome({ duration: 0 })
map.openFlyAnimation({
// duration1:4,
// easingFunction1: Cesium.EasingFunction.QUINTIC_IN_OUT,
callback: function () {
// 动画播放完成后回调
}
})
}
//添加蒙版
function maskDiv() {
var maskDiv = document.createElement("div")
maskDiv.id = "maskDiv";
maskDiv.style.cssText = `
position: absolute;
top:0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 9;
background-image:
radial-gradient(rgba(139, 138, 138, 0.219) 50%, rgba(1, 1, 1, 0.8) 80%, rgba(17, 16, 16, 0.9) 90%);
`
document.body.appendChild(maskDiv)
}
//实时人员位置数据
function showCarList() {
// 创建矢量数据图层
graphicLayer = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer)
// 鼠标移入提示信息
graphicLayer.bindTooltip(function (event) {
var attr = event.graphic?.attr
if (!attr) {
return
}
return '名称:'+attr.name+'
编号:'+attr.id
})
// 单击地图空白处
map.on(mars3d.EventType.clickMap, function (event) {
if (lastClickCar) {
lastClickCar.circle.show = false
lastClickCar = null
}
GongJuLanHide()
})
// 绑定点击事件
graphicLayer.on(mars3d.EventType.click, (event, position) => {
var car = event.graphic
personMsgtid(car.attr.id)
if (lastClickCar) {
if (lastClickCar === car) {
return
} // 重复单击,跳出
lastClickCar.circle.show = false
lastClickCar = null
}
car.circle.show = true
lastClickCar = car
})
var lastClickCar
let PersonsList = [];
// 定义一个存储已添加模型的ID集合
let addedCarIds = new Set();
// 定义一个获取人员列表的函数
function fetchPersonsList() {
$.ajax({
async: false,
type: 'GET',
traditional: true,
url: "/hxzkuwb/getGPSCesium",
dataType: 'json',
data: {},
success: function (data) {
PersonsList = data;
// 记录当前在线人员的ID
const currentOnlineIds = new Set();
const currentNoOnlineIds = new Set();
// 遍历人员列表
PersonsList.forEach(item => {
item.show = true;
item.type = 1;
// 仅处理在线人员
if (item.online === "1") { // 使用 '===' 比较
currentOnlineIds.add(item.id);
// 检查是否已添加过模型
if (!addedCarIds.has(item.id)) {
let modelParam;
switch (item.type) {
case 1:
modelParam = {
scale: 2,
url: "//data.mars3d.cn/gltf/mars/car/tufangche.glb"
};
break;
case 2:
modelParam = {
scale: 1,
url: "//data.mars3d.cn/gltf/mars/car/wajueji.glb"
};
break;
default:
modelParam = {};
}
let car = new mars3d.graphic.Route({
id: item.id,
name: item.name,
maxCacheCount: -1,
model: {
...modelParam,
clampToGround: true
},
label: {
text: item.name + " " + item.id,
font_size: 16,
color: "#ffffff",
outline: true,
outlineColor: "#000000",
distanceDisplayCondition: true,
pixelOffsetY: -20,
distanceDisplayCondition_near: 10,
visibleDepth: false
},
circle: {
radius: 50,
materialType: mars3d.MaterialType.CircleWave,
materialOptions: {
color: "red",
opacity: 0.3,
speed: 10,
count: 3,
gradient: 0.1
},
clampToGround: true,
show: false
},
attr: item
});
// 将模型添加到图层中
graphicLayer.addGraphic(car);
// 将已添加模型的ID记录到集合中
addedCarIds.add(item.id);
}
} else {
currentNoOnlineIds.add(item.id);
// 移除不在线人员的模型
if (addedCarIds.has(item.id)) {
// 通过 ID 查找对应的图形并移除
graphicLayer.getGraphics().forEach(graphic => {
if (graphic.id === item.id) {
graphicLayer.removeGraphic(graphic);
currentNoOnlineIds.delete(item.id)
}
});
addedCarIds.delete(item.id); // 移除 ID 记录
}
}
});
}
});
}
// 定义一个更新轨迹的函数
function updateTrajectories() {
$.ajax({
async: false,
type: 'GET',
traditional: true,
url: "/hxzkuwb/getGPS",
dataType: 'json',
data: {},
headers: {
},
success: function (data) {
var listALL = data;
graphicLayer.eachGraphic((car) => {
// 取出对应车辆的轨迹列表
var path = listALL.filter((item) => item.ptagid === car.id);
path.forEach((item) => {
var point = new mars3d.LngLatPoint(item.baoliu2, item.baoliu3, 0);
car.addDynamicPosition(point, item.paddtiem);
});
});
}
});
}
// 每五秒获取一次人员列表
setInterval(fetchPersonsList, 5000);
// 每两秒更新一次轨迹
setInterval(updateTrajectories, 2000);
// 页面加载时立即获取一次人员列表
fetchPersonsList();
}
//添加围栏
function addfence() {
var fences = [];
var fencesName = [];
$.ajax({
url: "/hxzkuwb/baidufenceName.do",
type: "GET",
async: false, // 设置为 false 以使请求同步
success: function(data) {
fencesName = data;
},
error: function(xhr, status, error) {
console.error("请求失败: ", status, error);
}
});
$.ajax({
async: false, //同步的
type: "GET",
url: "/hxzkuwb/baidufence.do",
dataType: "json",
success: function (data) {
fences = data.fences;
for (let i = 0 ; i