gcmsPoint.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * [ONEMAP.M.gcmsPoint]
  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 'Point'://点
  82. buildMarker(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 buildMarker(options){
  92. map23DControl.marker({
  93. action: 'add',
  94. groupId: modValue.mapDrawGroup,
  95. geojson: {
  96. "properties": {
  97. altitudeMode:0,
  98. iconUrl: onemapUrlConfig.gcmsServiceUrl+'/file'+options['properties']['style']['iconUrl'],
  99. iconSize: options['properties']['style']['iconSize'],
  100. iconAnchor: options['properties']['style']['iconAnchor'],
  101. popupAnchor: [0,-options['properties']['style']['iconAnchor'][1]]
  102. },
  103. "geometry": {
  104. "coordinates": options['geometry']['coordinates']
  105. }
  106. }
  107. })
  108. }
  109. /**
  110. * 注册监听
  111. * @type {Function}
  112. */
  113. function subscribe(){
  114. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  115. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  116. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  117. }
  118. /**
  119. * 取消监听
  120. * @type {Function}
  121. */
  122. function unSubscribe() {}
  123. function GroupControl(type) {
  124. if (type == "show") {
  125. map23DControl.group({
  126. action: 'show',
  127. guid: modValue.mapDrawGroup
  128. })
  129. map23DControl.group({
  130. action: 'show',
  131. guid: modValue.mapDrawGroup
  132. })
  133. } else if (type == "hide") {
  134. map23DControl.group({
  135. action: 'hide',
  136. guid: modValue.mapDrawGroup
  137. })
  138. map23DControl.group({
  139. action: 'hide',
  140. guid: modValue.mapDrawGroup
  141. })
  142. }
  143. }
  144. /**
  145. * 模块移除
  146. * @return {[type]} [description]
  147. */
  148. function remove(){
  149. map23DControl.group({
  150. action: 'cleanAll',
  151. guid: modValue.mapDrawGroup
  152. })
  153. map23DControl.group({
  154. action: 'remove',
  155. guid: modValue.mapDrawGroup
  156. })
  157. unSubscribe();
  158. }
  159. return ONEMAP.M.gcmsPoint = {
  160. init:init,
  161. remove:remove
  162. }
  163. });