user.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. }, 500);
  432. // $(tplLayout).appendTo($("#wrapper"));
  433. $(tplLayout).appendTo($("#userInfo"));
  434. //$('#userContent .userLink .cover-content').html(ONEMAP.D.user.name);
  435. //拖拽
  436. $(".userInfo .popup-ct").dragmove($('.userInfo'));
  437. if (ONEMAP.D.isLoad) {//判断是否登录,ture 登录
  438. return;
  439. var role_list = ONEMAP.D.user.roles;
  440. // 只有admin用户才有地图设置选项
  441. $.each(role_list, function (i, t) {
  442. switch (t) {
  443. case "admin":
  444. $('#userContent .userInfo .moreLink .linkList li.set').css("display", "inline-block");
  445. break;
  446. }
  447. })
  448. }
  449. if (map23DConfig.netType == 1) {
  450. $("#userInfo .check-button").html("离线");
  451. $("#userContent .lgfooter .check-button").animate({ "left": "40px" }, 200);
  452. status.netType = 1;
  453. } else {
  454. $("#userInfo .check-button").html("在线");
  455. $("#userContent .lgfooter .check-button").animate({ "left": "8px" }, 200);
  456. status.netType = 2;
  457. }
  458. if (ONEMAP.D.user.username != "map_super_user") {
  459. $('#userContent .userInfo .moreLink .linkList li.set').hide();
  460. }
  461. if (!map23DConfig.showSourceCenter) {
  462. $('#userContent .share').hide();
  463. }
  464. };
  465. // 获取地名地址token信息,并保存到LocalStorage中 - 刘梦祥
  466. function getAddrApiToken() {
  467. try {
  468. $.ajax({
  469. url: onemapUrlConfig.DMS_URL + '/dms/content/selectContentList',
  470. type: 'POST',
  471. headers: {
  472. token: localStorage.getItem("systemToken")
  473. },
  474. dataType: "json",
  475. data: {
  476. columnId: 1229,
  477. states: 0,
  478. pageSize: 10,
  479. page: 0
  480. },
  481. })
  482. .done(function (res) {
  483. if (res.content && res.content.data && res.content.data[0].c_content) {
  484. localStorage.setItem("Accesstoken", res.content.data[0].c_content);
  485. } else {
  486. ONEMAP.C.publisher.publish({
  487. type: 'warning',
  488. message: "用户尚未登录!"
  489. }, 'noteBar::add');
  490. }
  491. }).fail(function (error) {
  492. ONEMAP.C.publisher.publish({
  493. type: 'warning',
  494. message: error
  495. }, 'noteBar::add');
  496. console.error("getAddrApiToken", error);
  497. });
  498. } catch (error) {
  499. console.error("getAddrApiToken catch", error);
  500. }
  501. }
  502. // 地名地址搜索功能 - 刘梦祥
  503. function searchValueFun() {
  504. // 根据搜索条件进行搜索匹配
  505. try {
  506. let searchValue = $("#addressSearch").val();
  507. let params = {
  508. addr: searchValue,
  509. page: 1,
  510. limit: 10,
  511. projectId: [],
  512. addressType: [],
  513. fuzzy: true
  514. };
  515. if (localStorage.getItem("addrSearchTag") == 1) {
  516. params.fuzzy = true;
  517. } else {
  518. params.fuzzy = false;
  519. }
  520. // 开始搜索
  521. $.ajax({
  522. url: "http://10.235.245.226:7010/AddressCoreService/addrMatch/addrApi/searchAddrForGeo",
  523. type: 'POST',
  524. headers: {
  525. "Accesstoken": localStorage.getItem("Accesstoken")
  526. },
  527. data: params,
  528. })
  529. .done(function (res) {
  530. if (res.data.features.length > 0) {
  531. let resultDataList = res.data.features;
  532. showResultListBox(true, resultDataList, params.fuzzy);
  533. } else {
  534. ONEMAP.C.publisher.publish({
  535. type: 'warning',
  536. message: "关键词未搜索到结果!"
  537. }, 'noteBar::add');
  538. showResultListBox(false, [], false);
  539. }
  540. }).fail(function (error) {
  541. console.error("searchValueFun", error);
  542. showResultListBox(false, [], false);
  543. });
  544. } catch (error) {
  545. console.error("searchValueFun catch", error);
  546. showResultListBox(false, [], false);
  547. }
  548. }
  549. // 定位到指定的坐标
  550. ONEMAP.C.publisher.subscribe(function (data) {
  551. let localAddr = coordinate.shcj_to_wgs84(data.x, data.y);
  552. map23DControl.setView({
  553. center: {
  554. lat: localAddr[1],
  555. lng: localAddr[0]
  556. },
  557. zoom: 18
  558. })
  559. }, 'orientationToMap');
  560. // 根据条件渲染地名地址结果View - 刘梦祥 fuzzy:如果返回的结果是精准查找的话,点击Item后要有单独的处理事件并隐藏View
  561. function showResultListBox(status, resultList, fuzzy) {
  562. if ($(".resultItem")) {
  563. $(".resultItem").remove();
  564. }
  565. if (resultList.length > 0) {
  566. for (let i = 0; i < resultList.length; i++) {
  567. if (fuzzy) {
  568. $(`<div class="resultItem orientation" onclick="orientation('` + resultList[i].properties.x + `','` + resultList[i].properties.y + `')">` + (i + 1) + " : " + resultList[i].properties.addr + `</div>`).appendTo($("#resultListBox"));
  569. } else {
  570. $(`<div class="resultItem" onclick="searchAddrTure('` + resultList[i].properties.addr + `')">` + (i + 1) + " : " + resultList[i].properties.addr + `</div>`).appendTo($("#resultListBox"));
  571. }
  572. }
  573. }
  574. if (status) {
  575. $("#resultListBox").show();
  576. } else {
  577. localStorage.setItem("addrSearchTag", 0);
  578. $("#resultListBox").hide();
  579. }
  580. }
  581. function fullMap(option) {
  582. if (option) {
  583. $("#userContent").fadeOut('slow')
  584. } else {
  585. $("#userContent").fadeIn('slow')
  586. }
  587. }
  588. function change23D(options) {
  589. if (options == '2d') {
  590. $('#userContent').removeClass('class3d');
  591. // $("#userContent .userInfo .moreLink .linkList li.myBh").addClass('active');
  592. } else {
  593. $('#userContent').addClass('class3d');
  594. // $("#userContent .userInfo .moreLink .linkList li.myBh").removeClass('active');
  595. }
  596. }
  597. function remove() {
  598. ONEMAP.M.toolDraw.remove({ modName: 'cleanMap' });
  599. }
  600. function subscribe() {
  601. // ONEMAP.C.publisher.subscribe(remove,'tools:active');
  602. ONEMAP.C.publisher.subscribe(layoutesize, 'seitchNetwork');
  603. ONEMAP.C.publisher.subscribe(closeLeft, 'layout::closeLeft');
  604. ONEMAP.C.publisher.subscribe(change23D, 'change23D');
  605. ONEMAP.C.publisher.subscribe(fullMap, 'layout::fullMap');
  606. };
  607. function bindEvents() {
  608. //用户左上面板开关
  609. $('#userContent .userLink').bind('click', function () {
  610. var userInfo = $("#userContent .userInfo");
  611. if (userInfo.hasClass("active")) {
  612. userInfo.removeClass("active");
  613. } else {
  614. userInfo.addClass("active");
  615. $("#searchresult").hide();
  616. }
  617. //关掉menu
  618. if ($("#menu").hasClass("moveOut")) {
  619. $("#menu").animate({
  620. left: "-340px"
  621. }, 200)
  622. $("#menu").removeClass("moveOut");
  623. var layer = $("#layerControlMenu");
  624. var layerLeft = parseFloat($("#layerControlMenu").css("left"));
  625. if (layerLeft <= 0) {
  626. layer.animate({
  627. left: "-340px"
  628. }, 200)
  629. }
  630. // $("#menu .arrow").removeClass("left");
  631. }
  632. })
  633. //用户面板中我的收藏
  634. $("#userContent .userInfo .moreLink .linkList li.collect").bind("click", function () {
  635. require(['modDir/user/userSideBar'], function (userSideBar) {
  636. userSideBar.init();
  637. });
  638. if ($("#toolsBar").hasClass('cur')) {
  639. $("#toolsBar p").click();
  640. }
  641. // $("#userContent .userInfo .moreLink .linkList li.myBh").addClass('uFavo').addClass('active');
  642. })
  643. $(".data-share-link").attr("href", onemapUrlConfig.shareUrl);
  644. $('#userContent .userLink').bind('click', function () {
  645. if (ONEMAP.D.isLoad) {
  646. $('#userContent .userInfo .moreLink,.lgtop').show();
  647. $('#userContent .popup-lt,#userContent .popup-lb,#userContent .popup-rt,#userContent .popup-rb').show();
  648. $('#userContent .username').html(ONEMAP.D.user.name);//填入用户名
  649. // $('#userContent .username').html();//疑惑操作
  650. // $("#userContent .userInfo .moreLink .collect").show();
  651. $("#userContent .mt10").show();//展示上次登录时间
  652. $("#userContent").removeClass("no-login");//无实际用途
  653. $("#userContent .quit").show();//展示退出登录
  654. $("#userContent .userInfo .login").hide();//隐藏提示登录信息
  655. $("#userContent .userInfo .moreLink .linkList li.myBh").addClass('uFavo').addClass('active');
  656. } else {
  657. $('#userContent .userInfo .login').show();//展示提示登录信息
  658. $("#userContent .mt10").hide();//隐藏上次登录时间
  659. // $("#userContent").addClass("no-login");//无实际用途
  660. // $('#userContent .userInfo .moreLink,.lgtop').show();//疑惑操作
  661. $("#userContent .userInfo .moreLink").hide();//隐藏用户中心
  662. $("#userContent .quit").hide();//隐藏退出登录
  663. $("#userContent .userInfo .moreLink .linkList li.myBh").removeClass('uFavo').removeClass('active');//隐藏我的标注
  664. }
  665. $('#userContent .userLink').addClass('active');
  666. status.userContentShow = true;
  667. })
  668. //登录
  669. $('#userContent .userInfo .login a').bind('click', function () {
  670. // ONEMAP.C.gotoLogin();
  671. // require(['modDir/user/userLogin'], function (userLogin) {
  672. // userLogin.init();
  673. // });
  674. $("#userLogin").show();
  675. })
  676. $("#userContent .userInfo .moreLink .linkList li").bind('click', function () {
  677. var curmid = $(this).attr('mid');
  678. if (curmid == 'logout') {
  679. ONEMAP.C.logout();
  680. } else if (curmid == 'setting') {
  681. require(['modDir/user/userSetting'], function (userSetting) {
  682. userSetting.init();
  683. });
  684. }
  685. // else if (curmid == 'userCenter') {
  686. // require(['modDir/user/userCenter'], function(userCenter) {
  687. // userCenter.init('userFav');
  688. // });
  689. // }
  690. else if (curmid == 'set') {
  691. require(['modDir/user/userSetting'], function (userSetting) {
  692. userSetting.init();
  693. });
  694. }
  695. })
  696. // 退出登录
  697. $("#userContent .quit").bind('click', function () {
  698. // ONEMAP.C.logout();
  699. // $("#userContent .mt10").hide();
  700. localStorage.removeItem('userInfo');
  701. localStorage.removeItem('systemToken');
  702. window.location.reload();
  703. })
  704. // 标注显隐
  705. $("#userContent .userInfo .moreLink .linkList li.myBh").unbind("click").bind("click", function () {
  706. if ($(this).hasClass('uFavo')) {
  707. // if(status.showhideAll){
  708. //加载全部
  709. ONEMAP.M.toolDraw.addAllCollect("show");
  710. // }
  711. //$(".leaflet-marker-pane,.leaflet-overlay-pane,.leaflet-shadow-pane").show(); // 二维
  712. $("#userContent .userInfo .moreLink .linkList li.myBh").removeClass("uFavo");
  713. // status.showhideAll = false;
  714. } else {
  715. ONEMAP.M.toolDraw.addAllCollect("hide");
  716. //$(".leaflet-marker-pane,.leaflet-overlay-pane,.leaflet-shadow-pane").hide(); // 二维
  717. $("#userContent .userInfo .moreLink .linkList li.myBh").addClass("uFavo");
  718. }
  719. })
  720. // 关闭左侧栏
  721. $("#userInfo .arrow").bind('click', function () {
  722. ONEMAP.M.user.closeLeft();
  723. })
  724. //切换网络
  725. $("#switchInter").bind('click', function () {
  726. if (status.netType == 1) {
  727. curNetType = 2;
  728. } else {
  729. curNetType = 1
  730. }
  731. require(['layoutDir/switchNetwork'], function (switchNetwork) {
  732. switchNetwork.init(curNetType);
  733. });
  734. })
  735. //新登录
  736. // $("#userInfo").bind('click',function(){
  737. // require(['modDir/user/userLogin'], function (userLogin) {
  738. // userLogin.init();
  739. // });
  740. // })
  741. };
  742. function layoutesize(type) {
  743. if (type == "network") {
  744. status.netType = 1;
  745. $("#userInfo .check-button").html("离线");
  746. $("#userContent .lgfooter .check-button").animate({ "left": "40px" }, 200);
  747. } else {
  748. status.netType = 2;
  749. $("#userInfo .check-button").html("在线");
  750. $("#userContent .lgfooter .check-button").animate({ "left": "8px" }, 200);
  751. }
  752. }
  753. function closeLeft() {
  754. $("#menu").animate({
  755. left: "-340px"
  756. }, 200)
  757. $("#menu").removeClass("moveOut");
  758. var layer = $("#layerControlMenu");
  759. var layerLeft = parseFloat($("#layerControlMenu").css("left"));
  760. if (layerLeft <= 0) {
  761. layer.animate({
  762. left: "-340px"
  763. }, 200)
  764. }
  765. }
  766. return ONEMAP.M.user = {
  767. init: init,
  768. closeLeft: closeLeft
  769. }
  770. })