import { TUMap } from 'tumap';
|
import building from './building';
|
import major from './major';
|
import setting from './setting';
|
|
let map = null;
|
|
let timer = null;
|
|
let lastOUt = null;
|
|
let lastType = null;
|
|
let LY = { type: "build", name: null, id: null };
|
|
let MJ = { type: "major", index: null, flag: null };
|
|
// 初始化
|
export function init (id, callback) {
|
map = new TUMap({
|
id: id,
|
url: setting.isLocal ? setting.localUrl : setting.serveUrl,
|
onInit: function () {
|
inited();
|
if (callback) callback(map);
|
}
|
});
|
}
|
|
// 初始化完成
|
export function inited () {
|
//setTime();
|
map.setTime(1200); // 1200,noon-中午
|
// setTimeout(() => {
|
// setTime();
|
// }, 15 * 60 * 1000);
|
map.setWeather('sun'); // 晴天
|
map.execute('grapi', 'RoamingEnd', { time: 0 }, function (e) { console.log("grapi.RoamingEnd ->", e); }); // 停止漫游
|
|
window.setTimeout(function () {
|
setView(setting.defaultView); // 起始位置
|
}, 2500);
|
|
map.clearAllCovering(); // 清除poi+label
|
building.init(map)
|
major.init(map);
|
addEvent();
|
}
|
|
function setTime () {
|
let d = new Date();
|
let h = d.getHours();
|
let m = d.getMinutes();
|
let time = parseInt(h + "" + (m > 9 ? "" : "0") + m);
|
|
console.log("map.setTime =>", time);
|
map.setTime(time); // 1200,noon-中午
|
}
|
|
// 添加事件
|
export function addEvent () {
|
addInEvent(window.dataPool.dataPool);
|
addOutEvent(window.dataPool.dataPool);
|
}
|
|
// 添加输入事件
|
function addInEvent (DP) {
|
timer = setInterval(() => { // 监听 dataPoll 事件
|
if (!DP.UE_IN) return;
|
|
let ue = typeof DP.UE_IN === "string" ? JSON.parse(DP.UE_IN) : DP.UE_IN;
|
if (!ue || !(LY.type === ue.type || MJ.type === ue.type)) return;
|
|
do {
|
if (lastType !== ue.type) {
|
map.clearAllCovering();
|
lastType = ue.type;
|
}
|
|
if (LY.type === ue.type) { // "build"
|
if (ue.name === LY.name && ue.id === LY.id) break;
|
|
console.log('接受UE_IN消息 =>', ue);
|
LY.id = ue.id;
|
if (ue.name === LY.name) {
|
building.locateLY(LY.id);
|
} else {
|
LY.name = ue.name;
|
building.queryLY(LY.name, LY.id);
|
}
|
break;
|
}
|
|
if (MJ.type === ue.type) { // "major"
|
if (ue.index === MJ.index && ue.flag === MJ.flag) break;
|
|
console.log('接受UE_IN消息 =>', ue);
|
MJ.index = ue.index;
|
MJ.flag = ue.flag;
|
major.queryMajor(MJ.index, MJ.flag);
|
break;
|
}
|
} while (false);
|
//DP.UE_IN = null;
|
}, 1000);
|
}
|
|
// 添加输出事件
|
function addOutEvent (DP) {
|
map.pickPosition(function (e) { // 点击事件
|
if (!e || e.category !== 'billboard' || e.clickType !== 1 || building.IsLoaded()) return;
|
|
if (e.name === "MJ") { // 重大项目
|
major.locateGrave(e.data.id);
|
sendOut(DP, e, { type: "major.out", index: MJ.index, flag: MJ.flag, id: e.data.id });
|
return;
|
}
|
|
if (e.name === "LY") { // 产业楼宇
|
LY.id = e.data.id;
|
locateLY(e.data.id);
|
sendOut(DP, e, { type: "build.out", name: LY.name, id: LY.id });
|
}
|
});
|
|
// map.Enable3DBillboardCallBack(true, function (e) {
|
// if (e && e.BillboardMouseType == 'Pressed' && e.JsonNews) {
|
// that.$store.commit('changeVideo', e.JsonNews.index)
|
// that.$bus.$emit('manYouVideo', e)
|
// }
|
// });
|
}
|
|
function sendOut (DP, e, data) {
|
let json = JSON.stringify(data);
|
if (lastOUt === json) return;
|
|
lastOUt = json;
|
console.log('发送UE_OUT消息 => ' + json, e);
|
DP.UE_OUT = data;
|
}
|
|
// 定位
|
export function setView (view) {
|
// x-UE坐标X, y-UE坐标Y, z-UE坐标Z, roll-以朝向为轴的旋转角度, pitch-以朝向正右为轴的旋转角度, yaw-以朝向正上为轴的旋转角度, distance-镜头高度
|
map.setView(view.x, view.y, view.z, view.roll, view.pitch, view.yaw, view.distance);
|
}
|
|
// 飞向
|
export function flyTo (view) {
|
// x-UE坐标X, y-UE坐标Y, z-UE坐标Z, roll-以朝向为轴的旋转角度, pitch-以朝向正右为轴的旋转角度, yaw-以朝向正上为轴的旋转角度, distance-镜头高度, callback-回调函数,time-飞向时间
|
map.flyTo(view.x, view.y, view.z, view.roll, view.pitch, view.yaw, view.distance, view.callback, view.time || 5);
|
}
|
|
// 打印信息
|
export function print () {
|
console.log("UE.js", map, setting);
|
building.print();
|
major.print();
|
}
|
|
// 测试楼宇:UE.testLY()
|
export function testLY () {
|
building.testLY();
|
}
|
|
// 定位楼宇
|
export function locateLY (id) {
|
building.locateLY(id);
|
}
|
|
/**
|
* 查询楼宇:UE.testLY(), UE.locateLY(1756);
|
* dataPool.dataPool.UE_IN={type:'build',name:'新一代信息技术产业',id:"1776"};
|
* dataPool.dataPool.UE_IN={type:'build',name:'219',id:"1776"};
|
*/
|
export function queryLY (name, id) {
|
building.queryLY(name, id);
|
}
|
|
/**
|
* 查询重大项目
|
*
|
* 重大项目:UE.queryMajor(0,-1); UE.locateMajor(155);
|
* dataPool.dataPool.UE_IN={type:'major',index:0,flag:-1};
|
*
|
* 园区产值:UE.queryMajor(1,-1); UE.locateMajor("666");
|
* dataPool.dataPool.UE_IN={type:'major',index:1,flag:-1};
|
*
|
* 重点企业:UE.queryMajor(2,-1); UE.locateMajor("1986");
|
* dataPool.dataPool.UE_IN={type:'major',index:2,flag:-1};
|
*
|
* 区域产值:UE.queryMajor(3,1); UE.queryMajor(3,2); UE.queryMajor(3,3);
|
* dataPool.dataPool.UE_IN={type:'major',index:3,flag:1}; // 大兴部分
|
* dataPool.dataPool.UE_IN={type:'major',index:3,flag:2}; // 核心区
|
* dataPool.dataPool.UE_IN={type:'major',index:3,flag:3}; // 通州部分
|
*
|
* 重大项目右侧:UE.queryMajor(5,"道路建设项目"); // 产业项目,居住建设项目,电力基础设施建设项目
|
* dataPool.dataPool.UE_IN={type:'major',index:5,flag:"道路建设项目"};
|
*/
|
export function queryMajor (index, flag) {
|
major.queryMajor(index, flag);
|
}
|
|
// 定位项目
|
export function locateMajor (id) {
|
major.locateGrave(id);
|
}
|
|
export default {
|
map, timer, lastOUt, MJ, LY, init, inited, addEvent, setView, flyTo, print, testLY, locateLY, queryLY, queryMajor, locateMajor
|
};
|