nvsPtzcontrol.js
7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
(function () {
var nvs = {};
/// 播放类型
nvs.PlayerType = new function () {
this.kLivePlayer = 0; /// 实时预览
this.kRecordPlayer = 1; /// 录像回放
this.kFilePlayer = 2; /// 文件回放
};
/// 录像类型
nvs.RecordType = new function () {
this.kNone = 0;
this.kSystemRecord = 0x01;
this.kFrontRecord = 0x02;
this.kManualRecord = 0x04;
this.kAlarmRecord = 0x08;
};
/// 上下线状态
nvs.StatusType = new function () {
this.kOffline = 0; /// 下线
this.kOnline = 1; /// 上线
};
/// PTZ命令
nvs.PTZCommand = new function () {
this.PTZ_CMD_START = 0;
this.PTZ_CMD_STOP = 1; ///停止
this.PTZ_CMD_RIGHT = 2; ///右
this.PTZ_CMD_LEFT = 4; ///左
this.PTZ_CMD_DOWN = 6; /// 下
this.PTZ_CMD_UP = 8; /// 上
this.PTZ_CMD_RIGHT_UP = 22; //右上
this.PTZ_CMD_LEFT_UP = 24; //左上
this.PTZ_CMD_RIGHT_DOWN = 26; //右下
this.PTZ_CMD_LEFT_DOWN = 28; //左下
this.PTZ_CMD_SMALL = 10; ///光圈变小
this.PTZ_CMD_LARGE = 12; ///光圈变大
this.PTZ_CMD_ZOOM_IN = 14; ///焦距变大
this.PTZ_CMD_ZOOM_OUT = 16; ///焦距变小
this.PTZ_CMD_FOCUS_IN = 18; ///焦点前调
this.PTZ_CMD_FOCUS_OUT = 20; ///焦点后调
this.PTZ_CMD_ASSIST_FUNC_1 = 30; ///雨刷
this.PTZ_CMD_ASSIST_FUNC_2 = 32;
this.PTZ_CMD_ASSIST_FUNC_3 = 34;
this.PTZ_CMD_ASSIST_FUNC_4 = 36;
this.PTZ_RIGHT_APPLY = 40; ///权限申请
this.PTZ_RIGHT_RELEASE = 42; ///权限释放
this.PTZ_PRESET_ADD = 110; ///添加预置位
this.PTZ_PRESET_MODIDY = 112; ///修改预置位
this.PTZ_PRESET_DELETE = 114; ///删除预置位
this.PTZ_PRESET_GOTO = 116; ///转到预置位
this.PTZ_CMD_SCAN = 120; ///自动扫描开
this.PTZ_CMD_LENGTH = 121;
};
/// 预置位标识
nvs.PresetFlag = new function () {
this.kNormal = 0; ///普通预置位
this.kDay = 1; ///白天守望位
this.kNight = 2; ///夜晚守望位
};
window['nvs'] = nvs;
})();
function getParamsId(url){
var obj = {};
// pure user query object.
obj.user_query = {};
// parse the query string.
var query_string = String(url).replace(" ", "").split("?")[1];
if(query_string == undefined){
return "";
}
var queries = query_string.split("&");
$(queries).each(function(){
var query = this.split("=");
obj[query[0]] = query[1];
obj.user_query[query[0]] = query[1];
});
return obj.id;
}
function sendPtzcontrol(userId,id,cmd,para,speed){
var xhr = $.ajax({
url: "/nvsthird/ptzcontrol",
type: "post",
async: true,
dataType: "json",
contentType: "application/json",
data: JSON.stringify({
userId: userId,
chnId: id,
action:cmd,
data:para,
speed:speed
}),
timeout: 3000,
success: function(res) {
console.log('res:'+res);
//layer.msg('云镜控制成功', {icon: 1, time: 1000,skin: 'layer-ext-moon' });
},
error: function(XMLHttpRequest, textStatus, errorThrown){
layer.msg('云镜控制超时:' + errorThrown, {icon: 2, time: 2000,skin: 'layer-ext-moon' });
return false;
},
complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
if(status == 'timeout'){//超时,status还有success,error等值的情况
xhr.abort();
} else if(status == 'error') {
xhr.abort();
layer.msg('云镜控制失败', {icon: 2, time: 2000,skin: 'layer-ext-moon' });
}
},
});
}
function handlePtzcontrol(cmd,stop,para){
if (arguments.length == 1) {
doPtzcontrol(cmd,""+nvs.PTZCommand.PTZ_CMD_START,""+g_speed*8,false);
} else if (arguments.length == 2) {
if(stop == false) {
doPtzcontrol(cmd,""+nvs.PTZCommand.PTZ_CMD_START,""+g_speed*8,stop);
} else {
doPtzcontrol(cmd,""+nvs.PTZCommand.PTZ_CMD_STOP,""+g_speed*8,stop);
}
} else if (arguments.length == 3) {
doPtzcontrol(cmd,para,""+g_speed*8,stop);
}
}
// 云镜控制
$('.ptzsubwd_top').mousedown(function() { //向上
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_UP);
});
$('.ptzsubwd_top').mouseup(function() { //向上停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_UP,true);
});
$('.ptzsubwd_bottom').mousedown(function() { //向下
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_DOWN);
});
$('.ptzsubwd_bottom').mouseup(function() { //向下停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_DOWN,true);
});
$('.ptzsubwd_left').mousedown(function() { //左键
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT);
});
$('.ptzsubwd_left').mouseup(function() { //左键停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT,true);
});
$('.ptzsubwd_right').mousedown(function() { //右键
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT);
});
$('.ptzsubwd_right').mouseup(function() { //右键停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT,true);
});
$('.ptzsubwd_left_top').mousedown(function() { //左上
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_UP);
});
$('.ptzsubwd_left_top').mouseup(function() { //左上停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_UP,true);
});
$('.ptzsubwd_top_right').mousedown(function() { //右上
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_UP);
});
$('.ptzsubwd_top_right').mouseup(function() { //右上停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_UP,true);
});
$('.ptzsubwd_right_bottom').mousedown(function() { //右下
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_DOWN);
});
$('.ptzsubwd_right_bottom').mouseup(function() { //右下停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_DOWN,true);
});
$('.ptzsubwd_bottom_left').mousedown(function() { //左下
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_DOWN);
});
$('.ptzsubwd_bottom_left').mouseup(function() { //左下停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_DOWN,true);
});
$('.cloud_halo_big').mousedown(function() { //光圈放大
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LARGE);
});
$('.cloud_halo_big').mouseup(function() { //光圈放大停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LARGE,true);
});
$('.cloud_halo_small').mousedown(function() { //光圈缩小
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_SMALL);
});
$('.cloud_halo_small').mouseup(function() { //光圈缩小停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_SMALL,true);
});
$('.cloud_big').mousedown(function() { //焦距变大
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_IN);
});
$('.cloud_big').mouseup(function() { //焦距变大停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_IN,true);
});
$('.cloud_small').mousedown(function() { //焦距变小
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_OUT);
});
$('.cloud_small').mouseup(function() { //焦距变小停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_OUT,true);
});
$('.cloud_focus_big').mousedown(function() { //焦点变大
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_OUT);
});
$('.cloud_focus_big').mouseup(function() { //焦点变大停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_OUT,true);
});
$('.cloud_focus_small').mousedown(function() { //焦点变小
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_IN);
});
$('.cloud_focus_small').mouseup(function() { //焦点变小停止
handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_IN,true);
});