服务器期望的笔画类型是一个带有x、y属性的json对象,包含两个整数数组。这些值表示在设备触摸屏上书写时的 x,y 坐标用户输入。您可以收集并添加时间戳作为 JSON 笔画类型结构的可选“t”属性。
作为第一个选项,您可以使用我们的 web 组件:myscript-math-web、myscript-text-web 甚至 MyScriptJS 来管理用户墨水捕获和画布中的渲染。
你也可以自己抓取用户的笔迹,这种情况下我们推荐你使用(jquery PEP)[https://github.com/jquery/PEP](Pointer Event Polyfill)来帮助你管理用户触屏事件,即指针事件。
您必须监听 pointerdown、pointermove 和 pointerup 事件。一旦发生此类事件,以这种方式将事件坐标添加到您的结构中,例如:
var myStroke;
document.querySelector('#myCanvasId').addEventListener('pointerdown', function (e) {
e.preventDefault();
我的行程= {x:[],y:[],t:[]};
mystroke.x.push(e.clientX);
mystroke.y.push(e.clientY);
mystroke.t.push(e.timestamp)
},假);
document.querySelector('#myCanvasId').addEventListener('pointermove', function (e) {
e.preventDefault();
mystroke.x.push(e.clientX);
mystroke.y.push(e.clientY);
mystroke.t.push(e.timestamp)
},假);
document.querySelector('#myCanvasId').addEventListener('pointerup', function (e) {
e.preventDefault();
mystroke.x.push(e.clientX);
mystroke.y.push(e.clientY);
mystroke.t.push(e.timestamp)
// Send your stroke to the server
mystroke = {};
}, false);
如果您需要更详细的解释,可以查看this video。 10:40 上有关数字墨水捕获的详细信息。