layerController.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * [ONEMAP.M.menu]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/layerController',
  7. 'css!styles/menu',
  8. ], function(layerController,tplLayout,modelFly) {
  9. function init() {
  10. setLayout();
  11. bindEvent();
  12. subscribe();
  13. };
  14. function setLayout() {
  15. var top = $(window).height() - 140;
  16. $("#layerControlMenu").css({
  17. top:top
  18. })
  19. $(layerController).appendTo($("#layerControlMenu .cover-content"));
  20. $("#layerControlMenu .myLayers .scroll-bar").mCustomScrollbar({
  21. scrollInertia: 500
  22. });
  23. $('#layerControlMenu .im-m').dragmove($('#layerControlMenu'));
  24. }
  25. /**
  26. * 窗口布局重置
  27. * @type {Function}
  28. */
  29. function layoutResize(options) {
  30. $("#layerControlMenu .myLayers .scroll-bar").mCustomScrollbar('update');
  31. };
  32. function bindEvent() {
  33. $(".layerListSwitch").bind('click',function(){
  34. var mylayer = $(this).parent().parent();
  35. if(mylayer.hasClass('active')){
  36. mylayer.removeClass("active");
  37. $("#layerControlMenu").css("width",202+"px");
  38. }
  39. else{
  40. mylayer.addClass("active");
  41. $("#layerControlMenu").css("width",230+"px");
  42. }
  43. })
  44. }
  45. // 检查我的图层是否为空
  46. function checkLayerNull(){
  47. // 我的图层暂无数据时
  48. if(typeof($("#layerControlMenu .myLayers .mn-content li").eq(0).html()) == "undefined"){
  49. $("#layerControlMenu .mn-content p.tip-none").show();
  50. $("#layerControlMenu").removeClass("bl");
  51. }
  52. else{
  53. $("#layerControlMenu .mn-content p.tip-none").hide();
  54. if(!$("#layerControlMenu").hasClass("bl")){
  55. $("#layerControlMenu").addClass("bl");
  56. }
  57. }
  58. }
  59. // 全屏
  60. function fullMap(option){
  61. if(option){
  62. var layer = $("#layerControlMenu");
  63. layer.removeClass("bl");
  64. }else{
  65. ONEMAP.M.layerControlMenu.checkLayerNull();
  66. }
  67. }
  68. /**
  69. * 注册订阅
  70. * @type {Function}
  71. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  72. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  73. */
  74. function subscribe() {
  75. ONEMAP.C.publisher.subscribe(fullMap, 'layout::fullMap');
  76. ONEMAP.C.publisher.subscribe(layoutResize, 'menuListClick');
  77. }
  78. return ONEMAP.M.layerControlMenu = {
  79. init: init,
  80. status:status,
  81. checkLayerNull:checkLayerNull
  82. };
  83. })