711 lines
31 KiB
JavaScript
711 lines
31 KiB
JavaScript
|
|
|
||
|
|
function drawPath(configOptions) {
|
||
|
|
setContainer(configOptions);
|
||
|
|
container.innerHTML = '';
|
||
|
|
// container.ondrop = function(event){
|
||
|
|
// drop(event, configOptions, pointsLinkedList);
|
||
|
|
// };
|
||
|
|
// container.ondragover = function(event){
|
||
|
|
// allowDrop(event);
|
||
|
|
// };
|
||
|
|
var pointInflectionStyle = configOptions.pointsStyle.pointInflectionStyle;
|
||
|
|
var pointDefaultStyle = configOptions.pointsStyle.pointDefaultStyle;
|
||
|
|
var pointCompleteStyle = configOptions.pointsStyle.pointCompleteStyle;
|
||
|
|
var pointAbnormalStyle = configOptions.pointsStyle.pointAbnormalStyle;
|
||
|
|
var pointAlarmStyle = configOptions.pointsStyle.pointAlarmStyle;
|
||
|
|
var lineDefaultStyle = configOptions.linesStyle.lineDefaultStyle;
|
||
|
|
var lineCompleteStyle = configOptions.linesStyle.lineCompleteStyle;
|
||
|
|
var lineAbnormalStyle = configOptions.linesStyle.lineAbnormalStyle;
|
||
|
|
var lineAlarmStyle = configOptions.linesStyle.lineAlarmStyle;
|
||
|
|
var pointsLinkedList = new LinkedList();
|
||
|
|
configOptions.points.forEach(function(item,index) {
|
||
|
|
// if(item['type'] === '1') {
|
||
|
|
// item['pointStyle'] = pointInflectionStyle;
|
||
|
|
// } else {
|
||
|
|
// item['pointStyle'] = pointDefaultStyle;
|
||
|
|
// }
|
||
|
|
if(item.type === '1') {
|
||
|
|
item['pointStyle'] = pointInflectionStyle;
|
||
|
|
}
|
||
|
|
item['pointStyle'] = pointDefaultStyle;
|
||
|
|
item['patrolPlanId'] = configOptions.patrolPlanId;
|
||
|
|
pointsLinkedList.add(index,item);
|
||
|
|
});
|
||
|
|
|
||
|
|
pointsLinkedList.getItems().forEach(function(item, index) {
|
||
|
|
pointsLinkedList.set(index,item);
|
||
|
|
})
|
||
|
|
var points = deepClone(pointsLinkedList.getItems());
|
||
|
|
if(points.length && points.length === 1) {
|
||
|
|
// if(points[0].type === '1') {
|
||
|
|
// points[0]["pointStyle"] = pointInflectionStyle;
|
||
|
|
// } else {
|
||
|
|
// points[0]["pointStyle"] = pointDefaultStyle;
|
||
|
|
// }
|
||
|
|
|
||
|
|
if(points[0].status === '3') {
|
||
|
|
points[0]["pointStyle"] = pointCompleteStyle;
|
||
|
|
} else {
|
||
|
|
points[0]["pointStyle"] = pointDefaultStyle;
|
||
|
|
}
|
||
|
|
drawPoint(points[0], configOptions, pointsLinkedList);
|
||
|
|
} else {
|
||
|
|
for(var i = 0, len = points.length; i < len; i++) {
|
||
|
|
// if(points[i].type === "1") {
|
||
|
|
// points[i]["pointStyle"] = pointInflectionStyle;
|
||
|
|
// } else {
|
||
|
|
switch(points[i].status) {
|
||
|
|
// case '1':
|
||
|
|
// points[i]["pointStyle"] = pointCompleteStyle;
|
||
|
|
// break;
|
||
|
|
// case '2':
|
||
|
|
// points[i]["pointStyle"] = pointAbnormalStyle;
|
||
|
|
// break;
|
||
|
|
case '3':
|
||
|
|
//points[i]["pointStyle"] = pointAlarmStyle;
|
||
|
|
points[i]["pointStyle"] = pointCompleteStyle;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
points[i]["pointStyle"] = pointDefaultStyle;
|
||
|
|
}
|
||
|
|
// }
|
||
|
|
if(i === 0) {
|
||
|
|
switch(points[0].status) {
|
||
|
|
case '3':
|
||
|
|
configOptions.pointsStyle = pointCompleteStyle;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
configOptions.pointsStyle = pointDefaultStyle;
|
||
|
|
}
|
||
|
|
console.log(configOptions);
|
||
|
|
drawPoint(points[0], configOptions, pointsLinkedList);
|
||
|
|
}
|
||
|
|
if (i < len - 1) {
|
||
|
|
// if(points[i+1].type === "1"){
|
||
|
|
// switch(points[i+1].status) {
|
||
|
|
// case '1':
|
||
|
|
// pointInflectionStyle.borderColor = pointCompleteStyle.borderColor;
|
||
|
|
// lineDefaultStyle.lineColor = pointCompleteStyle.borderColor;
|
||
|
|
// break;
|
||
|
|
// case '2':
|
||
|
|
// pointInflectionStyle.borderColor = pointAbnormalStyle.borderColor;
|
||
|
|
// lineDefaultStyle.lineColor = pointAbnormalStyle.borderColor;
|
||
|
|
// break;
|
||
|
|
// case '3':
|
||
|
|
// pointInflectionStyle.borderColor = pointAlarmStyle.borderColor;
|
||
|
|
// lineDefaultStyle.lineColor = pointAlarmStyle.borderColor;
|
||
|
|
pointInflectionStyle.borderColor = pointCompleteStyle.borderColor;
|
||
|
|
// lineDefaultStyle.lineColor = pointCompleteStyle.borderColor;
|
||
|
|
// lineDefaultStyle.lineStyle = pointCompleteStyle.borderStyle;
|
||
|
|
// break;
|
||
|
|
// default:
|
||
|
|
// pointInflectionStyle.borderColor = pointDefaultStyle.borderColor;
|
||
|
|
// lineDefaultStyle.lineColor = pointDefaultStyle.borderColor;
|
||
|
|
// }
|
||
|
|
// points[i+1]["pointStyle"] = pointInflectionStyle;
|
||
|
|
|
||
|
|
// drawLine(points[i], points[i+1], lineDefaultStyle, configOptions, pointsLinkedList);
|
||
|
|
// } else {
|
||
|
|
switch(points[i+1].status) {
|
||
|
|
// case '1':
|
||
|
|
// points[i+1]["pointStyle"] = pointCompleteStyle;
|
||
|
|
// drawLine(points[i], points[i+1], lineCompleteStyle, configOptions, pointsLinkedList);
|
||
|
|
// break;
|
||
|
|
// case '2':
|
||
|
|
// points[i+1]["pointStyle"] = pointAbnormalStyle;
|
||
|
|
// drawLine(points[i], points[i+1], lineAbnormalStyle, configOptions, pointsLinkedList);
|
||
|
|
// break;
|
||
|
|
case '3':
|
||
|
|
// points[i+1]["pointStyle"] = pointAlarmStyle;
|
||
|
|
// drawLine(points[i], points[i+1], lineAlarmStyle, configOptions, pointsLinkedList);
|
||
|
|
if(points[i+2].status !== '3') {
|
||
|
|
points[i+1]['isCurrent'] = true;
|
||
|
|
}
|
||
|
|
points[i+1]["pointStyle"] = pointCompleteStyle;
|
||
|
|
drawLine(points[i], points[i+1], lineCompleteStyle, configOptions, pointsLinkedList);
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
drawLine(points[i], points[i+1], lineDefaultStyle, configOptions, pointsLinkedList);
|
||
|
|
}
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function setContainer(configOptions) {
|
||
|
|
var container = document.getElementById(configOptions.container);
|
||
|
|
container.style.width = (configOptions.containerWidth + '').indexOf('%') > -1 ? configOptions.containerWidth : configOptions.containerWidth + "px";
|
||
|
|
container.style.height = (configOptions.containerHeight + '').indexOf('%') > -1 ? configOptions.containerHeight : configOptions.containerHeight + 'px';
|
||
|
|
container.style.backgroundColor = configOptions.containerBgColor;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 画点函数
|
||
|
|
function drawPoint(p, configOptions, pl) {
|
||
|
|
var point = document.createElement("div");
|
||
|
|
var point1 = document.createElement("div");
|
||
|
|
var pointInfo = document.createElement("div");
|
||
|
|
var pointInfoCenter = document.createElement("div");
|
||
|
|
pointInfoCenter.style.cssText = 'width:' + 1.2 * p.pointStyle.radius + 'px;height:' + 1.2 * p.pointStyle.radius + 'px;border-radius:50%;background:#fff;position:absolute;left:4px;top:5px;display:block;z-index:3;transform: none;';
|
||
|
|
point.setAttribute("class", "patrol-point");
|
||
|
|
point.setAttribute("id", (p.routeId.indexOf("patrol-point-") > -1 ? "" : "patrol-point-") + p.routeId.replace("patrol-point-", ""));
|
||
|
|
pointInfo.setAttribute("id", "patrol-point-info-" + p.routeId);
|
||
|
|
var containerWidth = container.clientWidth || container.offsetWidth;
|
||
|
|
var containerHeight = container.clientHeight || container.offsetHeight;
|
||
|
|
//point.style.cssText += ";width:" + 2 * p.pointStyle.radius + "px;height: " + 2 * p.pointStyle.radius + "px;position:absolute;left:" + p.posX
|
||
|
|
//+ "px;top:" + p.posY + "px;line-height: " + 2 * p.pointStyle.radius + "px;border: " + p.pointStyle.borderWidth + "px " + p.pointStyle.borderStyle + " " + p.pointStyle.borderColor + ";border-radius: 50%;text-align: center;font-size: " + p.pointStyle.fontSize + "px;font-weight:800;vertical-align: middle;color:" + p.pointStyle.fontColor + ";text-shadow:" + p.pointStyle.shadow + ";box-shadow:" + p.pointStyle.shadow + ";z-index:800;background-color:#1c1d1f;transform: rotateX(0deg);";
|
||
|
|
|
||
|
|
point.style.cssText += ";width:" + 2 * p.pointStyle.radius + "px;height: " + 2 * p.pointStyle.radius + "px;position:absolute;left:" + p.posX
|
||
|
|
+ "px;top:" + p.posY + "px;line-height: " + 2 * p.pointStyle.radius + "px;border: " + p.pointStyle.borderWidth + "px " + p.pointStyle.borderStyle + " " + (p.isCurrent ? '#2e2e2e' : p.pointStyle.borderColor) + ";background-color:" + (p.isCurrent ? '#2e2e2e' : p.pointStyle.borderColor) + ";border-radius: 50%;text-align: center;font-size: " + p.pointStyle.fontSize + "px;font-weight:800;vertical-align: middle;color:" + p.pointStyle.fontColor + ";z-index:800;transform: rotateX(0deg);";
|
||
|
|
if(p.isCurrent){
|
||
|
|
p.pointStyle.borderColor = '#f33';
|
||
|
|
}
|
||
|
|
point1.style.cssText += ";width:" + 2 * p.pointStyle.radius + "px;height: " + 2 * p.pointStyle.radius + "px;position:absolute;left:" + p.posX
|
||
|
|
+ "px;top:" + p.posY + "px;line-height: " + 2 * p.pointStyle.radius + "px;border: " + p.pointStyle.borderWidth + "px " + p.pointStyle.borderStyle + " " + p.pointStyle.borderColor + ";border-radius: 50%;text-align: center;font-size: " + p.pointStyle.fontSize + "px;font-weight:800;vertical-align: middle;color:" + p.pointStyle.fontColor + ";z-index:801;background-color:transparent;transform: rotateX(60deg);";
|
||
|
|
if(p.type === '0') {
|
||
|
|
//point.style.cssText += "background-size: 4px 4px;background-image:-webkit-linear-gradient( 0deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% ), -webkit-linear-gradient( 90deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% );";
|
||
|
|
//point1.style.cssText += "background-size: 4px 4px;background-image:-webkit-linear-gradient( 0deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% ), -webkit-linear-gradient( 90deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% );transform:rotateX(45deg)";
|
||
|
|
point.innerHTML = '';
|
||
|
|
} else {
|
||
|
|
point.style.cssText += "width:" + p.pointStyle.radius + "px;height:" + p.pointStyle.radius + "px;position:absolute;left:" + (p.posX + 6)
|
||
|
|
+ "px;top:" + (p.posY + 6) + "px;display:block;";
|
||
|
|
// point1.style.cssText += "width:10px;height:10px;position:absolute;left:" + (p.posX + 10)
|
||
|
|
// + "px;top:" + p.posY + "px;display:block;";
|
||
|
|
// point.innerHTML = p.name ? p.name[0] : '巡';
|
||
|
|
point.innerHTML = '';
|
||
|
|
}
|
||
|
|
var mark = {
|
||
|
|
width: 20,
|
||
|
|
height: 20,
|
||
|
|
arrowWidth: 10,
|
||
|
|
arrowHeight: 25,
|
||
|
|
fontSize: 16
|
||
|
|
}
|
||
|
|
if(p.patrolPoint) {
|
||
|
|
if(p.isCurrent){
|
||
|
|
p.pointStyle.borderColor = '#f33';
|
||
|
|
pointInfo.style.cssText = ";display:none;position:absolute;top:-" + (mark.height - 3 * p.pointStyle.radius / 4 + mark.arrowHeight - 10) + "px;left:-" + (mark.width / 2 - 3 * p.pointStyle.radius / 4) + "px;width:" + mark.width + "px;height:" + mark.height + "px;background-color:" + p.pointStyle.borderColor + ";border-top-left-radius: 50%;border-top-right-radius: 50%;border-bottom-left-radius: 40%;border-bottom-right-radius: 40%;box-shadow:" + p.pointStyle.shadow + ";color:rgb(28,29,31);font-size:" + mark.fontSize + "px;font-family: '微软雅黑';z-index:2;transform: none;";
|
||
|
|
document.styleSheets[0].insertRule('#patrol-point-info-' + p.routeId + ':before{position:absolute;top:' + (mark.height - 3 * p.pointStyle.radius / 4) + 'px;left:' + (mark.width/ 2 - p.pointStyle.radius) + 'px;border: ' + mark.arrowWidth + 'px solid transparent;border-top:' + mark.arrowHeight + 'px solid ' + p.pointStyle.borderColor + ';content:"";width:0;height:0;z-index:1;transform: none;}', 0);
|
||
|
|
pointInfo.innerHTML = '<div id="patrol-info-'+ p.routeId +'" style="display:block;width:auto;height:auto;padding:3px;border-radius:3px;position: absolute;left: -80px;top: -75px;background-color:' + p.pointStyle.borderColor + ';color:' + '#fff' + ';font-size:14px;text-align:left;user-select:none;transform: none;"><span>巡检人:' + (p.worker==null?"":p.worker.caption) + '</span><br/><span style="white-space: nowrap;">巡检时间:' + (p.finishdt) + '</span></div>';
|
||
|
|
}
|
||
|
|
if(p.status !=='3' || p.isCurrent) {
|
||
|
|
p.pointStyle.borderColor = '#f33';
|
||
|
|
}
|
||
|
|
document.styleSheets[0].insertRule('#patrol-point-info-' + p.routeId + ':after{position:absolute;top:-25px;right:-60px;content:"'+ p.patrolPoint.name +'";color:' + p.pointStyle.borderColor + ';width: 120px;height:20px;white-space: nowrap;font-size:14px;transform: none;}', 0);
|
||
|
|
if(p.isCurrent){
|
||
|
|
pointInfo.appendChild(pointInfoCenter);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(p.infos === undefined) {
|
||
|
|
p['infos'] = {
|
||
|
|
state: 1
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(p.infos.state >= 0) {
|
||
|
|
point.appendChild(pointInfo);
|
||
|
|
}
|
||
|
|
if (configOptions.draggable) {
|
||
|
|
new Drag(point, p, pl);
|
||
|
|
}
|
||
|
|
container.appendChild(point);
|
||
|
|
if(p.type === '0') {
|
||
|
|
container.appendChild(point1);
|
||
|
|
}
|
||
|
|
// point.ondrop = function(event){
|
||
|
|
// drop(event, configOptions, pl);
|
||
|
|
// };
|
||
|
|
// point.ondragover = function(event){
|
||
|
|
// allowDrop(event);
|
||
|
|
// };
|
||
|
|
if(p.type === '0') {
|
||
|
|
if(p.isCurrent) {
|
||
|
|
pointInfo.style.display = 'block';
|
||
|
|
point.addEventListener("mouseover",function() {
|
||
|
|
document.getElementById("patrol-info-"+ p.routeId).style.display = 'block';
|
||
|
|
// point.style.backgroundSize = "";
|
||
|
|
// point.style.backgroundImage = "";
|
||
|
|
// point.style.borderColor = '#0f0';
|
||
|
|
});
|
||
|
|
point.addEventListener("mouseout",function() {
|
||
|
|
document.getElementById("patrol-info-"+ p.routeId).style.display = 'block';
|
||
|
|
});
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if(p.isCurrent){
|
||
|
|
pointInfo.style.display = 'block';
|
||
|
|
} else {
|
||
|
|
pointInfo.style.display = 'none';
|
||
|
|
}
|
||
|
|
if(p.status !== '3') {
|
||
|
|
console.log(point);
|
||
|
|
point.style.cssText += 'animation: pointInflection 1s infinite;';
|
||
|
|
//point.classList.add('flash');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$("#patrol-point-container").hide();
|
||
|
|
// point.addEventListener("contextmenu", function(e) {
|
||
|
|
// if(e.button === 2) {
|
||
|
|
// deleteRoutePoint(p,function(data) {
|
||
|
|
// if(JSON.parse(data).res === '1') {
|
||
|
|
// var floorId = configOptions.floorId;
|
||
|
|
// var patrolRecordId = configOptions.patrolRecordId;
|
||
|
|
// // var patrolPlanId = configOptions.patrolPlanId;
|
||
|
|
// if(p.type === '0') {
|
||
|
|
// var newP = replaceJsonWhiteSpace(p);
|
||
|
|
// newP['id'] = newP['patrolPointId'];
|
||
|
|
// var patrolPointStr = JSON.stringify(newP);
|
||
|
|
// $("#patro-list-" + floorId).append('<li class="patro-point" draggable="true" id="patrol-point-' + newP['patrolPointId'] + '" ondragstart="drag(event)" data-obj=' + patrolPointStr + ' style="font-size:14px;list-style:none;padding: 10px;height:20px;line-height:20px;cursor: move;">' + (newP["name"] ? newP["name"] : newP["patrolPoint"].name) + '</li>');
|
||
|
|
// }
|
||
|
|
// getRecordRoutePoints(floorId,patrolRecordId,configOptions);
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
|
||
|
|
}
|
||
|
|
/****************拖拽功能模块(开始)****************/
|
||
|
|
function Drag(element,elementData, pl){
|
||
|
|
this.elem = element;
|
||
|
|
this.elementData = elementData;
|
||
|
|
this.pl = pl;
|
||
|
|
var self = this;
|
||
|
|
this.elem.onmousedown = function (e){
|
||
|
|
var e = e || window.event;
|
||
|
|
e.preventDefault();
|
||
|
|
if(e.button === 0) {
|
||
|
|
self.posX = e.clientX - self.elem.offsetLeft;
|
||
|
|
self.posY = e.clientY - self.elem.offsetTop;
|
||
|
|
self.start();
|
||
|
|
document.onmouseup = function (){
|
||
|
|
self.stop();
|
||
|
|
};
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
Drag.prototype.start = function (){
|
||
|
|
var self = this;
|
||
|
|
document.onmousemove = function (e){
|
||
|
|
var x = e.clientX - self.posX;
|
||
|
|
var y = e.clientY - self.posY;
|
||
|
|
self.move(x, y);
|
||
|
|
};
|
||
|
|
};
|
||
|
|
Drag.prototype.move = function (x , y){
|
||
|
|
var self = this;
|
||
|
|
self.elem.style.left = x + "px";
|
||
|
|
self.elem.style.top = y + "px";
|
||
|
|
};
|
||
|
|
Drag.prototype.stop = function (e){
|
||
|
|
var self = this;
|
||
|
|
var configOptions = JSON.parse(localStorage.getItem('configOptions'));
|
||
|
|
var points = self.pl.getItems();
|
||
|
|
if(this.elementData && configOptions) {
|
||
|
|
points.forEach(function(item) {
|
||
|
|
if(item.id === self.elementData.id) {
|
||
|
|
item['posX'] = self.elem.offsetLeft;
|
||
|
|
item['posY'] = self.elem.offsetTop;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
points.forEach(function(item) {
|
||
|
|
if (item.id === self.elementData.id) {
|
||
|
|
updateRoutePoint({
|
||
|
|
id: item.routeId,
|
||
|
|
posx: item.posX,
|
||
|
|
posy: item.posY,
|
||
|
|
containerWidth: configOptions.containerWidth,
|
||
|
|
containerHeight: configOptions.containerHeight
|
||
|
|
}, function(data) {
|
||
|
|
var floorId = configOptions.floorId;
|
||
|
|
var patrolRecordId = configOptions.patrolRecordId;
|
||
|
|
// var patrolPlanId = configOptions.patrolPlanId;
|
||
|
|
// getRoutePoints(floorId,patrolPlanId,configOptions);
|
||
|
|
getRecordRoutePoints(floorId,patrolRecordId,configOptions);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
document.onmousemove = null;
|
||
|
|
document.onmouseup = null;
|
||
|
|
}
|
||
|
|
/****************拖拽功能模块(结束)****************/
|
||
|
|
|
||
|
|
// 画线函数
|
||
|
|
function drawLine(startPoint, endPoint, lineStyle,configOptions, pl) {
|
||
|
|
var line = document.createElement("div");
|
||
|
|
line.setAttribute("class","patrol-line");
|
||
|
|
line.setAttribute("id","patrol-line-" + endPoint.routeId);
|
||
|
|
var lineWidth = Math.sqrt(Math.pow((endPoint.posX + endPoint.pointStyle.radius + endPoint.pointStyle.borderWidth - startPoint.posX - startPoint.pointStyle.radius - startPoint.pointStyle.borderWidth), 2) + Math.pow((endPoint.posY + endPoint.pointStyle.radius + endPoint.pointStyle.borderWidth - startPoint.posY - startPoint.pointStyle.radius - startPoint.pointStyle.borderWidth), 2));
|
||
|
|
line.style.cssText += ";width: " + lineWidth + "px;position:absolute;left:" + (startPoint.posX + startPoint.pointStyle.radius + startPoint.pointStyle.borderWidth) + "px;top:" + (startPoint.posY + startPoint.pointStyle.radius + startPoint.pointStyle.borderWidth - lineStyle.lineWidth / 2) + "px;border-top: " + lineStyle.lineWidth + "px " + lineStyle.lineStyle + " " + lineStyle.lineColor + ";transform-origin: 0;transform:rotate(" + getAangle(startPoint, endPoint) + "deg);box-shadow:" + lineStyle.shadow + ";z-index:799;";
|
||
|
|
|
||
|
|
if(startPoint.status === '3' && endPoint.status !== '3' || startPoint.status !== '3' && endPoint.status !== '3'){
|
||
|
|
var worker = document.createElement('div');
|
||
|
|
worker.classList.add('fa');
|
||
|
|
worker.classList.add('fa-street-view');
|
||
|
|
worker.style.cssText = 'width:30px;height:30px;background:rgba(0,0,0,0);font-size:25px;text-align:center;color:' + ('red' || lineStyle.lineColor) + ';position:absolute;left:' + (lineWidth / 2) + 'px;top:-31px;animation:worker 1s infinite;';
|
||
|
|
line.style.cssText += 'animation: workingLine 1s infinite;';
|
||
|
|
if(startPoint.isCurrent) {
|
||
|
|
line.appendChild(worker);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
drawPoint(endPoint, configOptions, pl);
|
||
|
|
container.appendChild(line);
|
||
|
|
document.oncontextmenu = function(e) {
|
||
|
|
e.preventDefault();
|
||
|
|
};
|
||
|
|
// line.onmouseover = function(e) {
|
||
|
|
// line.style.borderColor = "#0f0";
|
||
|
|
// e.preventDefault();
|
||
|
|
// }
|
||
|
|
// line.onmouseout = function(e) {
|
||
|
|
// line.style.borderColor = lineStyle.lineColor;
|
||
|
|
// e.preventDefault();
|
||
|
|
// }
|
||
|
|
// line.oncontextmenu = function(e) {
|
||
|
|
// if(e.button === 2){
|
||
|
|
// var newInflectionPoint = {
|
||
|
|
// id: guid(),
|
||
|
|
// type: '1',
|
||
|
|
// patrolPlanId: configOptions.patrolPlanId,
|
||
|
|
// floorId: configOptions.floorId,
|
||
|
|
// containerWidth: configOptions.containerWidth,
|
||
|
|
// containerHeight: configOptions.containerHeight,
|
||
|
|
// infos: {
|
||
|
|
// text: "拐点",
|
||
|
|
// state: 0,
|
||
|
|
// message: "拐"
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// newInflectionPoint['patrolPointId'] = newInflectionPoint.id;
|
||
|
|
// newInflectionPoint['routeId'] = guid();
|
||
|
|
// newInflectionPoint['pointStyle'] = deepClone(configOptions.pointsStyle.pointInflectionStyle);
|
||
|
|
// newInflectionPoint['posX'] = e.clientX - $("#container").offset().left - newInflectionPoint.pointStyle.radius - newInflectionPoint.pointStyle.borderWidth;
|
||
|
|
// newInflectionPoint['posY'] = e.clientY - $("#container").offset().top - newInflectionPoint.pointStyle.radius - newInflectionPoint.pointStyle.borderWidth;
|
||
|
|
// if(e.target.id.indexOf("patrol-line-") > -1 && e.target.id !== "container" && !e.target.id.indexOf("patrol-point-") > -1) {
|
||
|
|
// pl.getItems().forEach(function(item, index){
|
||
|
|
// if(e.target.id === "patrol-line-" + item.routeId) {
|
||
|
|
// pl.add(item.index, newInflectionPoint);
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
// }
|
||
|
|
// pl.getItems().forEach(function(item, index) {
|
||
|
|
// pl.set(index, item);
|
||
|
|
// });
|
||
|
|
// pl.getItems().forEach(function(item, index) {
|
||
|
|
// if(newInflectionPoint.routeId === item.routeId){
|
||
|
|
// var newPoint = item;
|
||
|
|
// saveRoutePoint({
|
||
|
|
// id: newPoint.routeId,
|
||
|
|
// patrolPlanId: newPoint.patrolPlanId,
|
||
|
|
// previousId: newPoint.prevId,
|
||
|
|
// nextId: newPoint.nextId, //
|
||
|
|
// type: newPoint.type,
|
||
|
|
// patrolPointId: newPoint.id,
|
||
|
|
// posx: newPoint.posX,
|
||
|
|
// posy: newPoint.posY,
|
||
|
|
// containerWidth: configOptions.containerWidth,
|
||
|
|
// containerHeight: configOptions.containerHeight,
|
||
|
|
// floorId: configOptions.floorId
|
||
|
|
// },function(data) {
|
||
|
|
// if(JSON.parse(data).res === '1') {
|
||
|
|
// configOptions.points = deepClone(pl.getItems());
|
||
|
|
// drawAllPath(configOptions);
|
||
|
|
// } else {
|
||
|
|
// pl.remove(item.index);
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
// }
|
||
|
|
// e.preventDefault();
|
||
|
|
// };
|
||
|
|
if(endPoint.infos.state > -1) {
|
||
|
|
if(endPoint.type === '0') {
|
||
|
|
if(startPoint.status === '3' && endPoint.status !== '3' || startPoint.status !== '3' && endPoint.status !== '3'){
|
||
|
|
document.styleSheets[0].insertRule('#patrol-line-' + endPoint.routeId + ':before {position: absolute;bottom: -' + lineStyle.lineWidth + 'px;right: -' + lineStyle.lineWidth + 'px;margin-right: ' + (endPoint.pointStyle.radius - endPoint.pointStyle.borderWidth) + 'px;display: block;width: 0;height: 0;content: "";border: ' + 1.5 * lineStyle.lineWidth + 'px solid transparent;border-left: ' + 4 * lineStyle.lineWidth + 'px solid ' + lineStyle.lineColor + ';animation: workingLineArrow 1s infinite;}', 0);
|
||
|
|
} else {
|
||
|
|
document.styleSheets[0].insertRule('#patrol-line-' + endPoint.routeId + ':before {position: absolute;bottom: -' + lineStyle.lineWidth + 'px;right: -' + lineStyle.lineWidth + 'px;margin-right: ' + (endPoint.pointStyle.radius - endPoint.pointStyle.borderWidth) + 'px;display: block;width: 0;height: 0;content: "";border: ' + 1.5 * lineStyle.lineWidth + 'px solid transparent;border-left: ' + 4 * lineStyle.lineWidth + 'px solid ' + lineStyle.lineColor + ';}', 0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function getAangle(startP, endP) {
|
||
|
|
var radiusDiff = endP.pointStyle.radius + endP.pointStyle.borderWidth - startP.pointStyle.radius - startP.pointStyle.borderWidth;
|
||
|
|
var x = endP.posX - startP.posX + radiusDiff;
|
||
|
|
var y = endP.posY - startP.posY + radiusDiff;
|
||
|
|
if (x < 0 && y < 0) {// 第一象限
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI) - 180;
|
||
|
|
}
|
||
|
|
// ?
|
||
|
|
if (x < 0 && y > 0) {// 第三象限
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI) + 180;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (x > 0 && y < 0) {// 第一象限
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI);
|
||
|
|
}
|
||
|
|
// ?
|
||
|
|
if (x > 0 && y > 0) {// 第三象限
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (x < 0 && y === 0) {// 鼠标在x轴负方向
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI) + 180;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (x > 0 && y === 0) {
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI);
|
||
|
|
}
|
||
|
|
if (x === 0 && y < 0) {
|
||
|
|
return 180 - 360 * Math.atan(y / x) / (2 * Math.PI);
|
||
|
|
}
|
||
|
|
if (x === 0 && y > 0) {
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI);
|
||
|
|
}
|
||
|
|
return 360 * Math.atan(y / x) / (2 * Math.PI);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function deepClone(obj) {
|
||
|
|
var str, newobj = obj.constructor === Array ? [] : {};
|
||
|
|
if (typeof obj !== 'object') {
|
||
|
|
return;
|
||
|
|
} else if (JSON) {
|
||
|
|
str = JSON.stringify(obj), // 系列化对象
|
||
|
|
newobj = JSON.parse(str); // 还原
|
||
|
|
} else {
|
||
|
|
for (var i in obj) {
|
||
|
|
newobj[i] = typeof obj[i] === 'object' ? this.deepClone(obj[i]) : obj[i];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return newobj;
|
||
|
|
}
|
||
|
|
|
||
|
|
function getStyle(element, attr) {
|
||
|
|
if(element.currentStyle) {
|
||
|
|
return element.currentStyle[attr];
|
||
|
|
} else {
|
||
|
|
return getComputedStyle(element, false)[attr];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function allowDrop(ev) {
|
||
|
|
ev.preventDefault();
|
||
|
|
}
|
||
|
|
|
||
|
|
function drag(ev) {
|
||
|
|
var obj = $('#' + ev.target.id).data('obj');
|
||
|
|
ev.dataTransfer.setData("obj",JSON.stringify(obj));
|
||
|
|
ev.dataTransfer.setData("ID",ev.target.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
function drop(ev,configOptions, pl) {
|
||
|
|
ev.stopPropagation();
|
||
|
|
var data = ev.dataTransfer.getData("ID");
|
||
|
|
var pointStr = ev.dataTransfer.getData("obj");
|
||
|
|
var pointObj = JSON.parse(pointStr.replace(" ", "kongbai"));
|
||
|
|
var infos = {
|
||
|
|
text: pointObj['name'] ? pointObj['name']: "巡检点",
|
||
|
|
state: 0,
|
||
|
|
message: pointObj['name'] ? pointObj['name']: "巡检点"
|
||
|
|
};
|
||
|
|
pointObj['routeId'] = guid();
|
||
|
|
pointObj['pointStyle'] = deepClone(configOptions.pointsStyle.pointDefaultStyle);
|
||
|
|
pointObj['patrolPlanId'] = configOptions.patrolPlanId;
|
||
|
|
pointObj['patrolPointId'] = pointObj.id;
|
||
|
|
pointObj['type'] = '0';
|
||
|
|
pointObj['infos'] = infos;
|
||
|
|
// 拖拽到点上
|
||
|
|
if(ev.target.id === 'container' && !ev.target.id.indexOf("patrol-line-") > -1 && !ev.target.id.indexOf("patrol-point-") > -1) {
|
||
|
|
pointObj['prevId'] = null;
|
||
|
|
pointObj['nextId'] = null;
|
||
|
|
pointObj['posX'] = ev.offsetX - pointObj['pointStyle'].radius - pointObj['pointStyle'].borderWidth;
|
||
|
|
pointObj['posY'] = ev.offsetY - pointObj['pointStyle'].radius - pointObj['pointStyle'].borderWidth;
|
||
|
|
} else if(ev.target.id.indexOf('patrol-line-') > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-point-") > -1) {
|
||
|
|
pointObj['prevId'] = null;
|
||
|
|
pointObj['nextId'] = null;
|
||
|
|
pointObj['posX'] = ev.clientX - $("#container").offset().left - pointObj.pointStyle.radius - pointObj.pointStyle.borderWidth;
|
||
|
|
pointObj['posY'] = ev.clientY - $("#container").offset().top - pointObj.pointStyle.radius - pointObj.pointStyle.borderWidth;
|
||
|
|
} else if(ev.target.id.indexOf('patrol-point-') > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-line-") > -1) {
|
||
|
|
pointObj['prevId'] = null;
|
||
|
|
pointObj['nextId'] = null;
|
||
|
|
pointObj['posX'] = document.getElementById(ev.target.id).offsetLeft + pointObj['pointStyle'].radius + pointObj['pointStyle'].borderWidth;
|
||
|
|
pointObj['posY'] = document.getElementById(ev.target.id).offsetTop + pointObj['pointStyle'].radius + pointObj['pointStyle'].borderWidth;
|
||
|
|
} else {
|
||
|
|
|
||
|
|
}
|
||
|
|
if(pl.getItems().length === 0) {
|
||
|
|
pl.addFirst(pointObj);
|
||
|
|
} else {
|
||
|
|
if(ev.target.id === "container" && !ev.target.id.indexOf("patrol-line-") > -1 && !ev.target.id.indexOf("patrol-point-") > -1) {
|
||
|
|
pl.addLast(pointObj);
|
||
|
|
} else if(ev.target.id.indexOf("patrol-line-") > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-point-") > -1) {
|
||
|
|
pl.getItems().forEach(function(item, index) {
|
||
|
|
if(ev.target.id === "patrol-line-" + item.routeId) {
|
||
|
|
pl.add(item.index, pointObj);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
} else if(ev.target.id.indexOf("patrol-point-") > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-line-") > -1) {
|
||
|
|
pl.getItems().forEach(function(item, index) {
|
||
|
|
if(ev.target.id === "patrol-point-" + item.routeId) {
|
||
|
|
pl.add(item.index + 1, pointObj);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
pl.getItems().forEach(function(item, index) {
|
||
|
|
pl.set(index, item);
|
||
|
|
});
|
||
|
|
pl.getItems().forEach(function(item, index) {
|
||
|
|
if(pointObj.routeId === item.routeId){
|
||
|
|
var newPoint = item;
|
||
|
|
saveRoutePoint({
|
||
|
|
id: newPoint.routeId,
|
||
|
|
patrolPlanId: newPoint.patrolPlanId,
|
||
|
|
previousId: newPoint.prevId,
|
||
|
|
nextId: newPoint.nextId,
|
||
|
|
type: newPoint.type,
|
||
|
|
patrolPointId: newPoint.id,
|
||
|
|
posx: newPoint.posX,
|
||
|
|
posy: newPoint.posY,
|
||
|
|
containerWidth: configOptions.containerWidth,
|
||
|
|
containerHeight: configOptions.containerHeight,
|
||
|
|
structureCardPictureId: configOptions.floorId
|
||
|
|
},function(data) {
|
||
|
|
if(JSON.parse(data).res === '1') {
|
||
|
|
configOptions.points = deepClone(pl.getItems());
|
||
|
|
drawAllPath(configOptions);
|
||
|
|
$("#patrol-point-" + pointObj.id).remove();
|
||
|
|
} else {
|
||
|
|
pl.remove(item.index);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
ev.preventDefault();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取楼层信息
|
||
|
|
function getAllFloorList(unitId,callback) {
|
||
|
|
$.post(ext.contextPath + '/timeEfficiency/patrolArea/getAllFloorList.do', {unitId:unitId} , function(data) {
|
||
|
|
callback(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取巡检点数据
|
||
|
|
function getPatrolPointsList(configOptions, patrolPointInContainer) {
|
||
|
|
$("#patro-list-" + configOptions.floorId).html("");
|
||
|
|
var configOptions = JSON.parse(localStorage.getItem("configOptions"));
|
||
|
|
var patrolPointInContainer = deepClone(configOptions.points.filter(function(item) {return item['type'] === '0';}));
|
||
|
|
$.post(ext.contextPath + '/timeEfficiency/patrolArea/getPatrolPoints.do', {patrolAreaId:configOptions.patrolAreaId} , function(data) {
|
||
|
|
var patrolPointItem = "";
|
||
|
|
JSON.parse(data).forEach(function(item) {
|
||
|
|
var itemStr = JSON.stringify(replaceJsonWhiteSpace(item));
|
||
|
|
patrolPointItem += '<li class="patro-point" draggable="true" id="patrol-point-' + item['id'] + '" ondragstart="drag(event)" data-obj=' + itemStr + ' style="font-size:14px;list-style:none;padding: 10px;height:20px;line-height:20px;cursor: move;">' + item['name'] + '</li>';
|
||
|
|
});
|
||
|
|
$("#patro-list-" + configOptions.floorId).html(patrolPointItem);
|
||
|
|
patrolPointInContainer.forEach(function(point) {
|
||
|
|
$("#patrol-point-" + point.patrolPointId).remove();
|
||
|
|
});
|
||
|
|
$("#patrol-point-container").show();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPatrolPointsList1(configOptions) {
|
||
|
|
$.post(ext.contextPath + '/timeEfficiency/patrolArea/getPatrolPoints.do', {patrolAreaId:configOptions.patrolAreaId} , function(data) {
|
||
|
|
$("#patro-list-" + configOptions.floorId).html("");
|
||
|
|
JSON.parse(data).forEach(function(item) {
|
||
|
|
var itemStr = JSON.stringify(replaceJsonWhiteSpace(item));
|
||
|
|
var patrolPointItem = '<li class="patro-point" draggable="true" id="patrol-point-' + item['id'] + '" ondragstart="drag(event)" data-obj=' + itemStr + ' style="font-size:14px;list-style:none;padding: 10px;height:20px;line-height:20px;cursor: move;">' + item['name'] + '</li>';
|
||
|
|
$("#patro-list-" + configOptions.floorId).append(patrolPointItem);
|
||
|
|
});
|
||
|
|
$("#patrol-point-container").show();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 首次获取巡检路径点信息(巡检记录)
|
||
|
|
function getRoutePointsFirst(floorId,patrolRecordId,callback) {
|
||
|
|
$.post(ext.contextPath + '/timeEfficiency/patrolRecord/getRoutePoints.do?patrolRecordId=' + patrolRecordId + '&floorId=' + floorId, function(data) {
|
||
|
|
callback(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取巡检路径点信息(巡检记录)
|
||
|
|
function getRecordRoutePoints(floorId,patrolRecordId,configOptions) {
|
||
|
|
$.post(ext.contextPath + '/timeEfficiency/patrolRecord/getRoutePoints.do?patrolRecordId=' + patrolRecordId + '&floorId=' + floorId, function(data) {
|
||
|
|
var copyPoints = JSON.parse(data);
|
||
|
|
copyPoints.forEach(function(item,index) {
|
||
|
|
var insdt1 = item['insdt'].replace(' ', 'kongbai');
|
||
|
|
var infos = {
|
||
|
|
text: "新",
|
||
|
|
state: 0,
|
||
|
|
message: "新"
|
||
|
|
};
|
||
|
|
item['routeId'] = item['id'];
|
||
|
|
item['insdt'] = insdt1;
|
||
|
|
item['infos'] = infos;
|
||
|
|
item['posX'] = item['posx'];
|
||
|
|
item['posY'] = item['posy'];
|
||
|
|
});
|
||
|
|
configOptions.points = copyPoints;
|
||
|
|
drawAllPath(configOptions);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取巡检点信息
|
||
|
|
function getPatrolRecord(patrolRecordId){
|
||
|
|
$.post(ext.contextPath + '/timeEfficiency/patrolRecord/getPatrolPoint4APP.do',{id:patrolRecordId},function(data){
|
||
|
|
console.log(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function drawAllPath(configOptions) {
|
||
|
|
drawPath(configOptions);
|
||
|
|
localStorage.setItem("configOptions", JSON.stringify(configOptions));
|
||
|
|
$("#patrol-point-container").show();
|
||
|
|
}
|
||
|
|
|
||
|
|
function saveRoutePoint(param, callback) {
|
||
|
|
$.post(ext.contextPath + '/structure/structureCardPicture/saveRoutePoint.do', param, function(data) {
|
||
|
|
callback(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function updateRoutePoint(param, callback) {
|
||
|
|
$.post(ext.contextPath + '/structure/structureCardPicture/updateRoutePoint.do', param, function(data) {
|
||
|
|
callback(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function deleteRoutePoint(point,callback) {
|
||
|
|
$.post(ext.contextPath + '/structure/structureCardPicture/deleteRoutePoint.do?id=' + point.routeId + '&previousId=' + point.prevId + '&nextId=' + point.nextId, function(data) {
|
||
|
|
callback(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function replaceJsonWhiteSpace(jsonObj) {
|
||
|
|
for(var key in jsonObj) {
|
||
|
|
//如果对象类型为object类型且数组长度大于0 或者 是对象 ,继续递归解析
|
||
|
|
var element = jsonObj[key];
|
||
|
|
if(typeof element === 'string') {
|
||
|
|
jsonObj[key] = element.replace(" ", "kongbai");
|
||
|
|
}
|
||
|
|
if(element && element.length > 0 && typeof(element) == "object" || typeof(element) == "object") {
|
||
|
|
replaceJsonWhiteSpace(element);
|
||
|
|
} else { //不是对象或数组、直接输出
|
||
|
|
// console.log("----eles --> " + key + ":" + element + " ");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return jsonObj;
|
||
|
|
}
|
||
|
|
//生成唯一路径点ID
|
||
|
|
function S4() {
|
||
|
|
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
||
|
|
}
|
||
|
|
function guid() {
|
||
|
|
return (S4()+S4()+""+S4()+""+S4()+""+S4()+""+S4()+S4()+S4());
|
||
|
|
}
|