gcmsThematic.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * [ONEMAP.M.gcmsThematic]
  3. * @return {[object]}
  4. */
  5. define(function(){
  6. //参数
  7. var modValue = {
  8. options:{}
  9. };
  10. /**
  11. * 模块初始化
  12. * @return {[type]} [description]
  13. */
  14. function init(options){
  15. remove();
  16. modValue.options = {};
  17. for(var op in options){
  18. modValue.options[op] = options[op];
  19. }
  20. //注册监听
  21. subscribe();
  22. //获取内容数据
  23. getDetailData({callback:function(){
  24. showThematic();
  25. }});
  26. }
  27. function getDetailData(options){
  28. ONEMAP.V.loading.load();
  29. $.ajax({
  30. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  31. type:"GET",
  32. dataType: 'json'
  33. })
  34. .done(function(data) {
  35. ONEMAP.V.loading.loaded();
  36. if(data.code == 4){
  37. ONEMAP.C.noPermission('getDetailData');
  38. return false;
  39. }
  40. if(data.code == 3){
  41. ONEMAP.C.logout('getDetailData');
  42. }
  43. ONEMAP.D.gcmsCurArticleData = data['data'];
  44. options.callback();
  45. })
  46. .fail(function() {
  47. ONEMAP.V.loading.loaded();
  48. });
  49. }
  50. function showThematic(){
  51. if(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']].length == 0){
  52. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有专题图数据' }, 'noteBar::add');
  53. return false;
  54. }
  55. var thematicData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]);
  56. ONEMAP.V.loading.load();
  57. $.ajax({
  58. url: onemapUrlConfig.thematicDataUrl+'/production/metadata?production_id='+thematicData['guid'],
  59. type:"GET",
  60. dataType: 'json'
  61. })
  62. .done(function(data) {
  63. ONEMAP.V.loading.loaded();
  64. if(data.code == 4){
  65. ONEMAP.C.noPermission('getDetailData');
  66. }
  67. if(data.code == 3){
  68. ONEMAP.C.logout('getDetailData');
  69. }
  70. require(['modDir/atlas/atlasList'],function(atlasList){
  71. var layerObj = {
  72. guid:thematicData['guid'],
  73. name:'thematic_'+thematicData['guid'],
  74. center:[thematicData['center_lat'],thematicData['center_lon']],
  75. zoom:thematicData['min_zoom'],
  76. thumb_min_id:thematicData['thumb_min_id'],
  77. translate:thematicData['name'],
  78. min_zoom:thematicData['min_zoom'],
  79. max_zoom:thematicData['max_zoom'],
  80. data_type:thematicData['data_type'],
  81. map_type:thematicData['map_type'],
  82. showFavBtn:false,
  83. status:true
  84. }
  85. //atlasList._addSingleLayersControl();
  86. atlasList.addOverLayerToMap(layerObj);
  87. });
  88. })
  89. .fail(function() {
  90. ONEMAP.V.loading.loaded();
  91. });
  92. }
  93. function addThematicToMap(){
  94. }
  95. /**
  96. * 收藏专题图
  97. * @param {[type]} layerObj [description]
  98. */
  99. function _addFavThematic(layerObj){
  100. require(['modDir/userThematic'],function(userThematic){
  101. userThematic.addThematic(layerObj);
  102. });
  103. }
  104. /**
  105. * 注册监听
  106. * @type {Function}
  107. */
  108. function subscribe(){
  109. map2DViewer.map.on('layerOpacity:addFav',_addFavThematic);
  110. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  111. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  112. }
  113. /**
  114. * 取消监听
  115. * @type {Function}
  116. */
  117. function unSubscribe() {
  118. map2DViewer.map.off('layerOpacity:addFav',_addFavThematic);
  119. }
  120. /**
  121. * 模块移除
  122. * @return {[type]} [description]
  123. */
  124. function remove(){
  125. if(ONEMAP.M.thematic){
  126. ONEMAP.M.thematic.removeCurrentOverLayer();
  127. }
  128. unSubscribe();
  129. }
  130. return ONEMAP.M.gcmsThematic = {
  131. init:init,
  132. remove:remove
  133. }
  134. });