gcmsDrawPolyline.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * 绘制线
  3. * [ONEMAP.M.gcmsDrawPolyline]
  4. * @return {[object]}
  5. */
  6. define(function() {
  7. //数据存放和外部调用
  8. var modValue = {
  9. options: {},
  10. mapDrawGroup: null,
  11. };
  12. /**
  13. * 模块初始化
  14. * @return {[type]} [description]
  15. */
  16. function init(options) {
  17. remove();
  18. modValue.mapDrawGroup = map23DControl.group({
  19. action: 'add'
  20. });
  21. modValue.options = {};
  22. for (var op in options) {
  23. modValue.options[op] = options[op];
  24. }
  25. //订阅推送
  26. subscribe();
  27. //modValue.mapDrawGroup.addTo(_map);
  28. //获取内容数据
  29. getDetailData({
  30. callback: function() {
  31. showDrawLayer();
  32. }
  33. });
  34. }
  35. /**
  36. * 坐标反转
  37. * @param {[type]} latlngsAry [description]
  38. * @return {[type]} [description]
  39. */
  40. function latLngsToReverse(latlngsAry) {
  41. var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry));
  42. if (!$.isArray(tempLatlngsAry[0])) {
  43. return tempLatlngsAry.reverse();
  44. } else {
  45. $(tempLatlngsAry).each(function(index, el) {
  46. tempLatlngsAry[index] = latLngsToReverse(el);
  47. });
  48. }
  49. return tempLatlngsAry;
  50. };
  51. function getDetailData(options) {
  52. ONEMAP.V.loading.load();
  53. $.ajax({
  54. url: onemapUrlConfig.gcmsServiceUrl + '/show/' + modValue.options['column_name'] + '/' + modValue.options['article_id'],
  55. type: "GET",
  56. dataType: 'json'
  57. })
  58. .done(function(data) {
  59. ONEMAP.V.loading.loaded();
  60. if (data.code == 4) {
  61. ONEMAP.T.noPermission('getDetailData');
  62. }
  63. if (data.code == 3) {
  64. ONEMAP.T.logout('getDetailData');
  65. }
  66. ONEMAP.D.gcmsCurArticleData = data['data'];
  67. options.callback();
  68. })
  69. .fail(function() {
  70. ONEMAP.V.loading.loaded();
  71. });
  72. }
  73. /**
  74. * 显示标注内容
  75. * @return {[type]} [description]
  76. */
  77. function showDrawLayer() {
  78. var mapDrawData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]);
  79. if (mapDrawData['features'].length > 0) {
  80. $(mapDrawData['features']).each(function(index, el) {
  81. //switch(el['properties']['type']){
  82. //case 'Polyline'://线
  83. buildPolyline(el);
  84. // break;
  85. // }
  86. });
  87. map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapDrawGroup].getBounds());
  88. } else {
  89. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add');
  90. }
  91. }
  92. function buildPolyline(options) {
  93. if (!options['properties']['style']) {
  94. _.merge(options['properties'], {
  95. style: {
  96. color: '#0033ff',
  97. weight: 5,
  98. opacity: 0.5
  99. }
  100. })
  101. }
  102. map23DControl.polyline({
  103. action: 'add',
  104. groupId: modValue.mapDrawGroup,
  105. geojson: {
  106. "properties": {
  107. altitudeMode: 0,
  108. color: '#0033ff',
  109. weight: 5,
  110. opacity: 0.5
  111. },
  112. "geometry": {
  113. "coordinates": options['geometry']['coordinates']
  114. }
  115. }
  116. })
  117. }
  118. /**
  119. * 注册监听
  120. * @type {Function}
  121. */
  122. function subscribe() {
  123. ONEMAP.C.publisher.subscribe(remove, 'gcmsArticleShowRemove');
  124. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  125. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  126. }
  127. /**
  128. * 取消监听
  129. * @type {Function}
  130. */
  131. function unSubscribe() {}
  132. /**
  133. * 模块移除
  134. * @return {[type]} [description]
  135. */
  136. function remove() {
  137. map23DControl.group({
  138. action: 'cleanAll',
  139. guid: modValue.mapDrawGroup
  140. })
  141. map23DControl.group({
  142. action: 'remove',
  143. guid: modValue.mapDrawGroup
  144. })
  145. unSubscribe();
  146. }
  147. function GroupControl(type) {
  148. if (type == "show") {
  149. map23DControl.group({
  150. action: 'show',
  151. guid: modValue.mapDrawGroup
  152. })
  153. map23DControl.group({
  154. action: 'show',
  155. guid: modValue.mapDrawGroup
  156. })
  157. } else if (type == "hide") {
  158. map23DControl.group({
  159. action: 'hide',
  160. guid: modValue.mapDrawGroup
  161. })
  162. map23DControl.group({
  163. action: 'hide',
  164. guid: modValue.mapDrawGroup
  165. })
  166. }
  167. }
  168. return ONEMAP.M.gcmsDrawPolyline = {
  169. init: init,
  170. remove: remove
  171. }
  172. });