gcmsTrajectory.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. * [ONEMAP.M.gcmsTrajectory]
  3. * @return {[object]}
  4. */
  5. define(function() {
  6. //数据存放和外部调用
  7. var modValue = {
  8. options: {},
  9. mapDrawGroup: null,
  10. };
  11. /**
  12. * 模块初始化
  13. * @return {[type]} [description]
  14. */
  15. function init(options) {
  16. if(options.type!="all"){
  17. remove();
  18. }
  19. modValue.mapDrawGroup = map23DControl.group({
  20. action: 'add'
  21. });
  22. modValue.options = {};
  23. for (var op in options) {
  24. modValue.options[op] = options[op];
  25. }
  26. //订阅推送
  27. subscribe();
  28. //modValue.mapDrawGroup.addTo(_map);
  29. //获取内容数据
  30. getDetailData({
  31. callback: function() {
  32. showDrawLayer();
  33. }
  34. });
  35. }
  36. /**
  37. * 坐标反转
  38. * @param {[type]} latlngsAry [description]
  39. * @return {[type]} [description]
  40. */
  41. function latLngsToReverse(latlngsAry) {
  42. var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry));
  43. if (!$.isArray(tempLatlngsAry[0])) {
  44. return tempLatlngsAry.reverse();
  45. } else {
  46. $(tempLatlngsAry).each(function(index, el) {
  47. tempLatlngsAry[index] = latLngsToReverse(el);
  48. });
  49. }
  50. return tempLatlngsAry;
  51. };
  52. function getDetailData(options) {
  53. ONEMAP.V.loading.load();
  54. $.ajax({
  55. url: onemapUrlConfig.gcmsServiceUrl + '/show/' + modValue.options['column_name'] + '/' + modValue.options['article_id'],
  56. type: "GET",
  57. dataType: 'json'
  58. })
  59. .done(function(data) {
  60. ONEMAP.V.loading.loaded();
  61. if (data.code == 4) {
  62. ONEMAP.T.noPermission('getDetailData');
  63. }
  64. if (data.code == 3) {
  65. ONEMAP.T.logout('getDetailData');
  66. }
  67. ONEMAP.D.gcmsCurArticleData = data['data'];
  68. options.callback();
  69. })
  70. .fail(function() {
  71. ONEMAP.V.loading.loaded();
  72. });
  73. }
  74. /**
  75. * 显示标注内容
  76. * @return {[type]} [description]
  77. */
  78. function showDrawLayer() {
  79. var mapDrawData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]);
  80. var lineArray = [];
  81. if (mapDrawData['features'].length > 0) {
  82. $(mapDrawData['features']).each(function(index, el) {
  83. if(modValue.options.showMarker){
  84. buildMarker(el);
  85. }
  86. lineArray.push(el.geometry.coordinates);
  87. });
  88. buildPolyline(lineArray);
  89. map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapDrawGroup].getBounds());
  90. } else {
  91. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add');
  92. }
  93. }
  94. //打点
  95. function buildMarker(options) {
  96. var popupHtml = '<ul>'+
  97. '<li>时间:'+options.properties.time+'</li>'+
  98. '<li>海拔:'+options.properties.elevation+'</li>'+
  99. '<li>速度:'+options.properties.speed+'</li>'+
  100. '<li>精度:'+options.properties.accuracy+'</li>'+
  101. '<li>方位:'+options.properties.bearing+'</li>'+
  102. '</ul>';
  103. var options_popup = {
  104. name:'',
  105. content:popupHtml
  106. };
  107. popupHtml = ONEMAP.M.gcmsNav.creatPopupHtml(options_popup);
  108. map23DControl.marker({
  109. action: 'add',
  110. groupId: modValue.mapDrawGroup,
  111. geojson: {
  112. "type": "Feature",
  113. "properties": {
  114. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/ico_linePoint.png',
  115. iconSize: [14, 14],
  116. iconAnchor: [7, 7],
  117. popupAnchor: [0, -14],
  118. altitudeMode: 0,
  119. popupContent:popupHtml
  120. },
  121. "geometry": {
  122. "type": "Point",
  123. "coordinates": [options.geometry.coordinates[0], options.geometry.coordinates[1]]
  124. }
  125. }
  126. })
  127. };
  128. //画线
  129. function buildPolyline(lineArray) {
  130. map23DControl.polyline({
  131. action: 'add',
  132. groupId: modValue.mapDrawGroup,
  133. geojson: {
  134. "properties": {
  135. altitudeMode: 0,
  136. color: '#0033ff',
  137. weight: 5,
  138. opacity: 0.5
  139. },
  140. "geometry": {
  141. "coordinates": lineArray
  142. }
  143. }
  144. })
  145. };
  146. /**
  147. * 注册监听
  148. * @type {Function}
  149. */
  150. function subscribe() {
  151. ONEMAP.C.publisher.subscribe(remove, 'gcmsArticleShowRemove');
  152. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  153. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  154. }
  155. /**
  156. * 取消监听
  157. * @type {Function}
  158. */
  159. function unSubscribe() {}
  160. function GroupControl(type) {
  161. if (type == "show") {
  162. map23DControl.group({
  163. action: 'show',
  164. guid: modValue.mapDrawGroup
  165. })
  166. map23DControl.group({
  167. action: 'show',
  168. guid: modValue.mapDrawGroup
  169. })
  170. } else if (type == "hide") {
  171. map23DControl.group({
  172. action: 'hide',
  173. guid: modValue.mapDrawGroup
  174. })
  175. map23DControl.group({
  176. action: 'hide',
  177. guid: modValue.mapDrawGroup
  178. })
  179. }
  180. }
  181. /**
  182. * 模块移除
  183. * @return {[type]} [description]
  184. */
  185. function remove() {
  186. map23DControl.group({
  187. action: 'cleanAll',
  188. guid: modValue.mapDrawGroup
  189. })
  190. map23DControl.group({
  191. action: 'remove',
  192. guid: modValue.mapDrawGroup
  193. })
  194. unSubscribe();
  195. }
  196. return ONEMAP.M.gcmsTrajectory = {
  197. init: init,
  198. remove: remove
  199. }
  200. });