Browse Source

多点触控

huangxiaojing 3 years ago
parent
commit
c435a28391
2 changed files with 21 additions and 15 deletions
  1. 0 3
      screenAndroid/WXdraw.js
  2. 21 12
      screenIos/WXdraw.js

+ 0 - 3
screenAndroid/WXdraw.js

@@ -194,7 +194,6 @@ var draw_graph = function (graphType, obj) {
       var ping = resolving == 0 ?
         { "data": { "action": 0, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
         { "data": { "action": 0, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
       wsss.send(JSON.stringify(ping));
     }
     canDraw = true;
@@ -212,7 +211,6 @@ var draw_graph = function (graphType, obj) {
       var ping = resolving == 0 ?
         { "data": { "action": 1, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
         { "data": { "action": 1, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
       wsss.send(JSON.stringify(ping));
       ongoingTouches.forEach(function (item, index) {
         if (item.identifier === touchfor[i].identifier) {
@@ -239,7 +237,6 @@ var draw_graph = function (graphType, obj) {
       var ping = resolving == 0 ?
         { "data": { "action": 2, "count": touchfor.length, "pointerId": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
         { "data": { "action": 2, "count": touchfor.length, "pointerId": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
       wsss.send(JSON.stringify(ping));
     }
   };

+ 21 - 12
screenIos/WXdraw.js

@@ -169,6 +169,7 @@ var draw_graph = function (graphType) {
   $("#dedit").css("z-index", 20);
   // 先画在蒙版上 再复制到画布上
   //鼠标按下获取 开始xy开始画图
+  var ongoingTouches = [];
   var touchstart = function (e) {
     $('.control-right-img').attr({
       "data-id": "2"
@@ -176,17 +177,22 @@ var draw_graph = function (graphType) {
     $(".leftmains").css({
       "right": "-4rem"
     })
-    var touchfor = e.originalEvent.touches; //for 的手指数组
+    var touchfor = e.originalEvent.changedTouches; //for 的手指数组
     //是否横屏
     for (var i = 0; i < touchfor.length; i++) {
       var acrossWidthX = touchfor[i].pageY * (videoHeight / voheight);
       var acrossHeightY = videoWidth - touchfor[i].pageX * (videoWidth / vowidth);
       var verticalWidthX = touchfor[i].pageX * (videoWidth / vowidth);
       var verticalHeightY = touchfor[i].pageY * (videoHeight / voheight);
+      var idx = ongoingTouches.findIndex(function (ele) {
+        return ele.identifier === touchfor[i].identifier
+      })
+      if (idx < 0) {
+        ongoingTouches.push(touchfor[i]);
+      }
       var ping = resolving == 0 ?
-        { "data": { "action": 0, "count": touchfor.length, "id": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
-        { "data": { "action": 0, "count": touchfor.length, "id": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
+        { "data": { "action": 0, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
+        { "data": { "action": 0, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
       wsss.send(JSON.stringify(ping));
     }
     canDraw = true;
@@ -194,7 +200,7 @@ var draw_graph = function (graphType) {
 
   //鼠标离开 把蒙版canvas的图片生成到canvas中
   var touchend = function (e) {
-    var touchfor = e.originalEvent.touches; //for 的手指数组
+    var touchfor = e.originalEvent.changedTouches; //for 的手指数组
     //是否横屏
     for (var i = 0; i < touchfor.length; i++) {
       var acrossWidthX = touchfor[i].pageY * (videoHeight / voheight);
@@ -202,10 +208,14 @@ var draw_graph = function (graphType) {
       var verticalWidthX = touchfor[i].pageX * (videoWidth / vowidth);
       var verticalHeightY = touchfor[i].pageY * (videoHeight / voheight);
       var ping = resolving == 0 ?
-        { "data": { "action": 1, "count": touchfor.length, "id": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
-        { "data": { "action": 1, "count": touchfor.length, "id": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
+        { "data": { "action": 1, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
+        { "data": { "action": 1, "count": ongoingTouches.length, "pointerId": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
       wsss.send(JSON.stringify(ping));
+      ongoingTouches.forEach(function (item, index) {
+        if (item.identifier === touchfor[i].identifier) {
+          ongoingTouches.splice(index, 1)
+        }
+      })
     }
     canDraw = false;
   };
@@ -217,16 +227,15 @@ var draw_graph = function (graphType) {
 
   // 鼠标移动
   var touchmove = function (e) {
-    var touchfor = e.originalEvent.touches; //for 的手指数组
+    var touchfor = e.originalEvent.targetTouches; //for 的手指数组
     for (var i = 0; i < touchfor.length; i++) {
       var acrossWidthX = touchfor[i].pageY * (videoHeight / voheight);
       var acrossHeightY = videoWidth - touchfor[i].pageX * (videoWidth / vowidth);
       var verticalWidthX = touchfor[i].pageX * (videoWidth / vowidth);
       var verticalHeightY = touchfor[i].pageY * (videoHeight / voheight);
       var ping = resolving == 0 ?
-        { "data": { "action": 2, "count": touchfor.length, "id": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
-        { "data": { "action": 2, "count": touchfor.length, "id": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
+        { "data": { "action": 2, "count": touchfor.length, "pointerId": touchfor[i].identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
+        { "data": { "action": 2, "count": touchfor.length, "pointerId": touchfor[i].identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
       wsss.send(JSON.stringify(ping));
     }
   };