gcmsPointAVideo.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /**
  2. * [ONEMAP.M.gcmsVideo]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsVideo',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsVideo'],
  9. function(tpcLayout,Handlebars){
  10. var modValue = {
  11. options:{},
  12. mapPointGroup:null,
  13. };
  14. /**
  15. * 模块初始化
  16. * @return {[type]} [description]
  17. */
  18. function init(options){
  19. remove();
  20. modValue.mapPointGroup = map23DControl.group({
  21. action: 'add'
  22. });
  23. modValue.options = {};
  24. for(var op in options){
  25. modValue.options[op] = options[op];
  26. }
  27. //获取内容数据
  28. getDetailData();
  29. //订阅推送
  30. subscribe();
  31. }
  32. function getDetailData(options){
  33. ONEMAP.V.loading.load();
  34. $.ajax({
  35. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  36. type:"GET",
  37. dataType: 'json'
  38. })
  39. .done(function(data) {
  40. ONEMAP.V.loading.loaded();
  41. if(data.code == 4){
  42. ONEMAP.T.noPermission('getDetailData');
  43. }
  44. if(data.code == 3){
  45. ONEMAP.T.logout('getDetailData');
  46. }
  47. if(JSON.parse(data['data']['record'][modValue.options['field_name']])['features'].length == 0){
  48. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有视频数据' }, 'noteBar::add');
  49. remove();
  50. }else {
  51. ONEMAP.D.gcmsCurArticleData = data['data'];
  52. showPoint();
  53. //showVideo();
  54. }
  55. })
  56. .fail(function() {
  57. ONEMAP.V.loading.loaded();
  58. });
  59. }
  60. /**
  61. * 事件绑定
  62. * @return {[type]} [description]
  63. */
  64. function bindEvent(){
  65. $('#gcmsVideoModal .modal-header .close').bind('click', function() {
  66. remove();
  67. });
  68. $('#gcmsVideoModal .modal-header').dragmove($('#gcmsVideoModal'));
  69. var $box2 = $('#gcmsVideoModal').on('mousedown', '#coorForGcmsVideoModal', function(e) {
  70. var posix = {
  71. 'w': $box2.width(),
  72. 'h': $box2.height(),
  73. 'x': e.pageX,
  74. 'y': e.pageY
  75. };
  76. $.extend(document, {'move': true, 'call_down': function(e) {
  77. $box2.css({
  78. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  79. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  80. });
  81. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-145;
  82. $("#gcmsVideoModal .modal-body").css({height:bodyHeight});
  83. }});
  84. $.extend(document, {'move': true, 'call_up': function(e) {
  85. $('#gcmsVideoList .selected').click();
  86. }});
  87. return false;
  88. });
  89. }
  90. function showPoint(){
  91. var mapDrawData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]);
  92. if(mapDrawData['features'].length>0){
  93. $(mapDrawData['features']).each(function(index, el) {
  94. switch(el['properties']['type']){
  95. case 'VideoLocation'://点
  96. buildMarker(el);
  97. break;
  98. }
  99. });
  100. map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapPointGroup].getBounds());
  101. }else {
  102. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add');
  103. }
  104. };
  105. function buildMarker(options){
  106. var curGuid = map23DControl.marker({
  107. action: 'add',
  108. groupId: modValue.mapPointGroup,
  109. geojson: {
  110. "properties": {
  111. altitudeMode:0,
  112. iconUrl: onemapUrlConfig.gcmsServiceUrl+'/file'+options['properties']['style']['iconUrl']+'?jwt='+ONEMAP.D.user.ticket,
  113. iconSize: options['properties']['style']['iconSize'],
  114. iconAnchor: options['properties']['style']['iconAnchor'],
  115. popupAnchor: [0,-options['properties']['style']['iconAnchor'][1]]
  116. },
  117. "geometry": {
  118. "coordinates": options['geometry']['coordinates']
  119. }
  120. }
  121. });
  122. var file = options['properties']['file'];
  123. var oLabelObj = '<a href="javascript:ONEMAP.M.gcmsPointVideo.showVideo(\''+file+'\')">播放视频</a>';
  124. var options_popup = {
  125. name:'',
  126. content:oLabelObj
  127. };
  128. var new_popupHtml = ONEMAP.M.gcmsNav.creatPopupHtml(options_popup);
  129. map2DViewer.markers[curGuid].bindPopup(new_popupHtml,{
  130. closeButton:false,
  131. maxWidth:60,
  132. minWidth:40});
  133. map2DViewer.markers[curGuid].openPopup();
  134. map2DViewer.markers[curGuid].on('mouseover',function(){
  135. this.openPopup();
  136. })
  137. }
  138. function showVideo(file){
  139. $('#gcmsVideoModal').remove();
  140. $('#DIVSNplayerWMPvideoPlayer').remove();
  141. $('body').append(tpcLayout);
  142. bindEvent();
  143. var videoFileUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+file+'?jwt='+ONEMAP.D.user.ticket;
  144. // if(Modernizr.video.h264.length>0){
  145. // var videPlayerHtml = '<video src="'+videoFileUrl+'" width="470" height="400" autoplay controls></video>';
  146. // }else {
  147. var flashPlayerInfo = flashChecker();
  148. if (flashPlayerInfo && flashPlayerInfo.v > 10) {
  149. var videPlayerHtml = _setFlashPlayer("videoPlayer", "scripts/vendor/player/snplayer.swf?file=type:mp4;url:" + videoFileUrl + "", "100%", "100%", "SkinURL=skin/default.zip", true);
  150. } else {
  151. if (document.all) {
  152. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_winax.exe';
  153. } else {
  154. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_win.exe';
  155. }
  156. var videPlayerHtml = '<div class="install-flash-player" style="text-align:center">' +
  157. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  158. '<a href="' + flashPlayerLink + '"><img src="images/layout/get_flash.png"/><br/><span>Adobe Flash Player 11</span></a>' +
  159. '</div>';
  160. }
  161. //}
  162. $('#gcmsVideoModal').show();
  163. $('#gcmsVideoPlayer').empty().html(videPlayerHtml);
  164. //显示列表
  165. $('#gcmsVideoList').empty();
  166. /*$(JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']])).each(function(index, el) {
  167. $('<li><button vUrl="'+onemapUrlConfig.gcmsServiceUrl+'/file'+el+'" class="btn">视频['+(index+1)+']</button></li>').appendTo($('#gcmsVideoList'));
  168. });*/
  169. $('#gcmsVideoList .btn:eq(0)').addClass('selected');
  170. $('#gcmsVideoList .btn').bind('click',function(){
  171. var videoFileUrl = $(this).attr('vUrl');
  172. // if(Modernizr.video.h264.length>0){
  173. // var videPlayerHtml = '<video src="'+videoFileUrl+'" width="470" height="400" autoplay controls></video>';
  174. // }else {
  175. var flashPlayerInfo = flashChecker();
  176. if (flashPlayerInfo && flashPlayerInfo.v > 10) {
  177. var videPlayerHtml = _setFlashPlayer("videoPlayer", "scripts/vendor/player/snplayer.swf?file=type:mp4;url:" + videoFileUrl + "", "100%", "100%", "SkinURL=skin/default.zip", true);
  178. } else {
  179. if (document.all) {
  180. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_winax.exe';
  181. } else {
  182. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_win.exe';
  183. }
  184. var videPlayerHtml = '<div class="install-flash-player" style="text-align:center">' +
  185. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  186. '<a href="' + flashPlayerLink + '"><img src="images/layout/get_flash.png"/><br/><span>Adobe Flash Player 11</span></a>' +
  187. '</div>';
  188. }
  189. //}
  190. $('#gcmsVideoModal').show();
  191. $('#gcmsVideoPlayer').empty().html(videPlayerHtml);
  192. $('#gcmsVideoModal .selected').removeClass('selected');
  193. $(this).addClass('selected');
  194. });
  195. }
  196. function flashChecker(){
  197. var hasFlash = 0;
  198. var flashVersion =0;
  199. try{
  200. if(document.all){
  201. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  202. if(swf){
  203. hasFlash = 1;
  204. VSwf = swf.GetVariable('$version');
  205. flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
  206. }
  207. }else {
  208. if(navigator.plugins && navigator.plugins.length > 0){
  209. var swf = navigator.plugins["Shockwave Flash"];
  210. }
  211. if(swf){
  212. hasFlash = 1;
  213. var words = swf.description.split(" ");
  214. for(var i=0;i<words.length; i++){
  215. if(isNaN(parseInt(words[i]))) continue;
  216. flashVersion = parseInt(words[i]);
  217. }
  218. }
  219. }
  220. }catch (e) {
  221. }
  222. return {
  223. f:hasFlash,
  224. v:flashVersion
  225. };
  226. }
  227. /**
  228. * 添加Flash Player
  229. * @type {Function}
  230. * @param id {String} 容器id
  231. * @param url {String} url
  232. * @param width {Number} 宽度
  233. * @param height {Number} 高度
  234. * @param vars {String} 参数
  235. * @param transparent {String} 是否透明
  236. * @returns {string} flash player code
  237. * @private
  238. */
  239. function _setFlashPlayer(id, url, width, height, vars, transparent){
  240. $('#DIVSNplayerWMPvideoPlayer').remove();
  241. var wmode = transparent ? "transparent" : "opaque";
  242. var html = '';
  243. html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
  244. html += 'width="'+width+'" ';
  245. html += 'height="'+height+'" ';
  246. html += 'id="'+id+'"';
  247. html += '>';
  248. html += '<param name="movie" value="'+url+'" />';
  249. html += '<param name="allowFullScreen" value="true" />';
  250. html += '<param name="allowScriptAccess" value="always" />';
  251. html += '<param name="quality" value="high" />';
  252. html += '<param name="wmode" value="'+wmode+'" />';
  253. html += '<param name="flashvars" value="'+vars+'" />';
  254. html += '<embed type="application/x-shockwave-flash" ';
  255. html += 'width="'+width+'" ';
  256. html += 'height="'+height+'" ';
  257. html += 'name="'+id+'" ';
  258. html += 'src="'+url+'" ';
  259. html += 'allowfullscreen="true" ';
  260. html += 'allowscriptaccess="always" ';
  261. html += 'quality="high" ';
  262. html += 'wmode="'+wmode+'" ';
  263. html += 'flashvars="'+vars+'"'
  264. html += '></embed>';
  265. html += '</object>';
  266. return html;
  267. };
  268. /**
  269. * 界面布局重置
  270. * @type {Function}
  271. */
  272. function layoutResize(){
  273. }
  274. /**
  275. * 注册监听
  276. * @type {Function}
  277. */
  278. function subscribe(){
  279. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  280. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  281. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  282. }
  283. /**
  284. * 取消监听
  285. * @type {Function}
  286. */
  287. function unSubscribe() {}
  288. function GroupControl(type) {
  289. if (type == "show") {
  290. map23DControl.group({
  291. action: 'show',
  292. guid: modValue.mapPointGroup
  293. })
  294. map23DControl.group({
  295. action: 'show',
  296. guid: modValue.mapPointGroup
  297. })
  298. } else if (type == "hide") {
  299. map23DControl.group({
  300. action: 'hide',
  301. guid: modValue.mapPointGroup
  302. })
  303. map23DControl.group({
  304. action: 'hide',
  305. guid: modValue.mapPointGroup
  306. })
  307. }
  308. }
  309. /**
  310. * 模块移除
  311. * @return {[type]} [description]
  312. */
  313. function remove(){
  314. map23DControl.group({
  315. action: 'cleanAll',
  316. guid: modValue.mapPointGroup
  317. })
  318. map23DControl.group({
  319. action: 'remove',
  320. guid: modValue.mapPointGroup
  321. })
  322. $('#gcmsVideoModal').remove();
  323. $('#DIVSNplayerWMPvideoPlayer').remove();
  324. unSubscribe();
  325. }
  326. return ONEMAP.M.gcmsPointVideo = {
  327. init:init,
  328. remove:remove,
  329. showVideo:showVideo
  330. }
  331. });