legend.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. define(['html!templates/menu/legend',
  2. 'css!styles/menu/legend',
  3. 'css!styles/popupHtml'
  4. ], function(tpclayout) {
  5. var modValue = {
  6. pictureUrl:null,
  7. iviewer:null
  8. };
  9. var stutas = {
  10. initialized:false
  11. };
  12. function init(options){
  13. if(!stutas.initialized){
  14. setLayout();
  15. bindEvents();
  16. subscribe();
  17. }
  18. modValue.pictureUrl = options.pictureUrl;
  19. if(modValue.pictureUrl == "undefined"){
  20. ONEMAP.C.publisher.publish({type:'error',message:'暂无图例'},'noteBar::add');
  21. } else{
  22. updateView();
  23. }
  24. }
  25. function setLayout(){
  26. $(tpclayout).appendTo($("#wrapper"));
  27. };
  28. function updateView(){
  29. $("#tmaticLegendViewer").show();
  30. $('#tmaticLegendViewer .modal-body').css({height:$(window).height()/3*2});
  31. if (modValue.iviewer) {
  32. modValue.iviewer.iviewer('loadImage', modValue.pictureUrl);
  33. return false;
  34. } else {
  35. modValue.iviewer = $("#tmaticLegendViewerBox").iviewer({
  36. zoom_max: 200,
  37. zoom_min: 5,
  38. zoom: 100,
  39. src: modValue.pictureUrl,
  40. update_on_resize: true,
  41. });
  42. }
  43. }
  44. function bindEvents(){
  45. $("#tmaticLegendViewer .close").bind('click', function() {
  46. $("#tmaticLegendViewer").hide();
  47. })
  48. var $box2 = $('#tmaticLegendViewer').on('mousedown', '#coorForGcmsPictureViewer', function(e) {
  49. var posix = {
  50. 'w': $box2.width(),
  51. 'h': $box2.height(),
  52. 'x': e.pageX,
  53. 'y': e.pageY
  54. };
  55. $.extend(document, {
  56. 'move': true,
  57. 'call_down': function(e) {
  58. $box2.css({
  59. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  60. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  61. });
  62. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h) - 75;
  63. $("#tmaticLegendViewer .modal-body").css({ height: bodyHeight });
  64. $("#tmaticLegendViewerBox").iviewer('update');
  65. }
  66. });
  67. return false;
  68. });
  69. //拖拽
  70. $("#tmaticLegendViewer .popup-ct").dragmove($('#tmaticLegendViewer'));
  71. };
  72. function legendRemove(options){
  73. if(options.type == modValue.pictureUrl || options.type == 'allRemove'){
  74. $("#tmaticLegendViewer").remove();
  75. modValue.iviewer = null;
  76. }
  77. }
  78. function subscribe(){
  79. ONEMAP.C.publisher.subscribe(legendRemove,'legend:remove');
  80. }
  81. return ONEMAP.M.legend = {
  82. init:init
  83. }
  84. })