Angular的nativescirpt-canvas-如何重绘Canvas?

时间:2019-07-18 20:45:31

标签: nativescript-plugin

我想用NativeScript编写一个简单的“指南针”应用程序,这是一个有趣的项目,将提交给GitHub。 GPS部分已完成。我正在使用:https://market.nativescript.org/plugins/nativescript-canvas,使用'tns create --ng'创建的应用程序。画布绘制一次,效果很好!但是我想不断地用来自GPS的数据重绘它,我不知道该怎么做。

我试图将'canvas'值保存在Component的实例变量中,我的意思是事件'draw'-> event附带的值:{canvas:Canvas}但是重用该值会破坏整个应用程序,实际上是“未定义”,由于我对Angular / TypeScript的了解有限,我无法理解。任何提示如何在我喜欢的地方获得“画布”?一个带有示例的git repo?

我遵循了Angular的说明:

绘制(事件:{canvas:画布}){...

将其部署到android仿真器会导致错误(请参见下文),但在代码中的任何地方添加空格都会强制进行重新部署(“已检测到更改”),从而可以正常部署。因此,这当然不能部署到实际设备上。但首先-我需要更新canvas :) thx。

System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.HelloWorld/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err:
System.err: Error: Main entry is missing. App cannot be started. Verify app bootstrap.
System.err: File: "file:///data/data/org.nativescript.HelloWorld/files/app/vendor.js, line: 21886, column: 20
System.err:
System.err: StackTrace:
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.HelloWorld/files/app/vendor.js', line: 21886, column: 27
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.HelloWorld/files/app/vendor.js', line: 21731, column: 14
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.HelloWorld/files/app/vendor.js', line: 19544, column: 25

1 个答案:

答案 0 :(得分:2)

event参数还具有object属性,即canvasView。

要重绘,您可以致电

event.object.redraw()

然后您的绘图函数将再次被调用,您可以处理画布更新。