var deptMap;
|
var deptList;
|
var deptParent;
|
var deptParentId;
|
var map = new BMapGL.Map("container");
|
var timer;
|
var layer;
|
var showDeptFlag = true;
|
$(function () {
|
layui.use(['layer', 'laydate', 'form'], function () {
|
layer = layui.layer;
|
//旋转动画
|
// rotate();
|
});
|
});
|
|
|
//页面初始化后,查看是否有初始化仓库编码
|
window.onload = function () {
|
//初次定位到库区位置
|
if (dept) {
|
deptParent = dept;
|
//setTimeout('firstSetCenter()', 5000);
|
firstSetCenter();
|
}
|
};
|
|
|
//定位库区位置
|
function firstSetCenter() {
|
map.enableScrollWheelZoom(true);
|
//适应地图大小,设置地图中心点坐标及地图级别
|
map.centerAndZoom(new BMapGL.Point(dept.lon, dept.lat), 10);
|
|
setTimeout(function () {
|
map.setMapType(BMAP_NORMAL_MAP);
|
map.setMapStyleV2({
|
styleId: '2d7e9be25edbcb299c48ff8d14119eef'
|
});
|
$("#topdiv").css("display", "block");
|
currentSetCenter();
|
if (dept.type == "10") {
|
deptParentId = dept.id;
|
showChildDept();
|
getDeptChild()
|
}
|
}, 1000);
|
}
|
|
/**
|
* 将当前部门设为中心
|
*/
|
function currentSetCenter() {
|
map.centerAndZoom(new BMapGL.Point(deptParent.lon, deptParent.lat), 15);
|
}
|
|
/**
|
* 显示部门列表
|
*/
|
function showChildDept() {
|
if (showDeptFlag) {
|
$("#rightdiv").addClass("show");
|
showDeptFlag = false;
|
} else {
|
$("#rightdiv").removeClass("show");
|
showDeptFlag = true;
|
}
|
}
|
|
|
/**
|
* 渲染列表
|
* @param data
|
*/
|
function renderDept() {
|
//先清除之前的标记点
|
map.clearOverlays();
|
deptList = deptParent.children;
|
// console.log(deptList);
|
if (deptList) {
|
deptMap = {};
|
//右侧列表html
|
var html = "";
|
var myIcon;
|
var pt;
|
var pts = [];
|
var marker;
|
//把自己加进去一块标记出来
|
for(var i = 0; i < deptList.length; i ++){
|
!function(i){
|
var data1 = deptList[i];
|
if (data1.type == "10" || data1.type == "20") {
|
html += " <li onclick=\"setCenter(\'" + data1.id + "\');\">\n";
|
if (data1.type == "10") {
|
html += " <img src=\"../../static/images/gongsi.png\" >\n";
|
} else {
|
html += " <img src=\"../../static/images/cangku.png\" >\n";
|
}
|
html += " <div>\n" +
|
" <h4>" + (data1.name ? data1.name : "") + "</h4>\n" + (data1.address ? data1.address : "") + "</div>\n";
|
html += " </li>";
|
}
|
}(i);
|
}
|
|
//创建标记点
|
deptList.push(deptParent);
|
for(var i = 0; i < deptList.length; i ++){
|
!function(i){
|
var data2 = deptList[i];
|
if (data2.type == "10" || data2.type == "20") {
|
deptMap[data2.id] = data2;
|
if (data2.type == "10") {
|
myIcon = new BMapGL.Icon("../../static/images/zuobiao_blue.png", new BMapGL.Size(70, 70));
|
} else {
|
myIcon = new BMapGL.Icon("../../static/images/zuobiao_yellow.png", new BMapGL.Size(70, 70));
|
}
|
// 创建Marker标注,
|
pt = new BMapGL.Point(data2.lon, data2.lat);
|
pts.push(pt);
|
marker = new BMapGL.Marker(pt, {
|
icon: myIcon
|
});
|
// 将标注添加到地图
|
map.addOverlay(marker);
|
marker.addEventListener('click', function () {
|
openInfo(this, data2.id);
|
});
|
}
|
}(i);
|
}
|
|
$("#deptUl").html(html);
|
//将所有的点显示出来
|
var view = map.getViewport(eval(pts));
|
var mapZoom = view.zoom;
|
var centerPoint = view.center;
|
map.centerAndZoom(centerPoint, mapZoom);
|
} else {
|
layer.msg("没有下属部门信息!");
|
}
|
}
|
|
//点位点击事件
|
function openInfo(marker, deptId) {
|
var d = deptMap[deptId];
|
if (d) {
|
var sContent = "";
|
sContent += "<div style=\"margin:0;line-height:20px;padding:2px;\">联系人:" + (d.contact ? d.contact : "") + "<br/>联系电话:" + (d.phone ? d.phone : "") + "<br/>";
|
// sContent += "详细地址:" + (d.address?d.address:"") ;
|
// sContent +="<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>" ;
|
// sContent += d.desc ? d.desc:"";
|
// sContent += "</p>" ;
|
if (d.type == "20") {
|
sContent += "<button class=\"layui-btn layui-btn-primary layui-border-black\" onclick=\"openHome(\'" + d.id + "\');\">打开首页</button>"
|
}
|
|
sContent += "</div>";
|
|
var infoWindow = new BMapGL.InfoWindow(sContent, {
|
title: d.name, //标题
|
width: 200, //宽度
|
height: 120 //高度
|
|
});
|
marker.openInfoWindow(infoWindow);
|
} else {
|
console.log("没有从map中获取到部门")
|
}
|
|
}
|
|
/**
|
* 打开首页事件
|
*/
|
function openHome(deptId) {
|
//首先主动更换当前人临时部门
|
layer.msg("开始验证部门……");
|
|
$.ajax({
|
type: "GET",
|
cache: false,
|
url: "../../basic/common/change-deptId?deptId=" + deptId + "&userId=" + userId,
|
dataType: "json",
|
contentType: "application/json;charset=UTF-8",
|
success: function (result) {
|
if(model == "all"){
|
window.open("../../index?g=1", "_parent");
|
}else {
|
window.open("../../home?t=" + model + "&g=1", "_parent");
|
}
|
},
|
error: function (result) {
|
if("SUCCESS" == result.responseText){
|
if(model == "all"){
|
window.open("../../index?g=1", "_parent");
|
}else {
|
window.open("../../home?t=" + model + "&g=1", "_parent");
|
}
|
}else{
|
layer.alert("系统验证当前用户所在部门异常,请联系管理员!");
|
}
|
}
|
});
|
}
|
|
/**
|
* 渲染按钮
|
* @param data
|
*/
|
function renderBtnBack() {
|
//console.log(deptParent);
|
var html = "";
|
if (deptParent.id == dept.id) {
|
html += " <img src=\"../../static/images/fanhui.png\" style=\"width: 24px !important;padding-top: 10px !important;transform: rotateY(180deg)\">\n" +
|
"<div> <h4 onclick='currentSetCenter();'>当前下属分支</h4> </div>\n";
|
} else {
|
html += " <img src=\"../../static/images/fanhui.png\" style=\"width: 24px !important;padding-top: 10px !important;\">\n" +
|
" <div> <h4 onclick='backParent();'>返回上级</h4> </div>";
|
}
|
$("#btBack").html(html)
|
}
|
|
/**
|
* 返回上层
|
*/
|
function backParent() {
|
var nowTime = new Date().getTime();
|
var clickTime = $(this).attr("ctime");
|
if (clickTime != 'undefined' && (nowTime - clickTime < 3000)) {
|
alert('操作过于频繁,稍后再试');
|
return false;
|
} else {
|
$(this).attr("ctime", nowTime);
|
getDeptparent();
|
}
|
}
|
|
/**
|
* 仓库点击事件
|
* @param deptId
|
*/
|
function setCenter(deptId) {
|
// console.log(deptId);
|
|
// console.log(deptMap);
|
|
var d = deptMap[deptId];
|
console.log(d);
|
if (d) {
|
if (d.type == 10) {
|
//是公司还需要加载子部门数据并且渲染
|
deptParentId = d.id;
|
getDeptChild();
|
} else {
|
map.centerAndZoom(new BMapGL.Point(d.lon, d.lat), 15);
|
}
|
} else {
|
console.log("没有从map中获取到部门")
|
}
|
}
|
|
/**
|
* 获取数据
|
*/
|
function getDeptChild() {
|
$.ajax({
|
type: "POST",
|
url: "../../basic/gis/dept-child",
|
dataType: "json",
|
contentType: "application/json;charset=UTF-8",
|
data: JSON.stringify({
|
"deptId": deptParentId
|
}),
|
success: function (result) {
|
console.log(result);
|
if (result.code != "0000") {
|
layer.msg(result.msg);
|
} else {
|
deptParent = result.data;
|
deptParentId = result.data.id;
|
renderBtnBack();
|
renderDept();
|
//currentSetCenter();
|
}
|
},
|
error: function () {
|
layer.msg("获取信息失败!");
|
}
|
});
|
}
|
|
/**
|
* 获取数据
|
*/
|
function getDeptparent() {
|
|
$.ajax({
|
type: "POST",
|
url: "../../basic/gis/back-parent",
|
dataType: "json",
|
contentType: "application/json;charset=UTF-8",
|
data: JSON.stringify({
|
"deptId": deptParentId
|
}),
|
success: function (result) {
|
console.log(result);
|
if (result.code != "0000") {
|
layer.msg(result.msg);
|
} else {
|
deptParent = result.data;
|
deptParentId = result.data.id;
|
renderBtnBack();
|
renderDept();
|
//currentSetCenter();
|
}
|
},
|
error: function () {
|
layer.msg("获取信息失败!");
|
}
|
});
|
}
|
|
|
/**
|
* 初始动画
|
*/
|
function rotate() {
|
//开启鼠标滚轮缩放
|
map.enableScrollWheelZoom(true);
|
|
//开启地球模式
|
map.setMapType(BMAP_EARTH_MAP);
|
|
// 初始化地图,设置动画起始点坐标和地图级别
|
map.centerAndZoom(new BMapGL.Point(214.406, 40.000), 5);
|
|
//旋转动画开始
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(204.406, 40.000));
|
}, 2000);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(194.406, 40.000)); //旋转动画
|
}, 2250);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(184.406, 40.000)); //旋转动画
|
}, 2500);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(174.406, 40.000)); //旋转动画
|
}, 2775);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(164.406, 40.000)); //旋转动画
|
}, 3000);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(154.406, 40.000)); //旋转动画
|
}, 3250);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(144.406, 40.000)); //旋转动画
|
}, 3500);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(134.406, 40.000)); //旋转动画
|
}, 3750);
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(124.406, 40.000)); //旋转动画
|
}, 4000);
|
//旋转动画结束
|
setTimeout(function () {
|
map.panTo(new BMapGL.Point(114.403, 40.000));
|
}, 4250);
|
}
|
|
//格式化时间
|
function dateFormatStr(time) {
|
if (time) {
|
var d = new Date(time);
|
return dateFtt("yyyy-MM-dd hh:mm:ss", d);
|
}
|
return "";
|
}
|