gcmsShowInfos.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /**
  2. * [ONEMAP.M.gcmsShowInfos]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsShowInfos',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsShowInfos'],
  9. function(tpcLayout,Handlebars){
  10. /**
  11. * [modValue description]
  12. * 数据模块
  13. * @type {Object}
  14. */
  15. var modValue = {
  16. infoData:null,
  17. markerGroup:null,
  18. markers:{},
  19. iviewer:null
  20. };
  21. /**
  22. * 状态模块
  23. */
  24. var status = {
  25. initialized:false,
  26. showVideo:false,
  27. showImage:false,
  28. showAudio:false
  29. };
  30. function init(options){
  31. if(!status.initialized){
  32. subscribe();
  33. setLayout();
  34. status.initialized = true;
  35. }
  36. modValue.infoData = options;
  37. //添加markerGroup
  38. if(modValue.markerGroup){
  39. modValue.markerGroup = map23DControl.group({
  40. action: 'add'
  41. })
  42. }
  43. var markerID = null;
  44. if(modValue.infoData.action == 'add'){
  45. markerID = parsingData();
  46. }else if(modValue.infoData.action == 'remove'){
  47. removeCurMarker()
  48. }else if(modValue.infoData.action == 'removeAll'){
  49. removeAll();
  50. }else if(modValue.infoData.action == 'getMarkerInfos'){
  51. markerID = getMarkerInfos();
  52. }
  53. if(markerID){
  54. return markerID;
  55. }
  56. }
  57. function setLayout(){
  58. $(tpcLayout).appendTo($('body'));
  59. }
  60. /**
  61. * 创建markerPoup
  62. */
  63. function buildMarkerPoup(options){
  64. var popupHtml = '<div class="popup_html marker">'+
  65. ' <div class="popup-lt"></div>'+
  66. ' <div class="popup-lb"></div>'+
  67. ' <div class="popup-rt"></div>'+
  68. ' <div class="popup-rb"></div>'+
  69. ' <div class="popup-ct" style="text-indent:15px;line-height:48px">'+options.name+
  70. ' </div>'+
  71. ' <div class="popup-cb" style="padding-bottom:20px;color:#666666 !important">'+
  72. ' <div class="gems_marker" style="padding:30px 5px 0px 5px">'+options.content+
  73. ' </div>'+
  74. ' </div>'+
  75. '</div>'
  76. return popupHtml;
  77. }
  78. /**
  79. * 解析数据
  80. */
  81. function parsingData(){
  82. var curData = JSON.parse(modValue.infoData.data),markerPoup,locationData,markerOptions,dataUrl;
  83. switch (curData.table){
  84. case "record_note"://文本
  85. textHtml = curData.gcms_title+'<br/>'+curData.description;
  86. markerOptions ={
  87. markerPoup:buildMarkerPoup({
  88. name:curData.gcms_title,
  89. content:textHtml
  90. }),
  91. markerData:curData
  92. }
  93. break;
  94. case "record_picture"://图片
  95. var imageData = JSON.parse(curData.location_image).features[0];
  96. dataUrl = imageData.properties.file;
  97. var imageName = imageData.properties.name;
  98. markerOptions ={
  99. markerPoup:buildMarkerPoup({
  100. name:curData.gcms_title,
  101. content:'<a href="javascript:ONEMAP.M.gcmsShowInfos.showImage(\''+dataUrl+'\')">查看'+imageName+'</a>'
  102. }),
  103. markerData:curData,
  104. markerRecord:'location_image'
  105. }
  106. break;
  107. case "record_audio"://音频
  108. var audioData = JSON.parse(curData.location_audio).features[0];
  109. dataUrl = audioData.properties.file;
  110. var audioName = audioData.properties.name;
  111. markerOptions ={
  112. markerPoup:buildMarkerPoup({
  113. name:curData.gcms_title,
  114. content:'<a href="javascript:ONEMAP.M.gcmsShowInfos.showAudio(\''+dataUrl+'\')">查看'+audioName+'</a>'
  115. }),
  116. markerData:curData,
  117. markerRecord:'location_audio'
  118. }
  119. break;
  120. case "record_video"://视频
  121. var videoData = JSON.parse(curData.location_video).features[0];
  122. dataUrl = videoData.properties.file;
  123. var videoName = videoData.properties.name;
  124. markerOptions ={
  125. markerPoup:buildMarkerPoup({
  126. name:curData.gcms_title,
  127. content:'<a href="javascript:ONEMAP.M.gcmsShowInfos.showVideo(\''+dataUrl+'\')">查看'+videoName+'</a>'
  128. }),
  129. markerData:curData,
  130. markerRecord:'location_video'
  131. }
  132. break;
  133. }
  134. return showMarker(markerOptions)
  135. }
  136. /**
  137. * [showMarker description]
  138. * 添加marker点
  139. * @return {[type]} [description]
  140. */
  141. function showMarker(markerOptions){
  142. var markerData = markerOptions.markerData;
  143. var coordinates,locationData,title;
  144. if(markerOptions.markerRecord){
  145. locationData = markerData[markerOptions.markerRecord];
  146. locationData = JSON.parse(locationData).features[0];
  147. coordinates = locationData.geometry.coordinates;
  148. title = locationData.properties.name;
  149. }else{
  150. coordinates = [markerData.lon,markerData.lat];
  151. title = markerData.gcms_title;
  152. }
  153. var markerId = map23DControl.marker({
  154. action:'add',
  155. groupId:modValue.markerGroup,
  156. geojson:{
  157. "type": "Feature",
  158. "properties": {
  159. iconUrl: map23DConfig.map23DAssetsUrl+'/images/gcms/icon_'+markerData.table+'.png',
  160. iconSize: [35,50],
  161. iconAnchor: [17,50],
  162. popupAnchor: [0,-50],
  163. altitude:0,
  164. altitudeMode:1,
  165. },
  166. "geometry": {
  167. "type": "Point",
  168. "coordinates": coordinates
  169. }
  170. }
  171. })
  172. map2DViewer.markers[markerId].bindPopup(markerOptions.markerPoup,{title:title});
  173. modValue.markers[markerId] = {
  174. guid:markerId,
  175. location:markerOptions.markerRecord || 0,
  176. metaData:markerData
  177. };
  178. map23DControl.setView({
  179. center: {
  180. lat: coordinates[1],
  181. lng: coordinates[0]
  182. }
  183. })
  184. return markerId;
  185. }
  186. /**
  187. * 移除单个标记
  188. */
  189. function removeCurMarker(){
  190. var curGuid = modValue.infoData.guid;
  191. map23DControl.marker({
  192. action: 'remove',
  193. guid: curGuid
  194. })
  195. delete modValue.markers[curGuid];
  196. }
  197. /**
  198. *移除全部标记点
  199. */
  200. function removeAll(){
  201. map23DControl.group({
  202. action: 'cleanAll',
  203. guid: modValue.markerGroup
  204. })
  205. }
  206. /**
  207. * 获取标记点信息
  208. * 根据guid单个获取
  209. * 传递参数'all' 可以获取所有标记点信息
  210. */
  211. function getMarkerInfos(){
  212. var markerInfos = [];
  213. if(modValue.infoData.guid == "all"){
  214. $.each(modValue.markers,function(i,t){
  215. markerInfos.push(creatMeta(t));
  216. })
  217. }else{
  218. var metaData = modValue.markers[modValue.infoData.guid];
  219. markerInfos.push(creatMeta(metaData))
  220. }
  221. return markerInfos;
  222. }
  223. function creatMeta(t){
  224. var meta;
  225. if(t.location == 0) {
  226. meta = {
  227. id:t.metaData.gcms_id,
  228. title:t.metaData.gcms_title,
  229. note:t.metaData.description,
  230. lon:t.metaData.lon,
  231. lat:t.metaData.lat,
  232. type:t.metaData.type,
  233. createId:t.guid
  234. }
  235. }else{
  236. var curRecord = JSON.parse(t.metaData[t.location]).features[0];
  237. meta = {
  238. id:t.metaData.gcms_id,
  239. title:t.metaData.gcms_title,
  240. note:t.metaData.description,
  241. lon:curRecord.geometry.coordinates[0],
  242. lat:curRecord.geometry.coordinates[1],
  243. type:t.metaData.type,
  244. url:curRecord.properties.file,
  245. createId:t.guid
  246. }
  247. }
  248. return meta;
  249. }
  250. /**
  251. * 查看图片
  252. */
  253. function showImage(url){
  254. var showImageTemplate = Handlebars.compile($('#picture-item-template').html());
  255. if(status.showImage){
  256. $("#gcmsShowInfosPictureViewer").remove()
  257. }else{
  258. status.showImage = true;
  259. }
  260. $('body').append(showImageTemplate());
  261. url = onemapUrlConfig.gcmsServiceUrl+'/file'+url;
  262. if(modValue.iviewer){
  263. modValue.iviewer.iviewer('loadImage', url);
  264. return false;
  265. }else {
  266. modValue.iviewer = $("#gcmsShowInfosPictureViewerBox").iviewer(
  267. {
  268. zoom_max:200,
  269. zoom_min:5,
  270. zoom:100,
  271. src: url,
  272. update_on_resize:true,
  273. });
  274. }
  275. $('#gcmsShowInfosPictureViewer .close').bind('click', function() {
  276. $("#gcmsShowInfosPictureViewer").remove()
  277. });
  278. $('#gcmsShowInfosPictureViewer .modal-body').css({height:$(window).height()/3*2});
  279. var $box2 = $('#gcmsShowInfosPictureViewer').on('mousedown', '#coorForShowInfosPictureViewer', function(e) {
  280. var posix = {
  281. 'w': $box2.width(),
  282. 'h': $box2.height(),
  283. 'x': e.pageX,
  284. 'y': e.pageY
  285. };
  286. $.extend(document, {'move': true, 'call_down': function(e) {
  287. $box2.css({
  288. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  289. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  290. });
  291. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-75;
  292. $("#gcmsShowInfosPictureViewer .modal-body").css({height:bodyHeight});
  293. $("#gcmsShowInfosPictureViewerBox").iviewer('update');
  294. }});
  295. return false;
  296. });
  297. //拖拽
  298. $("#gcmsShowInfosPictureViewer .popup-ct").dragmove($('#gcmsShowInfosPictureViewer'));
  299. };
  300. /**
  301. * 播放视频
  302. */
  303. function showVideo(url){
  304. var showVideoTemplate = Handlebars.compile($('#video-item-template').html());
  305. if(status.showVideo){
  306. $("#gcmsShowInfosModal").remove()
  307. }else{
  308. status.showVideo = true;
  309. }
  310. $('body').append(showVideoTemplate());
  311. var videoFileUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+url;
  312. var flashPlayerInfo = flashChecker();
  313. if (flashPlayerInfo && flashPlayerInfo.v > 10) {
  314. var videPlayerHtml = _setFlashPlayer("videoPlayer", "scripts/vendor/player/snplayer.swf?file=type:mp4;url:" + videoFileUrl + "", "100%", "100%", "SkinURL=skin/default.zip", true);
  315. } else {
  316. if (document.all) {
  317. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_winax.exe';
  318. } else {
  319. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_win.exe';
  320. }
  321. var videPlayerHtml = '<div class="install-flash-player" style="text-align:center">' +
  322. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  323. '<a href="' + flashPlayerLink + '"><img src="images/layout/get_flash.png"/><br/><span>Adobe Flash Player 11</span></a>' +
  324. '</div>';
  325. }
  326. $('#gcmsShowInfosVideoPlayer').empty().html(videPlayerHtml);
  327. $('#gcmsShowInfosModal .popup-ct .close').bind('click', function() {
  328. $("#gcmsShowInfosModal").remove()
  329. });
  330. $('#gcmsShowInfosModal .popup-ct').dragmove($('#gcmsShowInfosModal'));
  331. var $box2 = $('#gcmsShowInfosModal').on('mousedown', '#coorForShowInfosVideoModal', function(e) {
  332. var posix = {
  333. 'w': $box2.width(),
  334. 'h': $box2.height(),
  335. 'x': e.pageX,
  336. 'y': e.pageY
  337. };
  338. $.extend(document, {'move': true, 'call_down': function(e) {
  339. $box2.css({
  340. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  341. //'height': Math.max(30, e.pageY - posix.y + posix.h)
  342. });
  343. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-145;
  344. $("#gcmsShowInfosModal .modal-body").css({height:bodyHeight});
  345. }});
  346. $.extend(document, {'move': true, 'call_up': function(e) {
  347. $('#gcmsShowInfosVideoList .selected').click();
  348. }});
  349. return false;
  350. });
  351. };
  352. /**
  353. * 播放音频
  354. */
  355. function showAudio(url){
  356. var showAudioTemplate = Handlebars.compile($('#audio-item-template').html());
  357. if(status.showAudio){
  358. $("#gcmsShowInfosModal").remove()
  359. }else{
  360. status.showAudio = true;
  361. }
  362. $('body').append(showAudioTemplate());
  363. var flashPlayerInfo = flashChecker();
  364. var audioFileUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+url;
  365. if (flashPlayerInfo && flashPlayerInfo.v > 10) {
  366. var audioPlayerHtml = _setFlashPlayer("audioPlayer", "scripts/vendor/player/snplayer.swf?file=type:mp3;url:" + audioFileUrl + "", "100%", "100%", "SkinURL=skin/default.zip", true);
  367. } else {
  368. if (document.all) {
  369. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_winax.exe';
  370. } else {
  371. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_win.exe';
  372. }
  373. var audioPlayerHtml = '<div class="install-flash-player" style="text-align:center">' +
  374. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  375. '<a href="' + flashPlayerLink + '"><img src="images/layout/get_flash.png"/><br/><span>Adobe Flash Player 11</span></a>' +
  376. '</div>';
  377. }
  378. $('#gcmsShowInfosAudioPlayer').empty().append(audioPlayerHtml);
  379. $('#gcmsShowInfosAudioModal .close').bind('click', function() {
  380. $("#gcmsShowInfosAudioModal").remove()
  381. });
  382. $('#gcmsShowInfosAudioModal .popup-ct').dragmove($('#gcmsShowInfosAudioModal'));
  383. var $box2 = $('#gcmsShowInfosAudioModal').on('mousedown', '#coorForShowInfosAudioModal', function(e) {
  384. var posix = {
  385. 'w': $box2.width(),
  386. 'h': $box2.height(),
  387. 'x': e.pageX,
  388. 'y': e.pageY
  389. };
  390. $.extend(document, {'move': true, 'call_down': function(e) {
  391. $box2.css({
  392. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  393. //'height': Math.max(30, e.pageY - posix.y + posix.h)
  394. });
  395. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-145;
  396. $("#gcmsShowInfosAudioModal .modal-body").css({height:bodyHeight});
  397. }});
  398. $.extend(document, {'move': true, 'call_up': function(e) {
  399. $('#gcmsShowInfosAudioList .selected').click();
  400. }});
  401. return false;
  402. });
  403. };
  404. function flashChecker(){
  405. var hasFlash = 0;
  406. var flashVersion =0;
  407. try{
  408. if(document.all){
  409. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  410. if(swf){
  411. hasFlash = 1;
  412. VSwf = swf.GetVariable('$version');
  413. flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
  414. }
  415. }else {
  416. if(navigator.plugins && navigator.plugins.length > 0){
  417. var swf = navigator.plugins["Shockwave Flash"];
  418. }
  419. if(swf){
  420. hasFlash = 1;
  421. var words = swf.description.split(" ");
  422. for(var i=0;i<words.length; i++){
  423. if(isNaN(parseInt(words[i]))) continue;
  424. flashVersion = parseInt(words[i]);
  425. }
  426. }
  427. }
  428. }catch (e) {
  429. }
  430. return {
  431. f:hasFlash,
  432. v:flashVersion
  433. };
  434. }
  435. /**
  436. * 添加Flash Player
  437. * @type {Function}
  438. * @param id {String} 容器id
  439. * @param url {String} url
  440. * @param width {Number} 宽度
  441. * @param height {Number} 高度
  442. * @param vars {String} 参数
  443. * @param transparent {String} 是否透明
  444. * @returns {string} flash player code
  445. * @private
  446. */
  447. function _setFlashPlayer(id, url, width, height, vars, transparent){
  448. $('#DIVSNplayerWMPvideoPlayer').remove();
  449. var wmode = transparent ? "transparent" : "opaque";
  450. var html = '';
  451. html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
  452. html += 'width="'+width+'" ';
  453. html += 'height="'+height+'" ';
  454. html += 'id="'+id+'"';
  455. html += '>';
  456. html += '<param name="movie" value="'+url+'" />';
  457. html += '<param name="allowFullScreen" value="true" />';
  458. html += '<param name="allowScriptAccess" value="always" />';
  459. html += '<param name="quality" value="high" />';
  460. html += '<param name="wmode" value="'+wmode+'" />';
  461. html += '<param name="flashvars" value="'+vars+'" />';
  462. html += '<embed type="application/x-shockwave-flash" ';
  463. html += 'width="'+width+'" ';
  464. html += 'height="'+height+'" ';
  465. html += 'name="'+id+'" ';
  466. html += 'src="'+url+'" ';
  467. html += 'allowfullscreen="true" ';
  468. html += 'allowscriptaccess="always" ';
  469. html += 'quality="high" ';
  470. html += 'wmode="'+wmode+'" ';
  471. html += 'flashvars="'+vars+'"'
  472. html += '></embed>';
  473. html += '</object>';
  474. return html;
  475. };
  476. /**
  477. * 注册订阅
  478. * @type {Function}
  479. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  480. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  481. */
  482. function subscribe(){}
  483. /**
  484. * 取消订阅
  485. * @type {Function}
  486. * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  487. */
  488. function unSubscribe(){}
  489. /**
  490. * 模块移除
  491. * @return {[type]} [description]
  492. */
  493. function remove(){
  494. //取消订阅
  495. unSubscribe();
  496. }
  497. return ONEMAP.M.gcmsShowInfos = {
  498. init:init,
  499. showImage:showImage,
  500. showVideo:showVideo,
  501. showAudio:showAudio
  502. }
  503. })
  504. /**
  505. * 模块调用方法
  506. */
  507. //add
  508. //ONEMAP.M.gcmsShowInfos.init({
  509. // action:'add',
  510. // data:data
  511. //})
  512. //
  513. //ONEMAP.M.gcmsShowInfos.init({
  514. // action:'remove', getMarkerInfos
  515. // guid:guid
  516. //})
  517. //
  518. //ONEMAP.M.gcmsShowInfos.init({
  519. // action:'removeAll'
  520. //})
  521. //
  522. //ONEMAP.M.gcmsShowInfos.init({
  523. // action:'getMarkerInfos'
  524. // guid:'all'
  525. //})
  526. //
  527. //
  528. //
  529. //{
  530. // "updatetime":1512732052000,
  531. // "gcms_secret_level":0,
  532. // "gcms_comment":"[{\"remark\": \"1\", \"auditor\": \"map_super_user\", \"time\": 1512972448364}, {\"remark\": \"1\", \"auditor\": \"map_super_user\", \"time\": 1512972098504}, {\"remark\": \"1\", \"auditor\": \"map_super_user\", \"time\": 1512971452320}]",
  533. // "gcms_publisher":"14",
  534. // "gcms_publish_time":1512972501575,
  535. // "gcms_title":"图像",
  536. // "gcms_status":3,
  537. // "location_image":"{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[119.31152344,34.57895241]},\"properties\":{\"type\":\"PictureLocation\",\"name\":\"连云港\",\"popupContent\":\"\",\"style\":{\"iconUrl\":\"/common/c1046a12-676d-11e7-91c9-0242ac110021.png\",\"iconSize\":[28,32],\"iconAnchor\":[14,16]},\"file\":\"/content/record_picture/133/a686d740-de39-11e7-b5c0-0242ac110016.jpg\"}}]}",
  538. // "description":"此为添加图像示例",
  539. // "gcms_create_time":1512733166995,
  540. // "gcms_auditor_name":"map_super_user",
  541. // "gcms_auditor":"14",
  542. // "gcms_id":133,
  543. // "gcms_toptime":0,
  544. // "gcms_audit_time":1512972499776,
  545. // "gcms_publisher_name":"map_super_user",
  546. // "gcms_istop":0,
  547. // "gcms_creator":"1535",
  548. // "gcms_read_number":188,
  549. // "gcms_creator_name":"867106023867663@xdc.org",
  550. // "gcms_change_time":1512972494784,
  551. // "model":"record_picture",
  552. // "table":"record_picture",
  553. // "tablename":"图片"
  554. //}