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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import { TUVector3 } from 'tumap'; //TUVector3, TUVector2, TURotator
import setting from './setting';
import { post, getUrl, gcj02ToWgs84 } from './api';
 
let arr = [];
 
let map = null;
 
let timer = null;
 
let lastOUt = null;
 
let lastIndex = null;
 
let isLoaded = false;
 
// 初始化
export function init (Map) {
  map = Map;
}
 
// 查询楼宇点
export async function queryLY (industry_id, id) {
  cls();
 
  let rs = await post(setting.lyUrl, { industry_id: industry_id });
  console.log('queryLY => ', rs);
 
  if (!rs || rs.status !== 200 || !rs.data || !rs.data.length) return;
 
  pretreat(rs.data);
  loadLY(rs.data);
  isLoaded = true;
  locateLY(id);
}
 
function pretreat (data) {
  let i = 0;
  while (i < data.length) {
    var d = data[i];
    if (!d.lng || isNaN(d.lng) || !d.lat || isNaN(d.lat)) {
      data.splice(i, 1);
      continue;
    };
 
    d.lng = parseFloat(d.lng);
    d.lat = parseFloat(d.lat);
    i++;
  }
}
 
// 清空
export function cls () {
  map.clearAllCovering();
  lastIndex = null;
  lastOUt = null;
  arr.length = 0;
}
 
// 加载楼宇
export function loadLY (data) {
  for (let i = 0, c = data.length; i < c; i++) {
    let d = data[i];
    let p = getLocalCoord(parseFloat(d.lng), parseFloat(d.lat));
 
    let params = createPosition(p.x, p.y, d, false);
    map.execute('grapi', 'Creat3DPOI', params, function (e) {
      locateLY(e.args.id);
    });
    arr.push(params);
  }
}
 
function getLocalCoord (x, y) {
  let arr = gcj02ToWgs84(x, y);
  //console.log([x, y], arr);
 
  //return map.transformWGS84ToLocal(x + setting.xOffset, y + setting.yOffset);
  return map.transformWGS84ToLocal((arr[0] - 26.897633220927) * 1.3, (arr[1] - 9.16663529527973) * 1.3);
}
 
// 创建点位方法
export function createPosition (ue4x, ue4y, d, flag) {
  let url = getUrl() + (flag ? 'UE/img/dot.png' : 'UE/img/dot1.png');
  let win = getAlertWin(d);
  let pp = setting.popups[6];
 
  var labelText;
  if (d.name != null) {
    labelText = d.name
  } else {
    labelText = d.build_name
  }
 
  return {
    //id: d.id, // poi点的id
    id: d.build_id,
    name: "LY",
    URL: win.url,//弹窗地址
    location: new TUVector3(ue4x, ue4y, 15000), // poi点位置
    icon: url, // icon图标
    size: pp.size, // icon的大小,1是正常大小
    labeltext: labelText, // 标签文字
    color: { r: 255, g: 255, b: 255, a: 1 }, // label文字颜色
    labelsize: 20, // label大小,默认为1
    labelHigh: 1000, // label高度
    wide: pp.height, // 弹窗宽度
    high: pp.width, // 弹窗高度
    horizontal: pp.xOffset, // 水平偏移
    vertical: pp.yOffset, // 垂直偏移
    data: d
  }
}
 
// 获取弹出窗口
export function getAlertWin (d) {
  //let width = 374, height = 256, imgWidth = 68; //, imgHeight = 60;
  return {
    //size: new TUVector2(width, height), // 弹窗大小
    //offset: new TUVector2(-imgWidth + 5, 5 + 12 - height / 2.3), // 弹窗位置,右:x正,下:y正
    url: getUrl() +
      // 'popupThree.html?name=' + getVal(d.name) +
      // '&mode=' + getVal(d.mode_of_operation) +
      // '&unit=' + getVal(d.development_unit) +
      // '&output=' + getVal(d.industrial_output) +
      // '&usage=' + getVal(d.land_usage) +
      // '&rate=' + getVal(d.vacancy_rate) +
      // '&num=' + getVal(d.enterprise_num) // 弹窗地址
      'popupThree.html?name=' + getVal(d.build_name) +
      '&mode=' + getVal(d.mode_of_operation) +
      '&unit=' + getVal(d.development_unit) +
      '&output=' + getVal(d.industrial_value) +
      '&usage=' + getVal(d.nature_of_land) +
      '&rate=' + getVal(d.settle_enterprise_num) +
      '&num=' + getVal(d.vacancy_rate) // 弹窗地址
  };
}
 
function getVal (val) {
  return val == null ? "" : val;
}
 
// 定位楼宇
export function locateLY (id) {
  let idx = findPOI(id);
  if (idx === -1 || lastIndex === idx) return;
 
  //map.focusOn(new TUVector3(arr[idx].ue4x + setting.winXOffset, arr[idx].ue4y, setting.poiHeight), new TURotator(0, -53, 0));
  map.flyTo(arr[idx].location.x + setting.winXOffset, arr[idx].location.y, 0, 0, -42, 0, 75000, null, 3);
 
  changeImg(id);
}
 
// 切换图片
export function changeImg (id) {
  let idx = findPOI(id);
  console.log("changeImg = " + idx);
  if (lastIndex != null) {
    changePOI(lastIndex, false);
    lastIndex = null;
  }
 
  lastIndex = idx;
  changePOI(idx, true);
 
  // map.execute('grapi', 'Show2dPOI', { visibility: true, id: id }, function (e) { });
  map.execute('grapi', 'ShowLabel', { id: id, visibility: false }, null); // 隐藏Label
  map.execute('grapi', 'ShowPopup', { id: id, visibility: true }, null); // 显示Popup
}
 
// 查找POI
export function findPOI (id) {
  for (let i = 0, c = arr.length; i < c; i++) {
    //if (parseInt(arr[i].data.id) === parseInt(id)) return i;
    if ("" + arr[i].data.build_id === "" + id) return i;
  }
 
  return -1;
}
 
// 切换POI
export function changePOI (index, flag) {
  let poi = arr[index];
  console.log("changePOI =>", poi);
 
  let bb = createPosition(poi.location.x, poi.location.y, poi.data, flag);
  map.execute('grapi', 'Remove3DPOI', { id: poi.id }, null);
  map.execute('grapi', 'Creat3DPOI', bb, function (e) {
    locateLY(e.args.id);
    sendOut(e);
  });
 
  arr.splice(index, 1, bb);
}
 
// 发送数据
function sendOut (e) {
  let data = { type: "build.out", name: e.args.data.industry_id, id: e.args.id };
  let json = JSON.stringify(data);
  if (lastOUt === json) return;
 
  console.log('发送消息 =>', e);
  window.dataPool.dataPool.UE_OUT = data;
}
 
// 是/否加载
export function IsLoaded () {
  if (isLoaded) {
    isLoaded = false;
    return true;
  }
 
  return isLoaded;
}
 
// 打印信息
export function print () {
  console.log("building.js", arr, timer, lastIndex, getUrl());
}
 
// dataPool.dataPool.UE_IN={type:'build',name:'新一代信息技术产业',id:601}
// 测试楼宇:UE.testLY(),UE.locateLY(601),UE.queryLY("新一代信息技术产业", 601)
export function testLY () {
  cls();
  loadLY(setting.lvJson);
  isLoaded = true;
  locateLY(601);
}
 
export default {
  arr, map, timer, lastIndex, isLoaded,
  init, queryLY, cls, loadLY, getAlertWin,
  locateLY, changeImg, findPOI, changePOI, IsLoaded, print, testLY
}