user.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /**
  2. * [ONEMAP.M.user]
  3. * @return {[object]}
  4. */
  5. define(['html!templates/user',
  6. 'css!styles/user',
  7. 'css!styles/tools/toolPublicPopup',
  8. 'modDir/tools/toolDraw_new'
  9. ], function (tplLayout) {
  10. /*****
  11. * 地理帮助脚本
  12. */
  13. const coordinate = {
  14. x_PI: (Math.PI * 3000.0) / 180.0,
  15. PI: Math.PI,
  16. ee: 0.00669342162296594323,
  17. a: 6378245.0,
  18. projs: {
  19. '01': 'wgs84', //84坐标
  20. '02': 'gcj02', //火星坐标
  21. '03': 'bd09', //百度坐标
  22. '04': 'utm4', //utm坐标
  23. '05': 'shcj', //城建坐标
  24. '06': 'meter', //米制单位
  25. '07': 'degree' // 度制单位
  26. },
  27. epsg: {
  28. //WGS 84 - WGS84 - World Geodetic System 1984, used in GPS
  29. '4326': '+proj=longlat +datum=WGS84 +no_defs',
  30. //WGS 84 / Pseudo-Mercator - Spherical Mercator, Google Maps, OpenStreetMap, Bing, ArcGIS, ESRI
  31. '3857':
  32. '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs',
  33. //CGCS2000 / 3-degree Gauss-Kruger zone 40
  34. '4528':
  35. '+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=40500000 +y_0=0 +ellps=GRS80 +units=m +no_defs'
  36. },
  37. bd09_to_gcj02: function (bd_lon, bd_lat) {
  38. var x = bd_lon - 0.0065
  39. var y = bd_lat - 0.006
  40. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_PI)
  41. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_PI)
  42. var gg_lng = z * Math.cos(theta)
  43. var gg_lat = z * Math.sin(theta)
  44. return [gg_lng, gg_lat]
  45. },
  46. gcj02_to_bd09: function (lng, lat) {
  47. var z =
  48. Math.Sqrt(lng * lng + lat * lat) + 0.00002 * Math.Sin(lat * this.x_PI)
  49. var theta = Math.Atan2(lat, lng) + 0.000003 * Math.Cos(lng * this.x_PI)
  50. var bd_lng = z * Math.Cos(theta) + 0.0065
  51. var bd_lat = z * Math.Sin(theta) + 0.006
  52. return [bd_lng, bd_lat]
  53. },
  54. wgs84_to_gcj02: function (lng, lat) {
  55. if (this.out_of_china(lng, lat)) {
  56. [lng, lat]
  57. } else {
  58. var dlat = this.transformlat(lng - 105.0, lat - 35.0)
  59. var dlng = this.transformlng(lng - 105.0, lat - 35.0)
  60. var radlat = (lat / 180.0) * this.PI
  61. var magic = Math.sin(radlat)
  62. magic = 1 - this.ee * magic * magic
  63. var sqrtmagic = Math.sqrt(magic)
  64. dlat =
  65. (dlat * 180.0) /
  66. (((this.a * (1 - this.ee)) / (magic * sqrtmagic)) * this.PI)
  67. dlng =
  68. (dlng * 180.0) / ((this.a / sqrtmagic) * Math.cos(radlat) * this.PI)
  69. var mglat = parseFloat(lat) + parseFloat(dlat)
  70. var mglng = parseFloat(lng) + parseFloat(dlng)
  71. return [mglng, mglat]
  72. }
  73. },
  74. gcj02_to_wgs84: function (lng, lat) {
  75. if (this.out_of_china(lng, lat)) {
  76. return [lng, lat]
  77. } else {
  78. var dlat = this.transformlat(lng - 105.0, lat - 35.0)
  79. var dlng = this.transformlng(lng - 105.0, lat - 35.0)
  80. var radlat = (lat / 180.0) * this.PI
  81. var magic = Math.sin(radlat)
  82. magic = 1 - this.ee * magic * magic
  83. var sqrtmagic = Math.sqrt(magic)
  84. dlat =
  85. (dlat * 180.0) /
  86. (((this.a * (1 - this.ee)) / (magic * sqrtmagic)) * this.PI)
  87. dlng =
  88. (dlng * 180.0) / ((this.a / sqrtmagic) * Math.cos(radlat) * this.PI)
  89. var mglat = lat + dlat
  90. var mglng = lng + dlng
  91. return [lng * 2 - mglng, lat * 2 - mglat]
  92. }
  93. },
  94. out_of_china: function (lng, lat) {
  95. // 纬度3.86~53.55,经度73.66~135.05
  96. return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55)
  97. },
  98. transformlat: function (lng, lat) {
  99. var ret =
  100. -100.0 +
  101. 2.0 * lng +
  102. 3.0 * lat +
  103. 0.2 * lat * lat +
  104. 0.1 * lng * lat +
  105. 0.2 * Math.sqrt(Math.abs(lng))
  106. ret +=
  107. ((20.0 * Math.sin(6.0 * lng * this.PI) +
  108. 20.0 * Math.sin(2.0 * lng * this.PI)) *
  109. 2.0) /
  110. 3.0
  111. ret +=
  112. ((20.0 * Math.sin(lat * this.PI) +
  113. 40.0 * Math.sin((lat / 3.0) * this.PI)) *
  114. 2.0) /
  115. 3.0
  116. ret +=
  117. ((160.0 * Math.sin((lat / 12.0) * this.PI) +
  118. 320 * Math.sin((lat * this.PI) / 30.0)) *
  119. 2.0) /
  120. 3.0
  121. return ret
  122. },
  123. transformlng: function (lng, lat) {
  124. var ret =
  125. 300.0 +
  126. lng +
  127. 2.0 * lat +
  128. 0.1 * lng * lng +
  129. 0.1 * lng * lat +
  130. 0.1 * Math.sqrt(Math.abs(lng))
  131. ret +=
  132. ((20.0 * Math.sin(6.0 * lng * this.PI) +
  133. 20.0 * Math.sin(2.0 * lng * this.PI)) *
  134. 2.0) /
  135. 3.0
  136. ret +=
  137. ((20.0 * Math.sin(lng * this.PI) +
  138. 40.0 * Math.sin((lng / 3.0) * this.PI)) *
  139. 2.0) /
  140. 3.0
  141. ret +=
  142. ((150.0 * Math.sin((lng / 12.0) * this.PI) +
  143. 300.0 * Math.sin((lng / 30.0) * this.PI)) *
  144. 2.0) /
  145. 3.0
  146. return ret
  147. },
  148. /// <summary>
  149. /// web墨卡托经纬度转米
  150. /// </summary>
  151. /// <param name="lng"></param>
  152. /// <param name="lat"></param>
  153. /// <returns></returns>
  154. degree_to_meter: function (lng, lat) {
  155. var x = (lng * 20037508.34) / 180
  156. var y = Math.log(Math.tan(((90 + lat) * this.PI) / 360)) / (this.PI / 180)
  157. y = (y * 20037508.34) / 180
  158. return [x, y]
  159. },
  160. //Web墨卡托转经纬度
  161. meter_to_degree: function (x, y) {
  162. var lon = (x / 20037508.34) * 180
  163. var lat = (y / 20037508.34) * 180
  164. lat =
  165. (180 / this.PI) *
  166. (2 * Math.atan(Math.exp((lat * this.PI) / 180)) - this.PI / 2)
  167. return [lon, lat]
  168. },
  169. /**
  170. * @description wgs84坐标转上海城建
  171. * @time 2020-09-02
  172. * @author zhb
  173. * @param {*} x
  174. * @param {*} y
  175. */
  176. wgs84_to_shcj: function (x, y) {
  177. let xy = []
  178. xy = this.shcj_get_UTM_from_WGS(x, y)
  179. return this.utm_to_shcj4(xy[0], xy[1])
  180. },
  181. utm_to_shcj4(x, y) {
  182. let DX, DY, T, K
  183. DX = -500199.29965
  184. DY = -3457078.805985
  185. T = 0.0000001755
  186. K = 1.0004000106
  187. return this.covert_by_four_parm(x, y, DX, DY, T, K)
  188. },
  189. shcj_get_UTM_from_WGS: function (lon, lat) {
  190. let a = 6378137
  191. let b = 6356752.3142451
  192. let f = (a - b) / a
  193. let eSquare = 2 * f - f * f
  194. let k0 = 0.9996
  195. let lonOrigin = 121.46714714
  196. let FN = 0
  197. // # 确保longtitude位于-180.00----179.9之间
  198. let lonTemp = lon + 180 - Math.floor((lon + 180) / 360) * 360 - 180
  199. let latRad = (lat * this.PI) / 180
  200. let lonRad = (lonTemp * this.PI) / 180
  201. let lonOriginRad = (lonOrigin * this.PI) / 180
  202. let e2Square = eSquare / (1 - eSquare)
  203. let V = a / Math.sqrt(1 - eSquare * Math.pow(Math.sin(latRad), 2))
  204. let T = Math.pow(Math.tan(latRad), 2)
  205. let C = e2Square * Math.pow(Math.cos(latRad), 2)
  206. let A = Math.cos(latRad) * (lonRad - lonOriginRad)
  207. let M =
  208. a *
  209. ((1 -
  210. eSquare / 4 -
  211. (3 * Math.pow(eSquare, 2)) / 64 -
  212. (5 * Math.pow(eSquare, 3)) / 256) *
  213. latRad -
  214. ((3 * eSquare) / 8 +
  215. (3 * Math.pow(eSquare, 2)) / 32 +
  216. (45 * Math.pow(eSquare, 3)) / 1024) *
  217. Math.sin(2 * latRad) +
  218. ((15 * Math.pow(eSquare, 2)) / 256 +
  219. (45 * Math.pow(eSquare, 3)) / 1024) *
  220. Math.sin(4 * latRad) -
  221. ((35 * Math.pow(eSquare, 3)) / 3072) * Math.sin(6 * latRad))
  222. // # x
  223. let UTMEasting =
  224. k0 *
  225. V *
  226. (A +
  227. ((1 - T + C) * Math.pow(A, 3)) / 6 +
  228. ((5 - 18 * T + Math.pow(T, 2) + 72 * C - 58 * e2Square) *
  229. Math.pow(A, 5)) /
  230. 120) +
  231. 500000.0
  232. // # y
  233. let UTMNorthing =
  234. k0 *
  235. (M +
  236. V *
  237. Math.tan(latRad) *
  238. (Math.pow(A, 2) / 2 +
  239. ((5 - T + 9 * C + 4 * Math.pow(C, 2)) * Math.pow(A, 4)) / 24 +
  240. ((61 - 58 * T + Math.pow(T, 2) + 600 * C - 330 * e2Square) *
  241. Math.pow(A, 6)) /
  242. 720))
  243. //# 南半球纬度起点为10000000.0m
  244. UTMNorthing += FN
  245. let xy = []
  246. xy[0] = UTMEasting
  247. xy[1] = UTMNorthing
  248. return xy
  249. },
  250. /**
  251. * @description 上海城建坐标转wgs84
  252. * @time 2020-09-02
  253. * @author zhb
  254. * @param {*} x
  255. * @param {*} y
  256. */
  257. shcj_to_wgs84: function (x, y) {
  258. let xy = []
  259. xy = this.shcj_to_utm4(x, y)
  260. return this.shcj_get_WGS_from_UTM(xy[0], xy[1])
  261. },
  262. shcj_to_utm4: function (x, y) {
  263. let DX, DY, T, K
  264. DX = 499999.90104
  265. DY = 3455696.403019
  266. T = -0.0000001755
  267. K = 0.999600149344
  268. return this.covert_by_four_parm(x, y, DX, DY, T, K)
  269. },
  270. //四参数公式
  271. covert_by_four_parm: function (x, y, dx, dy, a, k) {
  272. let px = 0
  273. let py = 0
  274. px = x * k * Math.cos(a) - y * k * Math.sin(a) + dx
  275. py = x * k * Math.sin(a) + y * k * Math.cos(a) + dy
  276. let xy = []
  277. xy[0] = px
  278. xy[1] = py
  279. return xy
  280. },
  281. shcj_get_WGS_from_UTM: function (x, y) {
  282. //WGS84
  283. let a = 6378137 //椭球体长半轴
  284. let b = 6356752.3142451 //椭球体短半轴
  285. // double a = 6378245 ;
  286. // double b =6356863.018773047300000000;
  287. x = 500000 - x
  288. let k0 = 0.9996
  289. let e = Math.sqrt(1 - Math.pow(b, 2) / Math.pow(a, 2))
  290. // # calculate the meridional arc
  291. let M = y / k0
  292. //# calculate footprint latitude
  293. let mu =
  294. M /
  295. (a *
  296. (1 -
  297. Math.pow(e, 2) / 4 -
  298. (3 * Math.pow(e, 4)) / 64 -
  299. (5 * Math.pow(e, 6)) / 256))
  300. let e1 =
  301. (1 - Math.pow(1 - Math.pow(e, 2), 1.0 / 2)) /
  302. (1 + Math.pow(1 - Math.pow(e, 2), 1.0 / 2))
  303. let J1 = (3 * e1) / 2 - (27 * Math.pow(e1, 3)) / 32
  304. let J2 = (21 * Math.pow(e1, 2)) / 16 - (55 * Math.pow(e1, 4)) / 32
  305. let J3 = (151 * Math.pow(e1, 3)) / 96
  306. let J4 = (1097 * Math.pow(e1, 4)) / 512
  307. let fp =
  308. mu +
  309. J1 * Math.sin(2 * mu) +
  310. J2 * Math.sin(4 * mu) +
  311. J3 * Math.sin(6 * mu) +
  312. J4 * Math.sin(8 * mu)
  313. // # Calculate Latitude and Longitude
  314. let e2 = Math.pow(e, 2) / (1 - Math.pow(e, 2))
  315. let C1 = e2 * Math.pow(Math.cos(fp), 2)
  316. let T1 = Math.pow(Math.tan(fp), 2)
  317. let R1 =
  318. (a * (1 - Math.pow(e, 2))) /
  319. Math.pow(1 - Math.pow(e * Math.sin(fp), 2), 3.0 / 2)
  320. //# This is the same as rho in the forward conversion formulas above, but calculated for fp instead of lat.
  321. let N1 = a / Math.pow(1 - Math.pow(e * Math.sin(fp), 2), 1.0 / 2)
  322. //# This is the same as nu in the forward conversion formulas above, but calculated for fp instead of lat.
  323. let D = x / (N1 * k0)
  324. let Q1 = (N1 * Math.tan(fp)) / R1
  325. let Q2 = Math.pow(D, 2) / 2
  326. let Q3 =
  327. ((5 + 3 * T1 + 10 * C1 - 4 * Math.pow(C1, 2) - 9 * e2) * Math.pow(D, 4)) /
  328. 24
  329. let Q4 =
  330. ((61 +
  331. 90 * T1 +
  332. 298 * C1 +
  333. 45 * Math.pow(T1, 2) -
  334. 3 * Math.pow(C1, 2) -
  335. 252 * e2) *
  336. Math.pow(D, 6)) /
  337. 720
  338. let lat = ((fp - Q1 * (Q2 - Q3 + Q4)) * 180) / this.PI
  339. // System.out.println("lat===="+Math.toRadians(fp - Q1*(Q2 - Q3 + Q4)));
  340. let Q5 = D
  341. let Q6 = ((1 + 2 * T1 + C1) * Math.pow(D, 3)) / 6
  342. let Q7 =
  343. ((5 -
  344. 2 * C1 +
  345. 28 * T1 -
  346. 3 * Math.pow(C1, 2) +
  347. 8 * e2 +
  348. 24 * Math.pow(T1, 2)) *
  349. Math.pow(D, 5)) /
  350. 120
  351. let lonmid = 121.46714714
  352. let lon = lonmid - (((Q5 - Q6 + Q7) / Math.cos(fp)) * 180) / this.PI
  353. //System.out.println("lon===="+(mMid - Math.toRadians((Q5 - Q6 + Q7)/Math.cos(fp))));
  354. // System.out.println(lat+","+lon);
  355. let xy = []
  356. xy[0] = lon
  357. xy[1] = lat
  358. return xy
  359. },
  360. wgs84_to_bd09: function (x, y) {
  361. let ll = this.wgs84_to_gcj02(x, y)
  362. ll = this.gcj02_to_bd09(ll[0], ll[1])
  363. return ll
  364. },
  365. bd09_to_wgs84: function (x, y) {
  366. let ll = this.bd09_to_gcj02(x, y)
  367. ll = this.gcj02_to_wgs84(ll[0], ll[1])
  368. return ll
  369. },
  370. gcj02_to_shcj: function (x, y) {
  371. let ll = this.gcj02_to_wgs84(x, y)
  372. ll = this.wgs84_to_shcj(ll[0], ll[1])
  373. return ll
  374. },
  375. shcj_to_gcj02: function (x, y) {
  376. let ll = this.shcj_to_wgs84(x, y)
  377. ll = this.wgs84_to_gcj02(ll[0], ll[1])
  378. return ll
  379. },
  380. /**
  381. * @description 坐标转换转换 01:84,02:高德,03.百度,04,UTM,05,上海城建,06:米制单位
  382. * @param {} from
  383. * @param {*} to
  384. * @param {*} xy
  385. * @time 2020-09-02
  386. * @author zhb
  387. */
  388. convert_proj_from_to: function (from, to, xy) {
  389. if (from === to) {
  390. return xy
  391. } else {
  392. let fromProj = this.projs[from]
  393. let toProj = this.projs[to]
  394. let targetMethod = `${fromProj}_to_${toProj}`
  395. return this[targetMethod](xy[0], xy[1])
  396. }
  397. }
  398. }
  399. var status = {
  400. userContentShow: false,
  401. netType: null,
  402. // showhideAll:true
  403. }
  404. function init() {
  405. setLayout();
  406. subscribe();
  407. bindEvents();
  408. };
  409. function setLayout() {
  410. // 获取地名地址token - 刘梦祥
  411. getAddrApiToken();
  412. // 渲染地名地址搜索框 - 刘梦祥
  413. setTimeout(function () {
  414. $("#addressSearch").show();
  415. showResultListBox(false, [], false);
  416. // 地名地址搜索框内容监听
  417. $("#addressSearch").on("change", function () {
  418. let searchValue = "";
  419. searchValue = $("#addressSearch").val();
  420. if (searchValue != "") {
  421. searchValueFun();
  422. } else {
  423. // 收起建议栏
  424. showResultListBox(false, [], false);
  425. }
  426. });
  427. //监听地名地址搜索结果View Close按钮
  428. $(".closeDiv").off("click").on("click", function () {
  429. showResultListBox(false, [], false);
  430. })
  431. //监听地名地址原网站跳转按钮点击事件
  432. $(".UserAHref").off("click").on("click", function () {
  433. window.open("http://10.235.245.226:3200/geoAM/#/map?token=" + localStorage.getItem("Accesstoken"), "_blank");
  434. })
  435. }, 500);
  436. // $(tplLayout).appendTo($("#wrapper"));
  437. $(tplLayout).appendTo($("#userInfo"));
  438. //$('#userContent .userLink .cover-content').html(ONEMAP.D.user.name);
  439. //拖拽
  440. $(".userInfo .popup-ct").dragmove($('.userInfo'));
  441. if (ONEMAP.D.isLoad) {//判断是否登录,ture 登录
  442. return;
  443. var role_list = ONEMAP.D.user.roles;
  444. // 只有admin用户才有地图设置选项
  445. $.each(role_list, function (i, t) {
  446. switch (t) {
  447. case "admin":
  448. $('#userContent .userInfo .moreLink .linkList li.set').css("display", "inline-block");
  449. break;
  450. }
  451. })
  452. }
  453. if (map23DConfig.netType == 1) {
  454. $("#userInfo .check-button").html("离线");
  455. $("#userContent .lgfooter .check-button").animate({ "left": "40px" }, 200);
  456. status.netType = 1;
  457. } else {
  458. $("#userInfo .check-button").html("在线");
  459. $("#userContent .lgfooter .check-button").animate({ "left": "8px" }, 200);
  460. status.netType = 2;
  461. }
  462. if (ONEMAP.D.user.username != "map_super_user") {
  463. $('#userContent .userInfo .moreLink .linkList li.set').hide();
  464. }
  465. if (!map23DConfig.showSourceCenter) {
  466. $('#userContent .share').hide();
  467. }
  468. };
  469. // 获取地名地址token信息,并保存到LocalStorage中 - 刘梦祥
  470. function getAddrApiToken() {
  471. try {
  472. $.ajax({
  473. url: onemapUrlConfig.DMS_URL + '/dms/content/selectContentList',
  474. type: 'POST',
  475. headers: {
  476. token: localStorage.getItem("systemToken")
  477. },
  478. dataType: "json",
  479. data: {
  480. columnId: 1229,
  481. states: 0,
  482. pageSize: 10,
  483. page: 0
  484. },
  485. })
  486. .done(function (res) {
  487. if (res.content && res.content.data && res.content.data[0].c_content) {
  488. localStorage.setItem("Accesstoken", res.content.data[0].c_content);
  489. } else {
  490. ONEMAP.C.publisher.publish({
  491. type: 'warning',
  492. message: "用户尚未登录!"
  493. }, 'noteBar::add');
  494. }
  495. }).fail(function (error) {
  496. ONEMAP.C.publisher.publish({
  497. type: 'warning',
  498. message: error
  499. }, 'noteBar::add');
  500. console.error("getAddrApiToken", error);
  501. });
  502. } catch (error) {
  503. console.error("getAddrApiToken catch", error);
  504. }
  505. }
  506. // 地名地址搜索功能 - 刘梦祥
  507. function searchValueFun() {
  508. // 根据搜索条件进行搜索匹配
  509. try {
  510. let searchValue = $("#addressSearch").val();
  511. let params = {
  512. addr: searchValue,
  513. page: 1,
  514. limit: 10,
  515. projectId: [],
  516. addressType: [],
  517. fuzzy: true
  518. };
  519. if (localStorage.getItem("addrSearchTag") == 1) {
  520. params.fuzzy = true;
  521. } else {
  522. params.fuzzy = false;
  523. }
  524. // 开始搜索
  525. $.ajax({
  526. url: "http://10.235.245.226:7010/AddressCoreService/addrMatch/addrApi/searchAddrForGeo",
  527. type: 'POST',
  528. headers: {
  529. "Accesstoken": localStorage.getItem("Accesstoken")
  530. },
  531. data: params,
  532. })
  533. .done(function (res) {
  534. if (res.data.features.length > 0) {
  535. let resultDataList = res.data.features;
  536. showResultListBox(true, resultDataList, params.fuzzy);
  537. } else {
  538. ONEMAP.C.publisher.publish({
  539. type: 'warning',
  540. message: "关键词未搜索到结果!"
  541. }, 'noteBar::add');
  542. showResultListBox(false, [], false);
  543. }
  544. }).fail(function (error) {
  545. console.error("searchValueFun", error);
  546. showResultListBox(false, [], false);
  547. });
  548. } catch (error) {
  549. console.error("searchValueFun catch", error);
  550. showResultListBox(false, [], false);
  551. }
  552. }
  553. // 定位到指定的坐标
  554. ONEMAP.C.publisher.subscribe(function (data) {
  555. let localAddr = coordinate.shcj_to_wgs84(data.x, data.y);
  556. map23DData.view.pitch = -90;
  557. map3DViewer.flyTo({
  558. center: {
  559. lat: localAddr[1],
  560. lng: localAddr[0]
  561. },
  562. zoom: 18,
  563. heading: 0, //摄像机平面角度 正北为0
  564. tilt: 0, //摄像机倾斜角
  565. });
  566. }, 'orientationToMap');
  567. // 根据条件渲染地名地址结果View - 刘梦祥 fuzzy:如果返回的结果是精准查找的话,点击Item后要有单独的处理事件并隐藏View
  568. function showResultListBox(status, resultList, fuzzy) {
  569. if ($(".resultItem")) {
  570. $(".resultItem").remove();
  571. }
  572. if (resultList.length > 0) {
  573. for (let i = 0; i < resultList.length; i++) {
  574. if (fuzzy) {
  575. $(`<div class="resultItem orientation" onclick="orientation('` + resultList[i].properties.x + `','` + resultList[i].properties.y + `')">` + (i + 1) + " : " + resultList[i].properties.addr + `</div>`).appendTo($("#resultListBox"));
  576. } else {
  577. $(`<div class="resultItem" onclick="searchAddrTure('` + resultList[i].properties.addr + `')">` + (i + 1) + " : " + resultList[i].properties.addr + `</div>`).appendTo($("#resultListBox"));
  578. }
  579. }
  580. }
  581. if (status) {
  582. $("#resultListBox").show();
  583. } else {
  584. localStorage.setItem("addrSearchTag", 0);
  585. $("#resultListBox").hide();
  586. }
  587. }
  588. function fullMap(option) {
  589. if (option) {
  590. $("#userContent").fadeOut('slow')
  591. } else {
  592. $("#userContent").fadeIn('slow')
  593. }
  594. }
  595. function change23D(options) {
  596. if (options == '2d') {
  597. $('#userContent').removeClass('class3d');
  598. // $("#userContent .userInfo .moreLink .linkList li.myBh").addClass('active');
  599. } else {
  600. $('#userContent').addClass('class3d');
  601. // $("#userContent .userInfo .moreLink .linkList li.myBh").removeClass('active');
  602. }
  603. }
  604. function remove() {
  605. ONEMAP.M.toolDraw.remove({ modName: 'cleanMap' });
  606. }
  607. function subscribe() {
  608. // ONEMAP.C.publisher.subscribe(remove,'tools:active');
  609. ONEMAP.C.publisher.subscribe(layoutesize, 'seitchNetwork');
  610. ONEMAP.C.publisher.subscribe(closeLeft, 'layout::closeLeft');
  611. ONEMAP.C.publisher.subscribe(change23D, 'change23D');
  612. ONEMAP.C.publisher.subscribe(fullMap, 'layout::fullMap');
  613. };
  614. function bindEvents() {
  615. //用户左上面板开关
  616. $('#userContent .userLink').bind('click', function () {
  617. var userInfo = $("#userContent .userInfo");
  618. if (userInfo.hasClass("active")) {
  619. userInfo.removeClass("active");
  620. } else {
  621. userInfo.addClass("active");
  622. $("#searchresult").hide();
  623. }
  624. //关掉menu
  625. if ($("#menu").hasClass("moveOut")) {
  626. $("#menu").animate({
  627. left: "-340px"
  628. }, 200)
  629. $("#menu").removeClass("moveOut");
  630. var layer = $("#layerControlMenu");
  631. var layerLeft = parseFloat($("#layerControlMenu").css("left"));
  632. if (layerLeft <= 0) {
  633. layer.animate({
  634. left: "-340px"
  635. }, 200)
  636. }
  637. // $("#menu .arrow").removeClass("left");
  638. }
  639. })
  640. //用户面板中我的收藏
  641. $("#userContent .userInfo .moreLink .linkList li.collect").bind("click", function () {
  642. require(['modDir/user/userSideBar'], function (userSideBar) {
  643. userSideBar.init();
  644. });
  645. if ($("#toolsBar").hasClass('cur')) {
  646. $("#toolsBar p").click();
  647. }
  648. // $("#userContent .userInfo .moreLink .linkList li.myBh").addClass('uFavo').addClass('active');
  649. })
  650. $(".data-share-link").attr("href", onemapUrlConfig.shareUrl);
  651. $('#userContent .userLink').bind('click', function () {
  652. if (ONEMAP.D.isLoad) {
  653. $('#userContent .userInfo .moreLink,.lgtop').show();
  654. $('#userContent .popup-lt,#userContent .popup-lb,#userContent .popup-rt,#userContent .popup-rb').show();
  655. $('#userContent .username').html(ONEMAP.D.user.name);//填入用户名
  656. // $('#userContent .username').html();//疑惑操作
  657. // $("#userContent .userInfo .moreLink .collect").show();
  658. $("#userContent .mt10").show();//展示上次登录时间
  659. $("#userContent").removeClass("no-login");//无实际用途
  660. $("#userContent .quit").show();//展示退出登录
  661. $("#userContent .userInfo .login").hide();//隐藏提示登录信息
  662. $("#userContent .userInfo .moreLink .linkList li.myBh").addClass('uFavo').addClass('active');
  663. } else {
  664. $('#userContent .userInfo .login').show();//展示提示登录信息
  665. $("#userContent .mt10").hide();//隐藏上次登录时间
  666. // $("#userContent").addClass("no-login");//无实际用途
  667. // $('#userContent .userInfo .moreLink,.lgtop').show();//疑惑操作
  668. $("#userContent .userInfo .moreLink").hide();//隐藏用户中心
  669. $("#userContent .quit").hide();//隐藏退出登录
  670. $("#userContent .userInfo .moreLink .linkList li.myBh").removeClass('uFavo').removeClass('active');//隐藏我的标注
  671. }
  672. $('#userContent .userLink').addClass('active');
  673. status.userContentShow = true;
  674. })
  675. //登录
  676. $('#userContent .userInfo .login a').bind('click', function () {
  677. // ONEMAP.C.gotoLogin();
  678. // require(['modDir/user/userLogin'], function (userLogin) {
  679. // userLogin.init();
  680. // });
  681. $("#userLogin").show();
  682. })
  683. $("#userContent .userInfo .moreLink .linkList li").bind('click', function () {
  684. var curmid = $(this).attr('mid');
  685. if (curmid == 'logout') {
  686. ONEMAP.C.logout();
  687. } else if (curmid == 'setting') {
  688. require(['modDir/user/userSetting'], function (userSetting) {
  689. userSetting.init();
  690. });
  691. }
  692. // else if (curmid == 'userCenter') {
  693. // require(['modDir/user/userCenter'], function(userCenter) {
  694. // userCenter.init('userFav');
  695. // });
  696. // }
  697. else if (curmid == 'set') {
  698. require(['modDir/user/userSetting'], function (userSetting) {
  699. userSetting.init();
  700. });
  701. }
  702. })
  703. // 退出登录
  704. $("#userContent .quit").bind('click', function () {
  705. // ONEMAP.C.logout();
  706. // $("#userContent .mt10").hide();
  707. localStorage.removeItem('userInfo');
  708. localStorage.removeItem('systemToken');
  709. window.location.reload();
  710. })
  711. // 标注显隐
  712. $("#userContent .userInfo .moreLink .linkList li.myBh").unbind("click").bind("click", function () {
  713. if ($(this).hasClass('uFavo')) {
  714. // if(status.showhideAll){
  715. //加载全部
  716. ONEMAP.M.toolDraw.addAllCollect("show");
  717. // }
  718. //$(".leaflet-marker-pane,.leaflet-overlay-pane,.leaflet-shadow-pane").show(); // 二维
  719. $("#userContent .userInfo .moreLink .linkList li.myBh").removeClass("uFavo");
  720. // status.showhideAll = false;
  721. } else {
  722. ONEMAP.M.toolDraw.addAllCollect("hide");
  723. //$(".leaflet-marker-pane,.leaflet-overlay-pane,.leaflet-shadow-pane").hide(); // 二维
  724. $("#userContent .userInfo .moreLink .linkList li.myBh").addClass("uFavo");
  725. }
  726. })
  727. // 关闭左侧栏
  728. $("#userInfo .arrow").bind('click', function () {
  729. ONEMAP.M.user.closeLeft();
  730. })
  731. //切换网络
  732. $("#switchInter").bind('click', function () {
  733. if (status.netType == 1) {
  734. curNetType = 2;
  735. } else {
  736. curNetType = 1
  737. }
  738. require(['layoutDir/switchNetwork'], function (switchNetwork) {
  739. switchNetwork.init(curNetType);
  740. });
  741. })
  742. //新登录
  743. // $("#userInfo").bind('click',function(){
  744. // require(['modDir/user/userLogin'], function (userLogin) {
  745. // userLogin.init();
  746. // });
  747. // })
  748. };
  749. function layoutesize(type) {
  750. if (type == "network") {
  751. status.netType = 1;
  752. $("#userInfo .check-button").html("离线");
  753. $("#userContent .lgfooter .check-button").animate({ "left": "40px" }, 200);
  754. } else {
  755. status.netType = 2;
  756. $("#userInfo .check-button").html("在线");
  757. $("#userContent .lgfooter .check-button").animate({ "left": "8px" }, 200);
  758. }
  759. }
  760. function closeLeft() {
  761. $("#menu").animate({
  762. left: "-340px"
  763. }, 200)
  764. $("#menu").removeClass("moveOut");
  765. var layer = $("#layerControlMenu");
  766. var layerLeft = parseFloat($("#layerControlMenu").css("left"));
  767. if (layerLeft <= 0) {
  768. layer.animate({
  769. left: "-340px"
  770. }, 200)
  771. }
  772. }
  773. return ONEMAP.M.user = {
  774. init: init,
  775. closeLeft: closeLeft
  776. }
  777. })