gcmsDrawPolygon.js 5.6 KB

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