gcmsPointAPicture.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. * [ONEMAP.M.gcmsPointAPicture]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsPicture',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsPicture'],
  9. function(tpcLayout,Handlebars){
  10. //数据存放和外部调用
  11. var modValue = {
  12. options:{},
  13. iviewer:null,
  14. pictureUrl:null,
  15. mapPointGroup:null,
  16. }
  17. /**
  18. * 模块初始化
  19. * @return {[type]} [description]
  20. */
  21. function init(options){
  22. remove();
  23. modValue.mapPointGroup = map23DControl.group({
  24. action: 'add'
  25. });
  26. modValue.options = {};
  27. for(var op in options){
  28. modValue.options[op] = options[op];
  29. }
  30. //获取内容数据
  31. getDetailData();
  32. //订阅推送
  33. subscribe();
  34. }
  35. function getDetailData(options){
  36. ONEMAP.V.loading.load();
  37. $.ajax({
  38. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  39. type:"GET",
  40. dataType: 'json'
  41. })
  42. .done(function(data) {
  43. ONEMAP.V.loading.loaded();
  44. if(data.code == 4){
  45. ONEMAP.T.noPermission('getDetailData');
  46. }
  47. if(data.code == 3){
  48. ONEMAP.T.logout('getDetailData');
  49. }
  50. if(JSON.parse(data['data']['record'][modValue.options['field_name']])['features'].length == 0){
  51. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有图片数据' }, 'noteBar::add');
  52. remove();
  53. }else {
  54. ONEMAP.D.gcmsCurArticleData = data['data'];
  55. showPoint();
  56. }
  57. })
  58. .fail(function() {
  59. ONEMAP.V.loading.loaded();
  60. });
  61. }
  62. function showPoint(){
  63. var mapDrawData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]);
  64. if(mapDrawData['features'].length>0){
  65. $(mapDrawData['features']).each(function(index, el) {
  66. switch(el['properties']['type']){
  67. case 'PictureLocation'://点
  68. buildMarker(el);
  69. break;
  70. }
  71. });
  72. map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapPointGroup].getBounds());
  73. }else {
  74. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add');
  75. }
  76. };
  77. function buildMarker(options){
  78. var curGuid = map23DControl.marker({
  79. action: 'add',
  80. groupId: modValue.mapPointGroup,
  81. geojson: {
  82. "properties": {
  83. altitudeMode:0,
  84. iconUrl: onemapUrlConfig.gcmsServiceUrl+'/file'+options['properties']['style']['iconUrl']+'?jwt='+ONEMAP.D.user.ticket,
  85. iconSize: options['properties']['style']['iconSize'],
  86. iconAnchor: options['properties']['style']['iconAnchor'],
  87. popupAnchor: [0,-options['properties']['style']['iconAnchor'][1]]
  88. },
  89. "geometry": {
  90. "coordinates": options['geometry']['coordinates']
  91. }
  92. }
  93. });
  94. var file = options['properties']['file'];
  95. var oLabelObj = '<a href="javascript:ONEMAP.M.gcmsPointAPicture.setPictureModal(\''+file+'\')">显示图片</a>';
  96. var options_popup = {
  97. name:'',
  98. content:oLabelObj
  99. };
  100. var new_popupHtml = ONEMAP.M.gcmsNav.creatPopupHtml(options_popup);
  101. map2DViewer.markers[curGuid].bindPopup(new_popupHtml,{
  102. closeButton:false,
  103. maxWidth:60,
  104. minWidth:40});
  105. map2DViewer.markers[curGuid].openPopup();
  106. map2DViewer.markers[curGuid].on('mouseover',function(){
  107. this.openPopup();
  108. })
  109. }
  110. /**
  111. * 设置容器
  112. */
  113. function setPictureModal(file){
  114. modValue.pictureUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+file+'?jwt='+ONEMAP.D.user.ticket;
  115. $('#gcmsPictureViewer').remove();
  116. $('body').append(tpcLayout);
  117. bindEvent();
  118. $('#gcmsPictureViewer').show();
  119. if(modValue.iviewer){
  120. modValue.iviewer.iviewer('loadImage', modValue.pictureUrl);
  121. return false;
  122. }else {
  123. modValue.iviewer = $("#gcmsPictureViewerBox").iviewer(
  124. {
  125. zoom_max:200,
  126. zoom_min:5,
  127. src: modValue.pictureUrl
  128. });
  129. }
  130. }
  131. /**
  132. * 事件绑定
  133. * @return {[type]} [description]
  134. */
  135. function bindEvent(){
  136. layoutResize();
  137. $('#gcmsPictureViewer .popup-ct .close').bind('click', function() {
  138. remove();
  139. });
  140. $('#gcmsPictureViewer .popup-ct').dragmove($('#gcmsPictureViewer'));
  141. var $box2 = $('#gcmsPictureViewer').on('mousedown', '#coorForGcmsPictureViewer', function(e) {
  142. var posix = {
  143. 'w': $box2.width(),
  144. 'h': $box2.height(),
  145. 'x': e.pageX,
  146. 'y': e.pageY
  147. };
  148. $.extend(document, {'move': true, 'call_down': function(e) {
  149. $box2.css({
  150. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  151. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  152. });
  153. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-75;
  154. $("#gcmsPictureViewer .modal-body").css({height:bodyHeight});
  155. $("#gcmsPictureViewerBox").iviewer('update');
  156. }});
  157. return false;
  158. });
  159. }
  160. /**
  161. * 界面布局重置
  162. * @type {Function}
  163. */
  164. function layoutResize(){
  165. $('#gcmsPictureViewer .modal-body').css({height:$(window).height()/2});
  166. }
  167. /**
  168. * 注册监听
  169. * @type {Function}
  170. */
  171. function subscribe(){
  172. ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  173. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  174. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  175. ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
  176. }
  177. /**
  178. * 取消监听
  179. * @type {Function}
  180. */
  181. function unSubscribe() {
  182. ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  183. }
  184. function GroupControl(type) {
  185. if (type == "show") {
  186. map23DControl.group({
  187. action: 'show',
  188. guid: modValue.mapPointGroup
  189. })
  190. map23DControl.group({
  191. action: 'show',
  192. guid: modValue.mapPointGroup
  193. })
  194. } else if (type == "hide") {
  195. map23DControl.group({
  196. action: 'hide',
  197. guid: modValue.mapPointGroup
  198. })
  199. map23DControl.group({
  200. action: 'hide',
  201. guid: modValue.mapPointGroup
  202. })
  203. }
  204. }
  205. /**
  206. * 模块移除
  207. * @return {[type]} [description]
  208. */
  209. function remove(){
  210. map23DControl.group({
  211. action: 'cleanAll',
  212. guid: modValue.mapPointGroup
  213. })
  214. map23DControl.group({
  215. action: 'remove',
  216. guid: modValue.mapPointGroup
  217. })
  218. $('#gcmsPictureViewer').remove();
  219. unSubscribe();
  220. modValue.iviewer = null;
  221. }
  222. return ONEMAP.M.gcmsPointAPicture = {
  223. init:init,
  224. remove:remove,
  225. setPictureModal:setPictureModal
  226. }
  227. });