简体   繁体   English

ng单击X3Dom形状

[英]ng-click on X3Dom shape

I'm trying to use angular.js with X3DOM. 我正在尝试将angular.js与X3DOM结合使用。 I want to be able to create a shape (in this case a sphere), and have it do something when the user clicks on it. 我希望能够创建一个形状(在本例中为一个球体),并在用户单击它时使其执行某些操作。 I've been able to get it to work using the traditional onclick method. 我已经能够使用传统的onclick方法使其正常工作。 However, when I switch to angular's ng-click, to event fails to fire. 但是,当我切换到angular的ng-click时,触发事件失败。 Unfortunately, since the data that I want to display is stored within the controller, using the angular onclick is kind of a must. 不幸的是,由于我要显示的数据存储在控制器内,因此必须使用角度onclick。

I've done a bit of research and supposedly angular.js isn't 100% compatible with X3DOM, so I'm guessing this is part of the issue. 我已经做了一些研究,并且认为angular.js与X3DOM并非100%兼容,所以我猜测这是问题的一部分。 But I've been using other angular directives without an issue. 但是我一直在使用其他角度指令没有问题。 Does anyone know if there's a way around this error? 有人知道这种错误是否可以解决吗?

Code Sample: 代码示例:

<transform translation="{{datum['Market Loading']}} {{datum['Growth Loading']}} {{datum['Size Loading']}}" ng-repeat="datum in energy.data" ng-hide="energy.hide === true" onclick="">
    <shape>
        <appearance>
            <material class="energy" diffuseColor="{{energy.color.join(' ')}}" transparency="{{energy.hide}}"></material>
        </appearance>
        <sphere radius="{{datum['Specific Risk']}} ng-click="DO SOMETHING"></sphere>
    </shape>
</transform>

I guess you need to use the standard onclick event, as X3DOM needs to translate click events on the canvas to the actual node inside the tag and x3dom does not know abaout ng-click. 我猜您需要使用标准的onclick事件,因为X3DOM需要将画布上的click事件转换为标记内的实际节点,并且x3dom不知道abaout ng-click。 In your standard onclick handler you can retrieve the angular scope aganain an fire your angular click handler from there. 在您的标准onclick处理程序中,您可以从此处检索角度范围aganain。

Something like this (untestet): 像这样的(unestet):

<sphere radius="{{datum['Specific Risk']}} onclick="myclick(event)"></sphere>

and a standard onclick event handler: 和标准的onclick事件处理程序:

function myclick(event) {
    // TODO: add more error handling
    var scope = angular.element(event.target).scope();
    scope.yourAngularClickHandler(event);
}

This is a bit ugly and getting the scope from the dom element on every click may also be slow. 这有点丑陋,每次单击从dom元素获取范围也可能很慢。 I'm doing something similar with an onmousemove event and the speed is okay. 我正在与onmousemove事件做类似的事情,而且速度还可以。 Don't forget to add some error handling for the cases where the scope is not ready or cannot be found etc. 对于范围未准备好或找不到的情况,请不要忘记添加一些错误处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM