gcmsPolygon.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * [ONEMAP.M.gcmsPolyline]
  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({callback:function(){
  31. showDrawLayer();
  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. map23DControl.polygon({
  105. action: 'add',
  106. groupId: modValue.mapDrawGroup,
  107. geojson: {
  108. "properties": {
  109. altitudeMode:0,
  110. color: options['properties']['style'].color,
  111. weight: options['properties']['style'].weight,
  112. opacity: options['properties']['style'].opacity,
  113. fillColor:options['properties']['style'].fillColor,
  114. fillOpacity:options['properties']['style'].fillOpacity,
  115. stroke:options['properties']['style'].stroke
  116. },
  117. "geometry": {
  118. "coordinates": options['geometry']['coordinates']
  119. }
  120. }
  121. })
  122. }
  123. /**
  124. * 注册监听
  125. * @type {Function}
  126. */
  127. function subscribe(){
  128. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  129. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  130. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  131. }
  132. /**
  133. * 取消监听
  134. * @type {Function}
  135. */
  136. function unSubscribe() {}
  137. function GroupControl(type) {
  138. if (type == "show") {
  139. map23DControl.group({
  140. action: 'show',
  141. guid: modValue.mapDrawGroup
  142. })
  143. map23DControl.group({
  144. action: 'show',
  145. guid: modValue.mapDrawGroup
  146. })
  147. } else if (type == "hide") {
  148. map23DControl.group({
  149. action: 'hide',
  150. guid: modValue.mapDrawGroup
  151. })
  152. map23DControl.group({
  153. action: 'hide',
  154. guid: modValue.mapDrawGroup
  155. })
  156. }
  157. }
  158. /**
  159. * 模块移除
  160. * @return {[type]} [description]
  161. */
  162. function remove(){
  163. map23DControl.group({
  164. action: 'cleanAll',
  165. guid: modValue.mapDrawGroup
  166. })
  167. map23DControl.group({
  168. action: 'remove',
  169. guid: modValue.mapDrawGroup
  170. })
  171. unSubscribe();
  172. }
  173. return ONEMAP.M.gcmsPolyline = {
  174. init:init,
  175. remove:remove
  176. }
  177. });