var colors = {}; var map; var disProvince;//行政区颜色渲染 var deptAreasMap = {}; var allDeptMap = {}; var markers = [];//点标记 var type = "0"; var county = "all"; //var switch2AreaNode2; $(function () { if (deptAreas) { for (var i = 0; i < deptAreas.length; i++) { deptAreasMap[deptAreas[i].id] = deptAreas[i]; } } if (allDept) { for (var i = 0; i < allDept.length; i++) { allDeptMap[allDept[i].id] = allDept[i]; } } //初始化时间 //initTime(); //初始化地图 initMap(); //左侧图表 /* pieChartLoad( [ {value: "0.000", name: '稻谷'}, {value: "0.000", name: '玉米'}, {value: "0.000", name: '小麦'} ], 'breedChart' );*/ //渲染部门 //renderDepts(); //大屏标语 //initDicSlogan(); //renderAreas(610000); setTimeout(function () { renderAreas(610000); }, 2000); }); // 刷新时间 function initTime() { setInterval(function () { $("#navBarDate").html(formatDate('mm月dd日', new Date())); $("#navBarTime").html(formatDate('HH:MM:SS', new Date())); $("#navBarWeek").html(getWeekDate()); }, 1000); } function initMap() { map = new AMap.Map('map_container', { center: [108.953544, 34.265892], zoom: 6.6, mapStyle: 'amap://styles/41f8248740d3659ddc65dc363078592c', // rotateEnable:true, // pitchEnable:true, // pitch: 0, // rotation: 0, resizeEnable: true //viewMode:'3D', //开启3D视图,默认为关闭 }); new AMap.DistrictSearch({ extensions: 'all', subdistrict: 0 }).search('陕西省', function (status, result) { // 外多边形坐标数组和内多边形坐标数组 var outer = [ new AMap.LngLat(-360, 90, true), new AMap.LngLat(-360, -90, true), new AMap.LngLat(360, -90, true), new AMap.LngLat(360, 90, true), ]; var holes = result.districtList[0].boundaries var pathArray = [ outer ]; pathArray.push.apply(pathArray, holes) var polygon = new AMap.Polygon({ pathL: pathArray, strokeColor: '#71B3ff',//#00eeff strokeWeight: 1, fillColor: '#000000',//#71B3ff fillOpacity: 0.4 }); polygon.setPath(pathArray); map.add(polygon); }) //console.log(colors); //------------------------------------------------------------------------------------------------------------------------- //默认行政区域编码 //renderColor(defaultAreaCode); } //socket信息返回處理 function socketOnMessage(pocket) { if (pocket.userId == "slogan") { var data = pocket.data; dicSlogan = data; initDicSlogan(); } } /** * 初始标语数据 */ function initDicSlogan() { if (dicSlogan) { if (dicSlogan.color == "red") { $("#sloganText").css({ color: "#DE2910" }); } else { $("#sloganText").css({ color: "#7ddfff" }); } $("#sloganText").text(dicSlogan.content); } } /** * 根据区县获取库区 */ function getDeptArea(city, county) { var list = []; if (deptAreas) { for (var i = 0; i < deptAreas.length; i++) { if (city == deptAreas[i].deptCity) { list.push(deptAreas[i]); } if (county == deptAreas[i].deptCounty) { list.push(deptAreas[i]); } } } return list; } /** * 用户点击城市或者县级区级渲染库区点位 */ function renderAreas(deptId) { var d = allDeptMap[deptId]; if (d) { closeInfoWindow(); removeColor(); delMarker(); //map.setCity(deptId); renderColor(deptId); var a = []; if ("10" == d.type) { a = getDeptArea(deptId, "") } if ("11" == d.type) { a = getDeptArea("", deptId) } if (a && a.length > 0) { for (var i = 0; i < a.length; i++) { addMarker(a[i], false); } } //刷新数据 county = deptId; ajaxFoodNum(); } else { console.log("没有获取到该行政区划:" + deptId); } //陕西 } /** * 渲染库区信息弹窗 * @param deptAreaId */ function showAreaInfo(deptAreaId) { var d = deptAreasMap[deptAreaId]; if (d) { closeInfoWindow(); removeColor(); delMarker(); //map.setCity(d.deptCounty); // map.setZoom(10); renderColor(d.deptCounty); addMarker(d, true); } else { console.log("没有获取到该库区:" + deptAreaId); } } /** * 渲染库区列表 */ function renderDepts() { if (depts) { var html = ""; var childs = []; var areas = []; for (var i = 0; i < depts.length; i++) { html += "
" + "
" + ""; if (depts[i].children && depts[i].children.length > 0) { childs = depts[i].children; for (var j = 0; j < childs.length; j++) { html += ""; } } else { //没有子节点,直接就是区级别 areas = getDeptArea("", depts[i].id); if (areas && areas.length > 0) { for (var k = 0; k < areas.length; k++) { html += ""; } } } html += "
" + "
"; } $("#menuDiv").html(html); } } /** * 获取地图行政区域颜色 * @param adcode * @returns {*} */ function getColorByAdcode(adcode) { if (!colors[adcode]) { var gb = Math.random() * 155 + 50; colors[adcode] = 'rgb(' + gb + ',' + gb + ',255)'; } return colors[adcode]; }; /** * *增加库区点位 * tag 是否直接显示信息弹窗 */ function addMarker(deptArea, tag) { if (deptArea) { var markerContent = "
" + // "

天府新区

" + " " + "
"; var position = [deptArea.lon, deptArea.lat]; var marker = new AMap.Marker({ position: position, // 将 html 传给 content content: markerContent, // 以 icon 的 [center bottom] 为原点 // achor:'center', offset: new AMap.Pixel(-25, -25) }); markers.push(marker); // 将 markers 添加到地图 map.add(marker); var infoWinodw = new AMap.InfoWindow({ isCustom: true, //使用自定义窗体 content: createInfoWindow(deptArea), achor: 'bottom-center', offset: new AMap.Pixel(0, 0) }); //鼠标点击marker弹出自定义的信息窗体 marker.on('click', function () { infoWinodw.open(map, marker.getPosition()); }); if (tag) { infoWinodw.open(map, marker.getPosition()); } } else { console.log("库区为空"); } } /** * *删除库区点位 */ function delMarker() { if (map) { map.remove(markers); } } //关闭信息窗体 function closeInfoWindow() { if (map) { map.clearInfoWindow(); } } /** * 创建信息窗口 */ function createInfoWindow(deptArea) { var deptAreaId = deptArea.id; var content = "
" + "
" + "
" + "
" + "
" + "
" + "
×
" + "
" + "
" + "
×
" + "
" + "
" + "
" + "
" + "
" + '
' + '
'+ '
'; if (deptArea.name.length>17) { content += '

' + (deptArea.name ? deptArea.name : "没有获取到库区信息") + '

' ; }else{ content += '

' + (deptArea.name ? deptArea.name : "没有获取到库区信息") + '

' ; } content += '
'+ '
' + '' + '
'+ '
'+ '

' + (deptArea.address ? deptArea.address + "(" + deptArea.lon + "," + deptArea.lat + ")" : "没有获取到库区信息") + '

' + '
' + '
' + '

粮仓个数(个)

' + '

' + (deptArea.depotNum ? deptArea.depotNum : 0) + '

' + '
' + '
' + '

油罐个数(个)

' + '

' + (deptArea.depotOilNum ? deptArea.depotOilNum : 0) + '

' + '
' + '
' + '
    ' + '
  • '; if (deptArea.storage && (deptArea.storage + "").length > 4) { content += '

    ' + (deptArea.storage ? deptArea.storage.toFixed(3) : 0) + '

    '; } else { content += '

    ' + (deptArea.storage ? deptArea.storage.toFixed(3) : 0) + '

    '; } content += '

    粮食储量(吨)

    '+ '
  • ' + '
  • '; if (deptArea.storage && (deptArea.oilStorage + "").length > 4) { content += '

    ' + (deptArea.oilStorage ? deptArea.oilStorage.toFixed(3) : 0) + '

    '; } else { content += '

    ' + (deptArea.oilStorage ? deptArea.oilStorage.toFixed(3) : 0) + '

    '; } content += '

    植物油储量(吨)

    ' + '
  • ' + '
  • ' + '

    ' + (deptArea.area ? deptArea.area : 0) + '

    ' + '

    占地面积(㎡)

    ' + '
  • ' + '
' + '' + '
' + "
" + "
"; return content; } /** * 调用父节点方法执行,默认退出全屏并进入后台 * @param id */ function toHomeDetail(id) { var url = "../home?t=grain&deptAreaId=" + id; window.parent.open(url, "_self"); }; /** * 根据行政编码渲染颜色,市级会将下面所有区渲染,区级只渲染当前区 * @param adcode */ function renderColor(adcode) { // disProvince = new AMap.DistrictLayer.Province({ // zIndex: 12, // adcode: adcode, // depth: 2, // opacity: 0.6, // styles: { // 'fill': function (properties) { // var adcode = properties.adcode; // return getColorByAdcode(adcode); // }, // 'province-stroke': 'cornflowerblue', // 'city-stroke': 'white',//中国地级市边界 // 'county-stroke': 'rgba(255,255,255,0.5)'//中国区县边界 // } // }); // disProvince.setMap(map); //window.switch2AreaNode2(adcode); switch2AreaNode(adcode); } function removeColor() { // if (disProvince) { // disProvince.setMap(null); // } } /** * 格式化日期 * @param fmt * @param date * @return {*} */ function formatDate(fmt, date) { var ret; const opt = { "Y+": date.getFullYear().toString(), // 年 "m+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "H+": date.getHours().toString(), // 时 "M+": date.getMinutes().toString(), // 分 "S+": date.getSeconds().toString() // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (var k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) } } return fmt; } /** *获取当前星期几 */ function getWeekDate() { var now = new Date(); var day = now.getDay(); var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); var week = weeks[day]; return week; } /** * 格式化日期 * @param fmt * @param date * @return {*} */ function formatDate(fmt, date) { var ret; const opt = { "Y+": date.getFullYear().toString(), // 年 "m+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "H+": date.getHours().toString(), // 时 "M+": date.getMinutes().toString(), // 分 "S+": date.getSeconds().toString() // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (let k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) } } return fmt; } /** *获取当前星期几 */ function getWeekDate() { var now = new Date(); var day = now.getDay(); var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); var week = weeks[day]; return week; } var navBarDateDom = document.getElementById('navBarDate'); var navBarTimeDom = document.getElementById('navBarTime'); var navBarWeekDom = document.getElementById('navBarWeek'); /*刷新时间*/ setInterval(function () { navBarDateDom.innerHTML = formatDate('mm月dd日', new Date()); navBarTimeDom.innerHTML = formatDate('HH:MM:SS', new Date()); navBarWeekDom.innerHTML = getWeekDate(); }, 1000) $(function () { $('.m-nav .tit').click(function () { $(this).siblings('.sub').stop().slideToggle(); }); $('.c-left .close').on('click', function () { $('.c-left').addClass('hidden') }); $('.c-left .o-btn').on('click', function () { $('.c-left').removeClass('hidden') }); $('.c-right .close').on('click', function () { $('.c-right').addClass('hidden') }); $('.c-right .o-btn').on('click', function () { $('.c-right').removeClass('hidden') }); });