TableUserGPS_21201.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_DirLine:[cc.Node]
  5. },
  6. ctor:function(){
  7. this.m_bInit = false;
  8. },
  9. // LIFE-CYCLE CALLBACKS:
  10. onLoad:function ()
  11. {
  12. this.Init();
  13. },
  14. Init:function()
  15. {
  16. if(this.m_bInit == true) return;
  17. this.m_bInit = true;
  18. this.node.active = false;
  19. console.log("gps onload")
  20. this.m_UserArr = new Array();
  21. this.m_LabIp = new Array();
  22. // this.m_LabAddr = new Array();
  23. for(var i = 0;i<4;i++){
  24. this.m_UserArr[i] = this.node.getChildByName('UserCtrl'+i).getComponent('UserCtrl');
  25. this.m_LabIp[i] = this.m_UserArr[i].node.getChildByName('IP').getComponent(cc.Label);
  26. // this.m_LabAddr[i] = this.m_UserArr[i].node.getChildByName('Addr').getComponent(cc.Label);
  27. }
  28. var DirNode = this.node.getChildByName('Dir');
  29. this.m_DirLineArray={};
  30. this.m_DirLineArray['0to1'] = DirNode.getChildByName('left_up').getChildByName('dir').getComponent(cc.Label);
  31. this.m_DirLineArray['1to0'] = DirNode.getChildByName('left_up').getChildByName('dir').getComponent(cc.Label);
  32. this.m_DirLineArray['0to3'] = DirNode.getChildByName('right_up').getChildByName('dir').getComponent(cc.Label);
  33. this.m_DirLineArray['3to0'] = DirNode.getChildByName('right_up').getChildByName('dir').getComponent(cc.Label);
  34. this.m_DirLineArray['0to2'] = DirNode.getChildByName('shu').getChildByName('dir').getComponent(cc.Label);
  35. this.m_DirLineArray['2to0'] = DirNode.getChildByName('shu').getChildByName('dir').getComponent(cc.Label);
  36. this.m_DirLineArray['1to2'] = DirNode.getChildByName('left_bottom').getChildByName('dir').getComponent(cc.Label);
  37. this.m_DirLineArray['2to1'] = DirNode.getChildByName('left_bottom').getChildByName('dir').getComponent(cc.Label);
  38. this.m_DirLineArray['2to3'] = DirNode.getChildByName('right_bottom').getChildByName('dir').getComponent(cc.Label);
  39. this.m_DirLineArray['3to2'] = DirNode.getChildByName('right_bottom').getChildByName('dir').getComponent(cc.Label);
  40. this.m_DirLineArray['1to3'] = DirNode.getChildByName('heng').getChildByName('dir').getComponent(cc.Label);
  41. this.m_DirLineArray['3to1'] = DirNode.getChildByName('heng').getChildByName('dir').getComponent(cc.Label);
  42. },
  43. SetUserAddress :function(UserItem){
  44. var viewID = this.m_Hook.m_GameClientEngine.SwitchViewChairID(UserItem.GetChairID());
  45. this.m_UserArr[viewID].node.active = true;
  46. this.m_UserArr[viewID].SetUserByID(UserItem.GetUserID() );
  47. this.m_LabIp[viewID].string = 'IP:'+UserItem.GetUserIP();
  48. },
  49. UpdateUserData:function(){
  50. this.SetUserCount(GameDef.GetPlayerCount());
  51. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  52. this.m_UserArr[i].InitUser();
  53. this.m_LabIp[i].string = '';
  54. }
  55. var kernel = gClientKernel.get();
  56. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  57. var pIClientUserItem = kernel.GetTableUserItem(i);
  58. if( pIClientUserItem != null ){
  59. this.SetUserAddress(pIClientUserItem);
  60. }
  61. }
  62. },
  63. UpdateAddress:function(GPSInfo){
  64. for (let i = 0; i < 3; i++) {
  65. if( GPSInfo[i] == null ) continue;
  66. var viewID = this.GetUserChairID(GPSInfo[i].dwUserID);
  67. viewID = this.m_Hook.m_GameClientEngine.SwitchViewChairID(viewID);
  68. console.log('GPS:UserID='+GPSInfo[i].dwUserID+' viewID='+viewID);
  69. if( viewID != INVALD_CHAIR )
  70. {
  71. this.m_LabIp[viewID].string = ''+GPSInfo[i].szAddress;
  72. // if( GPSInfo[i].dlongitude != 0 ) {
  73. // this.m_LabIp[viewID].string = ''+GPSInfo[i].szAddress;
  74. // }
  75. // else{
  76. // this.m_LabIp[viewID].string = '无法获取到GPS信息!';
  77. // }
  78. }
  79. for (var j in GPSInfo) {
  80. if( i == j )continue;
  81. // if( GPSInfo[i].byHide == 0 || GPSInfo[j].byHide == 0 )continue;
  82. //if( 0 != GPSInfo[i].dlongitude && 0 != GPSInfo[j].dlongitude)
  83. {
  84. var fromID = this.GetUserChairID(GPSInfo[i].dwUserID);
  85. var toID = this.GetUserChairID(GPSInfo[j].dwUserID);
  86. if( fromID == INVALD_CHAIR || toID == INVALD_CHAIR )continue;
  87. fromID = this.m_Hook.m_GameClientEngine.SwitchViewChairID(fromID);
  88. toID = this.m_Hook.m_GameClientEngine.SwitchViewChairID(toID);
  89. var dis = this.GetDistance(GPSInfo[i].dlatitude, GPSInfo[i].dlongitude,
  90. GPSInfo[j].dlatitude, GPSInfo[j].dlongitude) + ' km';
  91. console.log("距離:"+''+fromID+'to'+toID+' ==>'+dis);
  92. this.m_DirLineArray[''+fromID+'to'+toID].string = dis;
  93. this.m_DirLineArray[''+fromID+'to'+toID].node.parent.active = true;
  94. }
  95. }
  96. }
  97. },
  98. GetUserChairID:function(UserID){
  99. var kernel = gClientKernel.get();
  100. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  101. var pIClientUserItem = kernel.GetTableUserItem(i);
  102. if( pIClientUserItem != null ){
  103. if( pIClientUserItem.GetUserID() == UserID ){
  104. return pIClientUserItem.GetChairID();
  105. }
  106. }
  107. }
  108. return INVALD_CHAIR;
  109. },
  110. SetUserCount:function(Count){
  111. this.Init();
  112. this.m_nCount = Count;
  113. for (var i in this.m_DirLineArray) {
  114. this.m_DirLineArray[i].node.parent.active = false;
  115. }
  116. if ( Count == 2 ){
  117. this.m_UserArr[0].node.active = true;
  118. this.m_UserArr[1].node.active = false;
  119. this.m_UserArr[2].node.active = true;
  120. this.m_UserArr[3].node.active = false;
  121. }
  122. else{
  123. for (var i = 0; i < 4; i++)
  124. {
  125. var wViewID = this.m_Hook.m_GameClientEngine.SwitchViewChairID(i);
  126. this.m_UserArr[wViewID].node.active = i < Count;
  127. }
  128. }
  129. },
  130. _Rad :function(d){
  131. return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
  132. },
  133. //计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度
  134. GetDistance : function (lat1,lng1,lat2,lng2) {
  135. var radLat1 = this._Rad(lat1);
  136. var radLat2 = this._Rad(lat2);
  137. var a = radLat1 - radLat2;
  138. var b = this._Rad(lng1) - this._Rad(lng2);
  139. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
  140. Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
  141. s = s *6378.137 ;// EARTH_RADIUS;
  142. s = Math.round(s * 10000) / 10000; //输出为公里
  143. return s;
  144. },
  145. // update (dt) {},
  146. });