gcmsPolyline.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 'Polyline'://线
  82. buildPolyline(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 buildPolyline(options){
  92. if(!options['properties']['style']){
  93. _.merge(options['properties'],{
  94. style:{
  95. color:'#0033ff',
  96. weight:5,
  97. opacity:0.5
  98. }
  99. })
  100. }
  101. map23DControl.polyline({
  102. action: 'add',
  103. groupId: modValue.mapDrawGroup,
  104. geojson: {
  105. "properties": {
  106. altitudeMode:0,
  107. color: options['properties']['style'].color,
  108. weight: options['properties']['style'].weight,
  109. opacity: options['properties']['style'].opacity,
  110. },
  111. "geometry": {
  112. "coordinates": options['geometry']['coordinates']
  113. }
  114. }
  115. })
  116. }
  117. /**
  118. * 注册监听
  119. * @type {Function}
  120. */
  121. function subscribe(){
  122. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  123. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  124. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  125. }
  126. /**
  127. * 取消监听
  128. * @type {Function}
  129. */
  130. function unSubscribe() {}
  131. function GroupControl(type) {
  132. if (type == "show") {
  133. map23DControl.group({
  134. action: 'show',
  135. guid: modValue.mapDrawGroup
  136. })
  137. map23DControl.group({
  138. action: 'show',
  139. guid: modValue.mapDrawGroup
  140. })
  141. } else if (type == "hide") {
  142. map23DControl.group({
  143. action: 'hide',
  144. guid: modValue.mapDrawGroup
  145. })
  146. map23DControl.group({
  147. action: 'hide',
  148. guid: modValue.mapDrawGroup
  149. })
  150. }
  151. }
  152. /**
  153. * 模块移除
  154. * @return {[type]} [description]
  155. */
  156. function remove(){
  157. map23DControl.group({
  158. action: 'cleanAll',
  159. guid: modValue.mapDrawGroup
  160. })
  161. map23DControl.group({
  162. action: 'remove',
  163. guid: modValue.mapDrawGroup
  164. })
  165. unSubscribe();
  166. }
  167. return ONEMAP.M.gcmsPolyline = {
  168. init:init,
  169. remove:remove
  170. }
  171. });