define(['html!templates/menu/legend', 'css!styles/menu/legend', 'css!styles/popupHtml' ], function(tpclayout) { var modValue = { pictureUrl:null, iviewer:null }; var stutas = { initialized:false }; function init(options){ if(!stutas.initialized){ setLayout(); bindEvents(); subscribe(); } modValue.pictureUrl = options.pictureUrl; if(modValue.pictureUrl == "undefined"){ ONEMAP.C.publisher.publish({type:'error',message:'暂无图例'},'noteBar::add'); } else{ updateView(); } } function setLayout(){ $(tpclayout).appendTo($("#wrapper")); }; function updateView(){ $("#tmaticLegendViewer").show(); $('#tmaticLegendViewer .modal-body').css({height:$(window).height()/3*2}); if (modValue.iviewer) { modValue.iviewer.iviewer('loadImage', modValue.pictureUrl); return false; } else { modValue.iviewer = $("#tmaticLegendViewerBox").iviewer({ zoom_max: 200, zoom_min: 5, zoom: 100, src: modValue.pictureUrl, update_on_resize: true, }); } } function bindEvents(){ $("#tmaticLegendViewer .close").bind('click', function() { $("#tmaticLegendViewer").hide(); }) var $box2 = $('#tmaticLegendViewer').on('mousedown', '#coorForGcmsPictureViewer', function(e) { var posix = { 'w': $box2.width(), 'h': $box2.height(), 'x': e.pageX, 'y': e.pageY }; $.extend(document, { 'move': true, 'call_down': function(e) { $box2.css({ 'width': Math.max(30, e.pageX - posix.x + posix.w), 'height': Math.max(30, e.pageY - posix.y + posix.h) }); var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h) - 75; $("#tmaticLegendViewer .modal-body").css({ height: bodyHeight }); $("#tmaticLegendViewerBox").iviewer('update'); } }); return false; }); //拖拽 $("#tmaticLegendViewer .popup-ct").dragmove($('#tmaticLegendViewer')); }; function legendRemove(options){ if(options.type == modValue.pictureUrl || options.type == 'allRemove'){ $("#tmaticLegendViewer").remove(); modValue.iviewer = null; } } function subscribe(){ ONEMAP.C.publisher.subscribe(legendRemove,'legend:remove'); } return ONEMAP.M.legend = { init:init } })