/** * [ATLAS.M.atlasView] * @return {[object]} */ define(['html!templates/atlas/atlasView', 'css!styles/atlas/atlasView'], function(tplLayout){ /** * 模块数据 用于数据存储和外部调用 * @type {Object} */ var modValue = { options:{} } /** * 模块界面样式 例如:宽,高 * @type {Object} */ var styles = {} /** * 模块状态,用于存储模块的状态 例如:收起,关闭 * @type {Object} */ var status = {} /** * 初始化并订阅事件 * @return {[type]} [description] */ function init(){ //获取url参数 modValue.options = JSON.parse(ATLAS.C.encryption.deCode(ATLAS.T.getQueryString('serialize'))); modValue.options.type = parseInt(ATLAS.T.getQueryString('viewType')); if(modValue.options.type == 1){ modValue.options.guid = ATLAS.T.getQueryString('guid'); $('body').addClass('singleAtlas'); } if(modValue.options.type == 2){ modValue.options.leftGuid = ATLAS.T.getQueryString('left'); modValue.options.rightGuid = ATLAS.T.getQueryString('right'); $('body').addClass('compareAtlas'); } if(modValue.options.type == 3 || modValue.options.type == 4){ modValue.options.productionId = ATLAS.T.getQueryString('productionId'); $('body').addClass('atlasBook'); } setLayout(); bindEvent(); switch(modValue.options.type){ case 1: require(['modDir/atlas/singleAtlas'], function (singleAtlas) { singleAtlas.init(modValue.options); }); break; case 2: require(['modDir/atlas/compareView'], function (compareView) { compareView.init(modValue.options); }); break; case 3: case 4: require(['modDir/atlas/atlasBook'], function (atlasBook) { atlasBook.init(modValue.options); }); break; } } /** * 设置界面 */ function setLayout(){ $('#contentWrap').append(tplLayout); layoutResize(); $(window).resize(function() { layoutResize(); }); $(".category-list").mCustomScrollbar({ }); $(".info-list").mCustomScrollbar({ }); $("#atlasInfoDetailAll .contentWrap").mCustomScrollbar({ }); $('#atlasList .content').mCustomScrollbar({ horizontalScroll:true }); } /** * 界面事件绑定 * @return {[type]} [description] */ function bindEvent(){ $('#atlasInfo .header .abtn-up').bind('click',function(){ if($(this).hasClass('abtn-down')){ $(this).removeClass('abtn-down'); $(this).parent().next().show(); }else { $(this).addClass('abtn-down'); $(this).parent().next().hide(); } $(".info-list").mCustomScrollbar('update'); }); $('#atlasInfoDetail .abtn-more').bind('click',function(){ $('#atlasInfoDetailAll').show(); }) $('#atlasInfoDetailAll .abtn-close').bind('click',function(){ $('#atlasInfoDetailAll').hide(); }) $('.abtn-min-atlas-category').bind('click',function(){ if($(this).hasClass('min')){ $(this).removeClass('min'); $('#contentWrap').removeClass('hide-category'); }else { $(this).addClass('min'); $('#contentWrap').addClass('hide-category'); } ATLAS.C.publisher.publish({},'atlasView::layoutResize'); }) $('.abtn-min-atlas-info').bind('click',function(){ if($(this).hasClass('min')){ $(this).removeClass('min'); $('#contentWrap').removeClass('hide-info'); }else { $(this).addClass('min'); $('#contentWrap').addClass('hide-info'); } ATLAS.C.publisher.publish({},'atlasView::layoutResize'); }) $('.abtn-min-atlas-list').bind('click',function(){ if($(this).hasClass('min')){ $(this).removeClass('min'); $('#contentWrap').removeClass('hide-list'); }else { $(this).addClass('min'); $('#contentWrap').addClass('hide-list'); } ATLAS.C.publisher.publish({},'atlasView::layoutResize'); }) } /** * 界面重置 * @return {[type]} [description] */ function layoutResize(){ $('.category-list').css({height:$('#atlasCategory').height()-100}); } /** * 获取地图集目录数据 * @type {Function} * @private */ function getAtlasCatalogData(aid){ if(_this.options.type === 4){ var ajaxUrl = atlasUrlConfig.catalogServerUrl+'/production/modValue.options.type?production_id='+aid; }else { var ajaxUrl = atlasUrlConfig.catalogServerUrl+'/production/product_category?production_id='+aid; } ATLAS.V.loading.load(); $.ajax({ type:"get", dataType:'jsonp', url:ajaxUrl, success:function(data){ ATLAS.V.loading.loaded(); modValue.atlasCatalogData = data; setSideBarCatalog(); }, error:function(data){ ATLAS.V.loading.loaded(); ATLAS.C.publisher.publish({type:'error',message:'获取地图集目录数据失败!'},'noteBar::add'); } }); } /** * 设置图集目录 */ function setSideBarCatalog(){ $('#thematicCategory dl').empty(); var dtCount = 1; var liCount = 1; var first = true; for(var item in modValue.atlasCatalogData.category){ var cItem =modValue.atlasCatalogData.category[item]; if(modValue.options.type === 4){ var itemDt = $('
'+cItem.name+'
'); }else { var itemDt = $('
'+dtCount+'.'+cItem.name+'
'); } $('#thematicCategory dl').append(itemDt); var itemDd = $('
'); $('#thematicCategory dl').append(itemDd); var itemDdUl = $(''); itemDd.append(itemDdUl); for(var i= 0,l=cItem.list.length; i'+ ''+ dtCount+'.'+liCount+'-'+mItem.name+''); //AJAX获取专题图数据,添加专题图到地图容器 modValue.getThematicData(mItem.guid); first = false; }else { var mItemLi = $('
  • '+ ''+ dtCount+'.'+liCount+'-'+mItem.name+'
  • '); } mItemLi.find('a').bind('click',{da:mItem},function(e){ $('#thematicCategory dd ul li .select').removeClass('select'); $(this).addClass('select'); //ie6 hack e.preventDefault(); //AJAX获取专题图数据,添加专题图到地图容器 modValue.getThematicData(e.data.da.guid); }); mItemLi.appendTo(itemDdUl); liCount++; } dtCount++; liCount = 1; } $('#thematicCategory dt:first').addClass('select'); $('#thematicCategory dd:first').css({display:"block"}).addClass('open'); $('#thematicCategory dt').bind('click',function(){ if($(this).hasClass('select')){ $(this).removeClass('select'); $(this).next().removeClass('open').css({display:"none"}); }else { $(this).addClass('select'); $(this).next().css({display:"block"}).addClass('open').css({height:'auto'}); } }) } /** * AJAX获取相应GUID的专题图数据 * @type {Function} * @param guid {Number} guid * @private */ function getThematicData(guid){ var ajaxUrl = atlasUrlConfig.thematicDataServerUrl+'/production/metadata?production_id='+guid; ATLAS.V.loading.load(); $.ajax({ type:"get", dataType:'jsonp', url:ajaxUrl, success:function(data){ ATLAS.V.loading.loaded(); modValue.currentThematicData = data.metadata; //添加专题图到地图容器中 addThematicToMap(); }, error:function(data){ ATLAS.V.loading.loaded(); ATLAS.C.publisher.publish({type:'error',message:'获取地图数据失败!'},'noteBar::add'); } }); } /** * 添加专题图到地图上 */ function addThematicToMap(){ } /** * 注册订阅 * @type {Function} * 推送:ATLAS.C.publisher.publish(options,'atlasView::type'); * 订阅:ATLAS.C.publisher.subscribe(layoutResize,'sideBarLayoutChange'); */ function subscribe(){} /** * 取消订阅 * @type {Function} * 取消订阅:ATLAS.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange'); */ function unSubscribe(){} /** * 模块移除 * @return {[type]} [description] */ function remove(){ //取消订阅 //unSubscribe(); } return ATLAS.M.atlasView = { init:init, layoutResize:layoutResize } });