gridInfoByLonlat.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. define(['html!templates/menu/baseCalc/gridInfoByLonlat',
  2. 'css!styles/tools/toolPublicPopup',
  3. 'css!styles/menu/baseCalc/gridInfoByLonlat',
  4. ],
  5. function (tplLayout) {
  6. /**
  7. * 模块状态,用于存储模块的状态 例如:收起,关闭
  8. * @type {Object}
  9. */
  10. var status = {
  11. initialized: false//是否初始化
  12. };
  13. /**
  14. * 模块数据 用于数据存储和外部调用
  15. * @type {Object}
  16. * 数据存放
  17. */
  18. var modValue = {
  19. data: {},
  20. handler: null
  21. };
  22. /**
  23. * 初始化并订阅事件
  24. * @return {[type]} [description]
  25. */
  26. function open(data) {
  27. if (!status.initialized) {
  28. setLayout();
  29. bindEvent();
  30. subscribe();
  31. status.initialized = true;
  32. } else {
  33. // 重置
  34. reset();
  35. }
  36. modValue.data = data;
  37. $("#gridInfoByLonlatModal .title").text(data.label);
  38. ONEMAP.C.publisher.publish({
  39. modName: 'gridInfoByLonlat'
  40. }, 'baseCalc:active');
  41. };
  42. function setLayout() {
  43. $('body').append(tplLayout);
  44. //拖拽
  45. $("#gridInfoByLonlatModal .popup-ct").dragmove($('#gridInfoByLonlatModal'));
  46. };
  47. /**
  48. * 事件绑定
  49. */
  50. function bindEvent() {
  51. $("#gridInfoByLonlatModal .close").bind('click', function () {
  52. close();
  53. });
  54. $("#gridInfoByLonlatModal .openFunc").bind('click', function () {
  55. openFunc();
  56. });
  57. $("#gridInfoByLonlatModal .closeFunc").bind('click', function () {
  58. closeFunc();
  59. });
  60. };
  61. function openFunc() {
  62. addMapClickEvent();
  63. }
  64. function closeFunc() {
  65. removeMapClickEvent();
  66. }
  67. /**
  68. * 注册监听
  69. * @type {Function}
  70. */
  71. function subscribe() {
  72. ONEMAP.C.publisher.subscribe(remove, 'baseCalc:active');
  73. };
  74. /**
  75. * 关闭模块
  76. * @return {[type]} [description]
  77. */
  78. function remove(options) {
  79. if (options.modName != 'gridInfoByLonlat') {
  80. close();
  81. } else {
  82. $("#gridInfoByLonlatModal").show();
  83. }
  84. }
  85. function reset() {
  86. $("#gridInfoByLonlatForm .outputResult table tr").empty("")
  87. removeMapClickEvent();
  88. }
  89. function close() {
  90. $("#gridInfoByLonlatModal").hide();
  91. reset();
  92. }
  93. /**
  94. * 获取并计算经纬度
  95. * @private
  96. */
  97. function getInfo(lon, lat) {
  98. $.ajax({
  99. type: "get",
  100. dataType: 'json',
  101. url: onemapUrlConfig.PROXY_URL + "/getWGridCJByLonlat",
  102. data: {
  103. lon: lon,
  104. lat: lat,
  105. },
  106. success: function (data) {
  107. if (data.code == 200) {
  108. setOutputResult(data.content)
  109. }
  110. },
  111. error: function (error) {
  112. console.log(error)
  113. }
  114. });
  115. return;
  116. };
  117. function setOutputResult(data) {
  118. $("#gridInfoByLonlatForm .outputResult table tr").empty()
  119. let html = "";
  120. ttttt(data.位置信息).map(function (item) {
  121. html += item
  122. })
  123. if (typeof data.微网格信息 != "string" && Object.getOwnPropertyNames(data.微网格信息).length >= 3) {
  124. ttttt(data.微网格信息).map(function (item) {
  125. html += item
  126. })
  127. }
  128. if (typeof data.村居信息 != "string" && Object.getOwnPropertyNames(data.村居信息).length >= 3) {
  129. ttttt(data.村居信息).map(function (item) {
  130. html += item
  131. })
  132. }
  133. if (typeof data.网格信息 != "string" && Object.getOwnPropertyNames(data.网格信息).length >= 3) {
  134. ttttt(data.网格信息).map(function (item) {
  135. html += item
  136. })
  137. }
  138. function ttttt(obj) {
  139. let fieldArr = Object.getOwnPropertyNames(obj);
  140. let htmlArr = fieldArr.map(function (field) {
  141. return "<tr><td><span>" + field + ":</span></td><td><span>" + obj[field] + "</span></td></tr>"
  142. })
  143. return htmlArr;
  144. }
  145. $("#gridInfoByLonlatForm .outputResult table tr").append(html);
  146. }
  147. function addMapClickEvent() {
  148. if (modValue.handler != null) return;
  149. modValue.handler = new Cesium.ScreenSpaceEventHandler(map3DViewer.map.canvas);
  150. // 监听鼠标点击事件
  151. modValue.handler.setInputAction(function (click) {
  152. let cartesian = map3DViewer.map.scene.globe.pick(map3DViewer.map.camera.getPickRay(click.position), map3DViewer.map.scene);
  153. if (Cesium.defined(cartesian)) {
  154. // 将笛卡尔坐标转换为经纬度坐标
  155. var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
  156. var longitude = Cesium.Math.toDegrees(cartographic.longitude)
  157. var latitude = Cesium.Math.toDegrees(cartographic.latitude)
  158. getInfo(longitude, latitude)
  159. // var heightString = cartographic.height.toFixed(2);
  160. // console.log('经度:' + longitudeString + ',纬度:' + latitudeString + ',高度:' + heightString)
  161. }
  162. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  163. }
  164. function removeMapClickEvent() {
  165. if (modValue.handler) {
  166. modValue.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
  167. modValue.handler = null;
  168. }
  169. }
  170. return ONEMAP.M.gridInfoByLonlatForm = {
  171. open: open,
  172. };
  173. })