/** * @fileoverview 专题图 模块 * @author Song.Huang * @version 1.0.0 */ define([ 'html!templates/atlas/atlasList', 'modDir/service/regionSearch', 'css!styles/atlas/atlasList' ], function(tplLayout,regionSearchF) { /** * 模块数据 用于数据存储和外部调用 * @type {Object} * 数据存放 */ var modValue = { options : { page: 1, //页数 pageSize: 24, //每页条数 searchType: 'byPage', //搜索类型 searchKeyWord: '', //搜索关键字 searchId: 0, //搜索ID theme: null, //分类 region: '', //当前区域 0 全球 area: '' }, //查询数据集合 thematicDataResult:null, //专题图分类 thematicCategory:[], tuisonglist:[], } /** * 状态值 * @type {Boolean} * @default false * @private */ var status = { initialized:false, isFirstAdd:true, showInfoData:false, showSideBar:false, fStatu:false }; var overLayerOpacityControl; /** * 初始化容器 * @type {Function} */ function init(idx) { //未初始化,初始化布局 // status.fStatu = false; // if (idx == 0) { if (!status.initialized) { //设置容器布局 setLayout(); bindEvent(); //订阅推送 subscribe(); status.initialized = true; } if(idx == 1){ //获取专题图分类后,默认显示第一页列表 getCategory(function() { listThematicCategory(); showThematic({ page: 1, searchType: 'byPage' }); }); } if(idx == 101){ // 搜索那边点击了更多 $('#thematicSearchKey').val(ONEMAP.D.user.searchKeyWord) thematicSearchHandler({ keyWord: ONEMAP.D.user.searchKeyWord }); } if(idx == 102){ // 搜索那边过来的,不展开侧栏 $('#thematicSearchKey').val(ONEMAP.D.user.searchKeyWord) thematicSearchHandler({ keyWord: ONEMAP.D.user.searchKeyWord }); } else{ //开启侧栏 ONEMAP.C.publisher.publish('handShow','layout::sideBar'); status.showSideBar = true; } //设置zIndex 为最高 var zIndex = ONEMAP.M.sideBar.getZIndex(); $('#thematicPanel').css({zIndex:zIndex}); ONEMAP.D.currentSideBarMod = 'atlas'; }; /** * 初始化布局 */ function setLayout(){ $(tplLayout).appendTo($("#sideBarBody")); $("#atlasInfoDetail").appendTo('#wrapper'); // $('#thematicPanel .btn-atals-labrary').css({ // background:'url('+onemapUrlConfig.atlasLibraryUrl+'/images/layout/logo.png) top center' // }) layoutResize(); $(window).resize(function(event) { layoutResize(); }); $("#thematicResultsList").mCustomScrollbar({ scrollInertia: 1000 }); }; /** * 窗口布局重置 * @type {Function} */ function layoutResize() { $("#thematicResultsList").css({ height: $("#sideBar").height() - $('#thematicCategoryList').height() - 180 }); $("#thematicResultsList").mCustomScrollbar('update'); }; /** * 界面事件绑定 * @return {[type]} [description] */ function bindEvent(){ //region $('#currentRegionCheckbox').bind('click', function() { $('#currentAreaCheckbox').parent().removeClass('checked'); $('#currentAreaCheckbox').removeAttr('checked'); $('#thematicSearchKey').val('请输入名称'); if ($(this).parent().hasClass('checked')) { modValue.options.region = ''; modValue.options.page = 1; modValue.options.area = ''; modValue.options.searchKeyWord = ''; getPageResult(modValue.options); map2DViewer.map.off('zoomend moveend dragend', regionThematicSearch); ONEMAP.C.publisher.unSubscribe(regionThematicSearch, 'mapChange'); $(this).parent().removeClass('checked'); } else { map2DViewer.map.off('zoomend moveend dragend', areaThematicSearch); map2DViewer.map.on('zoomend moveend dragend', regionThematicSearch); ONEMAP.C.publisher.subscribe(regionThematicSearch, 'mapChange'); modValue.options.area = ''; modValue.options.searchKeyWord = ''; regionThematicSearch(); $(this).parent().addClass('checked'); } }); //bounds $('#currentAreaCheckbox').bind('click', function() { $('#currentRegionCheckbox').parent().removeClass('checked'); $('#currentRegionCheckbox').removeAttr('checked'); $('#thematicSearchKey').val('请输入名称'); if ($(this).parent().hasClass('checked')) { modValue.options.page = 1; modValue.options.area = ''; modValue.options.searchKeyWord = ''; getPageResult(modValue.options); map2DViewer.map.off('zoomend moveend dragend', areaThematicSearch); $(this).parent().removeClass('checked'); } else { modValue.options.region = ''; map2DViewer.map.off('zoomend moveend dragend', regionThematicSearch); map2DViewer.map.on('zoomend moveend dragend', areaThematicSearch); modValue.options.region = ''; modValue.options.searchKeyWord = ''; areaThematicSearch(); $(this).parent().addClass('checked'); } }); $('#thematicSearchKey').bind('focus', function() { if ($(this).val() == '请输入名称') { $(this).val(''); }; }); $('#thematicSearchKey').bind('focusout', function() { if ($(this).val() == '') { $(this).val('请输入名称'); $("#thematicCategoryList ul li.cur a").click(); }; }); //搜索回车搜索 $('#thematicSearchKey').bind('keydown', function(e) { var layerType = $("#thematicResultsList").attr("layerType"); if (e.keyCode === 13) { if ($('#thematicSearchKey').val() != '' && $('#thematicSearchKey').val() != '请输入名称') { if(ONEMAP.D.user.searchType == 1){ thematicSearchHandler({ keyWord: $('#thematicSearchKey').val() }); } else{ require(['modDir/atlas/atlasCategory'], function(atlasCategory) { ONEMAP.C.publisher.publish('handShow','layout::sideBar'); status.showSideBar = true; atlasCategory.init(layerType,"search"); }); ONEMAP.D.user.searchKeyWord = $('#thematicSearchKey').val(); } } } }); //按钮搜索 $('#thematicSearchSubmit').bind('click', function() { var layerType = $("#thematicResultsList").attr("layerType"); if ($('#thematicSearchKey').val() != '' && $('#thematicSearchKey').val() != '请输入名称') { if(ONEMAP.D.user.searchType == 1){ thematicSearchHandler({ keyWord: $('#thematicSearchKey').val() }); } else{ require(['modDir/atlas/atlasCategory'], function(atlasCategory) { ONEMAP.C.publisher.publish('handShow','layout::sideBar'); status.showSideBar = true; atlasCategory.init(layerType,"search"); }); ONEMAP.D.user.searchKeyWord = $('#thematicSearchKey').val(); } } }); //海量地图库 $('.btn-atals-labrary').bind('click',function(){ var windowOpen = window.open(); var openUrl = onemapUrlConfig.atlasLibraryUrl; if(!ONEMAP.D.user.guest){ openUrl; } windowOpen.location = openUrl; }) } /** * 显示指定参数的专题列表 * @type {Function} * @param options {Object} {} */ function showThematic(options) { ONEMAP.T.objExtend(modValue.options, options, true); getPageResult(modValue.options); }; /** * 专题图查询 * @param {[type]} options [description] * @return {[type]} [description] */ function thematicSearchHandler(options) { // $('#thematicCategoryList .cur').removeClass('cur'); // $('#thematicCategoryList li:eq(0)').addClass('cur'); $('#currentAreaCheckbox').removeAttr('checked'); $('#currentAreaCheckbox').parent().removeClass('checked'); $('#currentRegionCheckbox').removeAttr('checked'); $('#currentRegionCheckbox').parent().removeClass('checked'); map2DViewer.map.off('zoomend moveend dragend', areaThematicSearch); map2DViewer.map.off('zoomend moveend dragend', regionThematicSearch); modValue.options.searchKeyWord = options.keyWord; modValue.options.searchType = 'byKeyWord'; modValue.options.page = 1; // modValue.options.theme = null; modValue.options.area = ''; modValue.options.region = ''; getPageResult(modValue.options); }; /** * 搜索分类列表内容 * @return {[type]} [description] */ function listThematicCategory() { $('#thematicCategoryList ul').empty(); var allLi = $('
' + notText + '
').appendTo($("#thematicResultsList .item-list")); $("#thematicPage").hide(); }; function openNoCenterThematic(thematicData){ var openUrl = onemapUrlConfig.atlasLibraryUrl+'/atlasView.html?viewType=1'+ '&guid='+thematicData.guid+ '&serialize='+ONEMAP.C.encryption.enCode(JSON.stringify({ page: modValue.options.page, //页数 pageSize: modValue.options.pageSize, //每页条数 searchWord:'' })); window.open(openUrl); } /** * 更新侧栏 列表和分页 * @type {Function} * @private */ function createResultHtml() { //清除当前加载的专题图 //removeCurrentOverLayer(); if (modValue.thematicDataResult && modValue.thematicDataResult.map_list.length > 0) { if(ONEMAP.D.searchFirstResult == false){ $("#placePanel .thematic-content .thematic-title li:eq(0)").show().addClass("active").click(); ONEMAP.D.searchFirstResult = true; } //列表 var ul = $('单幅图暂无数据!
'); $("#thematicPage,#placePanel .thematic-content .thematic-title li:eq(0)").hide(); $("#placePanel .thematic-content .thematic-title li:eq(0)").removeClass("active"); // ONEMAP.D.searchFirstResult = false; } }; /** * 换页点击事件 */ function clickpage(op, allp) { if (op == 1) { $("#thematicPage .firstpage").css("background", "url(../images/layout/page_11.png) no-repeat 7px 11px") $("#thematicPage .uppage").css("background", "url(../images/layout/page_13.png) no-repeat 10px 11px") $("#thematicPage .nextpage").css("background", "url(../images/layout/page_06ch.png) no-repeat 10px 11px") $("#thematicPage .endpage").css("background", "url(../images/layout/page_08ch.png) no-repeat 7px 11px") } else if (op == allp) { $("#thematicPage .firstpage").css("background", "url(../images/layout/page_11ch.png) no-repeat 7px 11px") $("#thematicPage .uppage").css("background", "url(../images/layout/page_13ch.png) no-repeat 10px 11px") $("#thematicPage .nextpage").css("background", "url(../images/layout/page_06.png) no-repeat 10px 11px") $("#thematicPage .endpage").css("background", "url(../images/layout/page_08.png) no-repeat 7px 11px") } else { $("#thematicPage .firstpage").css("background", "url(../images/layout/page_11ch.png) no-repeat 7px 11px") $("#thematicPage .uppage").css("background", "url(../images/layout/page_13ch.png) no-repeat 10px 11px") $("#thematicPage .nextpage").css("background", "url(../images/layout/page_06ch.png) no-repeat 10px 11px") $("#thematicPage .endpage").css("background", "url(../images/layout/page_08ch.png) no-repeat 7px 11px") } modValue.options.page = parseInt(op); showThematic({ page: parseInt(op),searchType: 'byKeyWord'}); }; /** * 添加专题图层到地图层 * @type {Function} * @param obj {Object} 构造好了的专题图对象 * @private */ function addOverLayerToMap(data) { //添加到23D地图上 //如果是2D 添加透明度控件 modValue.currentOverLayerGuid = map23DControl.tileLayer({ action: 'add', layer: { url2D: onemapUrlConfig.thematicTileUrl + '/' + data.guid + '?l={z}&x={x}&y={y}', url3D: onemapUrlConfig.thematicTileUrl + '/' + data.guid + '?l={z}&x={x}&y={y}', //url3D: onemapUrlConfig.thematicTileFo3DUrl + '/' + data.guid + '?l={z}&x={x}&y={y}', minZoom: data['min_zoom'], maxZoom: data['max_zoom'], maxNativeZoom: data['max_zoom'], attribution: '', opacity: 1, imageType: 'png', name:data.name, guid:data.guid } }) ONEMAP.D.ThematicInMapData[modValue.currentOverLayerGuid] = { 'name':data.name, 'guid':data.guid }; if(status.showInfoData){ getShowInfo(data); } // overLayerOpacityControl = new L.Control.LayerOpacity( // map2DViewer.layers[modValue.currentOverLayerGuid], // { // thematic_data:data, // min_zoom:data['min_zoom'], // max_zoom:data['max_zoom'], // showFavBtn:true, // atlas:true, // favCallback:addFavThematic, // getShowInfoCallback:addThematicToMap, // closeCallback:removeCurrentOverLayer // } // ).addTo(map2DViewer.map); thematicControl( map2DViewer.layers[modValue.currentOverLayerGuid], { data:data, showFavBtn: false, showFavBtn:true, atlas:true, favCallback:addFavThematic, getShowInfoCallback:addThematicToMap, closeCallback:removeCurrentOverLayer }) ONEMAP.D.overLayerCount++; map2DViewer.map.setZoomScope(data['min_zoom'],data['max_zoom']); // map23DControl.setView({ // center: { // lat: data['center_lat'], // lng: data['center_lon'] // }, // zoom: data['zoom'] // }) if(typeof(data['max_zoom'])!="undefined"){ ONEMAP.M.myLayers.zoomActions("add",data['min_zoom'], data['max_zoom'],data['center_lat'],data['center_lon'],data['initial_zoom'],data.name); } else{ ONEMAP.M.myLayers.zoomActions("add",1, 19,map23DData.view.center['lat'],map23DData.view.center['lng'],data['initial_zoom'],data.name); } }; //添加三维专题图控制条 function thematicControl(layer,options){ modValue.thematicControlHtml = $("作者: '+data.author+'
').appendTo($('#atlasInfoDetail .cover-content')); $('创建时间: '+data.created_time+'
').appendTo($('#atlasInfoDetail .cover-content')); $('发布者: '+data.publisher+'
').appendTo($('#atlasInfoDetail .cover-content')); $('发布时间: '+data.publication_date+'
').appendTo($('#atlasInfoDetail .cover-content')); $('地图来源: '+data.original_atlas+'
').appendTo($('#atlasInfoDetail .cover-content')); $('最小缩放等级: '+data.min_zoom_level+'
').appendTo($('#atlasInfoDetail .cover-content')); $('最大缩放等级: '+data.max_zoom_level+'
').appendTo($('#atlasInfoDetail .cover-content')); //$('瓦片格式: '+data.image_format+'
').appendTo($('#atlasInfoDetail .content')); //$('瓦片质量: '+data.image_quality+'
').appendTo($('#atlasInfoDetail .content')); $('地图宽度: '+data.map_image_width+'像素
').appendTo($('#atlasInfoDetail .cover-content')); $('地图高度: '+data.map_image_height+'像素
').appendTo($('#atlasInfoDetail .cover-content')); if(data.coordinate_system == 0){data.coordinate_system = '无坐标图形'} $('坐标系: '+data.coordinate_system+'
').appendTo($('#atlasInfoDetail .cover-content')); } function addThematicToMap(data){ // console.log(data); if(!status.showInfoData){ status.showInfoData = true; getShowInfo(data); }else{ status.showInfoData = false; $('#atlasInfoDetail').hide(); } }; /** * 获取专题图分类 * @return {[type]} [description] */ function getCategory(callback_func) { var ajaxUrl = onemapUrlConfig.thematicDataUrl + '/map/theme'; ONEMAP.V.loading.load(); $.ajax({ url: ajaxUrl, type: 'GET', dataType: 'jsonp' }) .done(function(data) { // //console.log(data); ONEMAP.V.loading.loaded(); modValue.thematicCategory = data; callback_func(data); }) .fail(function() { ONEMAP.V.loading.loaded(); }); }; /** * 根据 options 参数获取 专题列表信息 * @param callback_func {Function} 回调方法 * @return {Object} */ function byDefault(callback_func) { var ajaxUrl = onemapUrlConfig.thematicDataUrl + '/map/list' + '?types=[1,2,4]&page=' + modValue.options.page + '&pagesize=' + modValue.options.pageSize + '®ion=' + modValue.options.region + '&area=' + modValue.options.area; if (modValue.options.theme != null && modValue.options.theme != 'undefined') { ajaxUrl += '&theme=' + modValue.options.theme; } var searchWord = $("#thematicSearchKey").val(); if (searchWord != null && searchWord != 'undefined' && searchWord != '' && searchWord != '请输入名称') { ajaxUrl += '&search=' + searchWord; } ONEMAP.V.loading.load(); $.ajax({ url: ajaxUrl, type: 'GET', dataType: 'jsonp' }) .done(function(data) { ONEMAP.V.loading.loaded(); callback_func(data); }) .fail(function() { ONEMAP.V.loading.loaded(); }); }; /** * 关键字查询 * @param keyword {String} 关键字 * @param callback_func {Function} 回调方法 * @return {Object} */ function byKeyWord(keyword, callback_func) { var ajaxUrl = onemapUrlConfig.thematicDataUrl + '/map/list' + '?types=[1,2,4]&page=' + modValue.options.page + '&pagesize=' + modValue.options.pageSize + '&search=' + encodeURIComponent(keyword) + '®ion=' + modValue.options.region + '&area=' + modValue.options.area; if (modValue.options.theme != null && modValue.options.theme != 'undefined') { ajaxUrl += '&theme=' + modValue.options.theme; } ONEMAP.V.loading.load(); $.ajax({ url: ajaxUrl, type: 'GET', dataType: 'jsonp' }) .done(function(data) { ONEMAP.V.loading.loaded(); callback_func(data); }) .fail(function() { ONEMAP.V.loading.loaded(); }); }; // 监听图层操作动作 function layerAction(options){ // console.log(options); if(options.action == "remove"){ // console.log("remove"); removeLayer(options.guid); } else if(options.action == "opacity"){ var opt = options.options.opacity; setOpacity(options.guid,opt); } else if(options.action == "up" || options.action == "down"){ ONEMAP.M.myLayerActions.changeFloor(); } } // 更改层级 function changeFloor(){ var li = $("#layerControlMenu .myLayers .mn-content li"); var layer = $("#mapHolder #map2DWrap .leaflet-layer"); var liLength = li.length; var zidArr = new Array(); for(var i=0;i