gcmsDrawPoint.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * 绘制点
  3. * [ONEMAP.M.gcmsDrawPoint]
  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. showDrawPoint();
  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 showDrawPoint() {
  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 'Point'://点
  83. buildMarker(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 buildMarker(options) {
  93. var coordinates = options.geometry.coordinates;
  94. for(var i=0;i<coordinates.length;i++){
  95. map23DControl.marker({
  96. action: 'add',
  97. groupId: modValue.mapDrawGroup,
  98. geojson: {
  99. "properties": {
  100. altitudeMode: 0,
  101. iconUrl: map23DConfig.map23DAssetsUrl+'/images/gcms/marker-icon.png',
  102. iconSize: [32,32],
  103. iconAnchor: [16,32]
  104. },
  105. "geometry": {
  106. "coordinates": coordinates[i]
  107. }
  108. }
  109. })
  110. }
  111. }
  112. /**
  113. * 注册监听
  114. * @type {Function}
  115. */
  116. function subscribe() {
  117. ONEMAP.C.publisher.subscribe(remove, 'gcmsArticleShowRemove');
  118. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  119. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  120. }
  121. function GroupControl(type) {
  122. if (type == "show") {
  123. map23DControl.group({
  124. action: 'show',
  125. guid: modValue.mapDrawGroup
  126. })
  127. map23DControl.group({
  128. action: 'show',
  129. guid: modValue.mapDrawGroup
  130. })
  131. } else if (type == "hide") {
  132. map23DControl.group({
  133. action: 'hide',
  134. guid: modValue.mapDrawGroup
  135. })
  136. map23DControl.group({
  137. action: 'hide',
  138. guid: modValue.mapDrawGroup
  139. })
  140. }
  141. }
  142. /**
  143. * 取消监听
  144. * @type {Function}
  145. */
  146. function unSubscribe() {}
  147. /**
  148. * 模块移除
  149. * @return {[type]} [description]
  150. */
  151. function remove() {
  152. map23DControl.group({
  153. action: 'cleanAll',
  154. guid: modValue.mapDrawGroup
  155. })
  156. map23DControl.group({
  157. action: 'remove',
  158. guid: modValue.mapDrawGroup
  159. })
  160. unSubscribe();
  161. }
  162. function GroupControl(type) {
  163. if (type == "show") {
  164. map23DControl.group({
  165. action: 'show',
  166. guid: modValue.mapDrawGroup
  167. })
  168. map23DControl.group({
  169. action: 'show',
  170. guid: modValue.mapDrawGroup
  171. })
  172. } else if (type == "hide") {
  173. map23DControl.group({
  174. action: 'hide',
  175. guid: modValue.mapDrawGroup
  176. })
  177. map23DControl.group({
  178. action: 'hide',
  179. guid: modValue.mapDrawGroup
  180. })
  181. }
  182. }
  183. return ONEMAP.M.gcmsDrawPoint = {
  184. init: init,
  185. remove: remove
  186. }
  187. });