toolWeatherMap.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * @fileoverview 工具 云图动画 模块
  3. * @author Song.Huang
  4. * @version 1.0.0
  5. */
  6. define(['html!templates/tools/toolWeatherMap',
  7. 'css!styles/tools/toolWeatherMap'],
  8. function(tpcLayout){
  9. /**
  10. * 状态值
  11. * @type {Boolean}
  12. * @default false
  13. * @private
  14. */
  15. var status ={
  16. initialized:false//是否初始化
  17. }
  18. /**
  19. * 模块数据 用于数据存储和外部调用
  20. * @type {Object}
  21. * 数据存放
  22. */
  23. var modValue ={
  24. weatherMapData:[],
  25. currentSelected:0,
  26. weatherMapLayerGuid:null,
  27. intervalTimer:null,
  28. timeStep:5000
  29. }
  30. /**
  31. * 初始化
  32. * 监听事件
  33. * @type {Function}
  34. */
  35. function init(options){
  36. remove();
  37. // modValue.weatherMapData = [
  38. // {
  39. // datetime:'2017-08-09 12:20',
  40. // layerUrl:'http://mt.mmmaps.cn/v1.0/gh?z={z}&x={x}&y={y}'
  41. // },
  42. // {
  43. // datetime:'2017-08-09 14:20',
  44. // layerUrl:'http://mt.mmmaps.cn/v1.0/go?z={z}&x={x}&y={y}'
  45. // },
  46. // {
  47. // datetime:'2017-08-09 15:20',
  48. // layerUrl:'http://mt.mmmaps.cn/v1.0/gr?z={z}&x={x}&y={y}'
  49. // },
  50. // {
  51. // datetime:'2017-08-09 16:20',
  52. // layerUrl:'http://mt.mmmaps.cn/v1.0/gm?z={z}&x={x}&y={y}'
  53. // }
  54. // ]
  55. for(var op in options){
  56. modValue[op] = options[op];
  57. }
  58. if(modValue.weatherMapData.length == 0){
  59. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有云图数据' }, 'noteBar::add');
  60. return false;
  61. }
  62. if(!status.initialized){
  63. status.initialized = true;
  64. setLayout();
  65. bindEvent();
  66. actionEvent();
  67. subscribe();
  68. }
  69. };
  70. function setLayout(){
  71. $('body').append(tpcLayout);
  72. //绑定数据列表
  73. _.each(modValue.weatherMapData, function(el,index) {
  74. $('<li cid="'+index+'">'+el.datetime+'</li>').appendTo('#timePlayerControl .time-list ul');
  75. });
  76. $('#timePlayerControl .time-list').mCustomScrollbar();
  77. };
  78. function bindEvent(){
  79. $('#timePlayerControl .abtn-close').bind('click',function(){
  80. $("#userThematicList .thematic-layer-link").removeClass('selected');
  81. remove();
  82. });
  83. $('#timePlayerControl .datetime-picker').bind('click',function(){
  84. $('#timePlayerControl .time-list').show();
  85. });
  86. $('#timePlayerControl .time-list').bind('mouseleave',function(){
  87. $('#timePlayerControl .time-list').hide();
  88. });
  89. $('#timePlayerControl .time-list li').bind('click',function(){
  90. rollPlay('stop');
  91. $('#timePlayerControl .datetime-picker').html($(this).html());
  92. $('#timePlayerControl .time-list').hide();
  93. modValue.currentSelected = $(this).attr('cid');
  94. actionEvent();
  95. });
  96. $('#timePlayerControl .player-control .prev-start').bind('click',function(){
  97. rollPlay('stop');
  98. modValue.currentSelected = 0;
  99. actionEvent();
  100. });
  101. $('#timePlayerControl .player-control .prev').bind('click',function(){
  102. if(modValue.currentSelected == 0){
  103. ONEMAP.C.publisher.publish({ type: 'warning', message: '已经到达第一条记录' }, 'noteBar::add');
  104. return false;
  105. }else {
  106. rollPlay('stop');
  107. modValue.currentSelected--;
  108. actionEvent();
  109. }
  110. });
  111. $('#timePlayerControl .player-control .pause').bind('click',function(){
  112. rollPlay('stop');
  113. });
  114. $('#timePlayerControl .player-control .play').bind('click',function(){
  115. rollPlay('start');
  116. });
  117. $('#timePlayerControl .player-control .next').bind('click',function(){
  118. if(modValue.currentSelected == (modValue.weatherMapData.length-1)){
  119. ONEMAP.C.publisher.publish({ type: 'warning', message: '已经到达最后一条记录' }, 'noteBar::add');
  120. return false;
  121. }else {
  122. rollPlay('stop');
  123. modValue.currentSelected++;
  124. actionEvent();
  125. }
  126. });
  127. $('#timePlayerControl .player-control .next-end').bind('click',function(){
  128. rollPlay('stop');
  129. modValue.currentSelected = modValue.weatherMapData.length-1;
  130. actionEvent();
  131. });
  132. };
  133. /**
  134. * 循环播放
  135. * @param {[type]} op [description]
  136. * @return {[type]} [description]
  137. */
  138. function rollPlay(op){
  139. if(op == 'stop'){
  140. clearInterval(modValue.intervalTimer);
  141. $('#timePlayerControl .player-control .pause').hide();
  142. $('#timePlayerControl .player-control .play').show();
  143. }
  144. if(op == 'start'){
  145. modValue.intervalTimer = setInterval(function(){
  146. modValue.currentSelected++;
  147. if(modValue.currentSelected == modValue.weatherMapData.length){
  148. modValue.currentSelected = 0;
  149. }
  150. actionEvent();
  151. },modValue.timeStep);
  152. actionEvent();
  153. $('#timePlayerControl .player-control .pause').show();
  154. $('#timePlayerControl .player-control .play').hide();
  155. }
  156. }
  157. /**
  158. * 播放面板触发事件
  159. * @return {[type]} [description]
  160. */
  161. function actionEvent(){
  162. //先移除后添加
  163. if(modValue.weatherMapLayerGuid){
  164. removeWeatherLayer();
  165. }
  166. var layerOp = {
  167. layerUrl:modValue.weatherMapData[modValue.currentSelected]['layerUrl']
  168. }
  169. $('#timePlayerControl .datetime-picker').html(modValue.weatherMapData[modValue.currentSelected]['datetime']);
  170. addWeatherLayer(layerOp);
  171. }
  172. /**
  173. * 添加云图到地图上
  174. */
  175. function addWeatherLayer(options){
  176. var tdTileLayerUrl = options['layerUrl'].replace('{z}/{x}/{y}', '%d/%d/%d');
  177. tdTileLayerUrl = options['layerUrl'].replace('z={z}&x={x}&y={y}', 'z=%d&x=%d&y=%d');
  178. modValue.weatherMapLayerGuid = map23DControl.tileLayer({
  179. action: 'add',
  180. layer: {
  181. url2D: options['layerUrl'],
  182. url3D: tdTileLayerUrl,
  183. imageType: 'png'
  184. }
  185. })
  186. }
  187. /**
  188. * 移除指定guid的云图
  189. * @return {[type]} [description]
  190. */
  191. function removeWeatherLayer(){
  192. map23DControl.tileLayer({
  193. action: 'remove',
  194. guid:modValue.weatherMapLayerGuid
  195. })
  196. modValue.weatherMapLayerGuid = null;
  197. }
  198. /**
  199. * 注册监听
  200. */
  201. function subscribe(){
  202. }
  203. /**
  204. * 功能移除
  205. */
  206. function remove(options){
  207. $('#timePlayerControl').remove();
  208. clearInterval(modValue.intervalTimer);
  209. modValue.weatherMapData = [];
  210. modValue.currentSelected = 0;
  211. removeWeatherLayer();
  212. modValue.weatherMapLayerGuid = null;
  213. status.initialized = false;
  214. }
  215. return ONEMAP.M.toolWeatherMap = {
  216. init:init,
  217. remove:remove
  218. }
  219. });