import { mainMap } from "../index.js"; import { pushbuttonAlarmList,pushButtonAlarmResiveReq, showPushButtonEventPage} from "../showAlarmListTable.js"; import { alarmHandleCreateData } from "./moveDeviceMarker.js"; import { autoOpenRightSlide } from "../pageEventTool.js"; import { showStationIpcRightVideo } from "../schoolBaseInfo.js"; import {sosDeviceAlarmAccept, sosDeviceAlarmDone} from "../sosVideoAndAudio.js" import { closeSosAlarmVideo, openSosAlarmVideo } from "../popSosVideo.js"; import { getPushButtonInfoWindowDiv } from "./pushButtonMarker.js"; import { schoolPushButtonList } from "../showPushButtonInfo.js"; var eventMarkerHash={}; function delPushButtonEventMarker(eventId){ if(eventId in eventMarkerHash){ //把 Marker 添加到图层 mainMap.removeLayer(eventMarkerHash[eventId]); delete eventMarkerHash[eventId]; //先把当前的marker重置 var resivePushButtonData=pushButtonEventFindDeviceId(eventId) //取消报警器的告警 sosAsrAcceptAndDone(resivePushButtonData,"relieve"); } } //通过eventId查找设备Id function pushButtonEventFindDeviceId(eventId){ var list=pushbuttonAlarmList.filter(item=>{ return item["eventId"]==eventId }) return list[0]; } //通过设备的Id,查询设备信息 function pushButtonEventFindId(deviceId){ var list=schoolPushButtonList.filter(item=>{ return item["pointId"]==deviceId }) return list[0]; } //更新告警信息 function updatePushButtonEvent(item){ pushbuttonAlarmList.unshift(item); drawPushButtonEventMarker(item); showPushButtonEventPage(); } function drawPushButtonEventMarker(item){ addPushButtonEventMarker(item); if(pushbuttonAlarmList.length>0){ var longitude=pushbuttonAlarmList[0]['longitude'] var latitude=pushbuttonAlarmList[0]['latitude'] mainMap.setView([latitude,longitude], 18); } } function addPushButtonEventMarker(obj){ var eventId=obj['eventId']; var longitude=obj["longitude"]; var latitude=obj["latitude"]; var address=obj["address"]; var iconObj=getPushButtonAlarmIcon(obj) let marker=L.marker([latitude,longitude],{ icon: iconObj,//将marker设置为上面引用的图形 title:address, riseOnHover:false, zIndexOffset:1000 }) if(!(eventId in eventMarkerHash)){ eventMarkerHash[eventId]=marker } marker.bindTooltip(address).openTooltip(); marker.on('click',function(e){ showPushButtonInfoWindow(obj); }) //把 Marker 添加到图层 mainMap.addLayer(marker); //启动视频 startSosVideo(obj); } function showPushButtonInfoWindow(obj){ var eventId=obj["eventId"]; if(eventId in eventMarkerHash){ var eventObj=pushButtonEventFindDeviceId(eventId); var deviceObj=pushButtonEventFindId(eventObj["deviceId"]); eventMarkerHash[eventId].unbindPopup(); eventMarkerHash[eventId].bindPopup(`
${getPushButtonInfoWindowDiv(deviceObj)}
`,{maxHeight:260}).openPopup(); var lnglat= eventMarkerHash[eventId].getLatLng() mainMap.setView(lnglat, 18); } } function getPushButtonAlarmIcon(obj){ var deviceId=obj["deviceId"]; var eventId=obj["eventId"]; var div=getSosAlarmVideoAlarm(obj); return L.divIcon({ className: "my-div-icon", html: `

学校:${obj["station"]}

地址:${obj["address"]}

时间:${obj["timestamp"]}

${div}

` }) } //启动视频 function startSosVideo(obj){ var devicetype=obj['devicetype']; if(devicetype=="asr_av"){ //页面初始化的时候,调用视频,会出现问题。 setTimeout(()=>{ sosAsrAlarmVideo(obj,"open") },3000) } } //这里需要判断是否开启报警视频 function sosAsrAlarmVideo(obj,type){ var devicetype=obj["devicetype"]; if(devicetype=="asr_av" ){ if(type=="open"){ openSosAlarmVideo(obj); }else if(type=="close"){ closeSosAlarmVideo(obj); } } } //获取按钮告警视频 function getSosAlarmVideoAlarm(obj){ var devicetype=obj["devicetype"]; var deviceId=obj["deviceId"]; var div=""; if(devicetype=="asr_av"){ div=`
`; } if(devicetype=="asr_a"){ div=`
`; } return div; } window.closePushButtonEvent=function(that){ var eventId=$(that).parent().attr("eventId"); pushButtonAlarmResiveReq(eventId); } window.processedPushButtonEvent=function(that){ var eventId=$(that).parent().attr("eventId") pushButtonHandleData(eventId); } //一键告警的处置 function pushButtonHandleData(eventId){ var obj=pushButtonEventFindDeviceId(eventId) alarmHandleCreateData(obj); //自动打开视频 autoOpenRightSlide(); showStationIpcRightVideo({station:obj["station"]}) //自动接警 sosAsrAcceptAndDone(obj,"handle"); } //这里需要判断,如果是asr_a跟asr_av都需要像设备端消警 function sosAsrAcceptAndDone(obj,type){ var devicetype=obj["devicetype"]; if( devicetype=="asr_a" || devicetype=="asr_av" ){ if(type=="handle"){ sosDeviceAlarmAccept(obj); }else if(type=="relieve"){ sosDeviceAlarmDone(obj); } } } export{ drawPushButtonEventMarker, addPushButtonEventMarker, delPushButtonEventMarker, sosAsrAcceptAndDone, pushButtonHandleData, updatePushButtonEvent, pushButtonEventFindId, showPushButtonInfoWindow }