1
13693261870
2023-06-26 da58af6936b5ec3504ed5f69c60894d1403a5e95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
};