userSideBar.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. /**
  2. * [ONEMAP.M.mod]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/user/userSideBar',
  7. 'css!styles/user/userSideBar',
  8. 'modDir/picture',
  9. ],
  10. function (tplLayout) {
  11. /**
  12. * 模块数据 用于数据存储和外部调用
  13. * @type {Object}
  14. * 数据存放
  15. */
  16. var modValue = {
  17. subModName: null,
  18. getHeatmapTime: 'all',
  19. getTileHeatmapTime: 'all',
  20. cfg: {
  21. "radius": 2,
  22. "maxOpacity": 0.8,
  23. "scaleRadius": true,
  24. "useLocalExtrema": true,
  25. latField: 'lat',
  26. lngField: 'lng',
  27. valueField: 'count'
  28. },
  29. heatData: null,
  30. userInfoStatu: 1,
  31. userHeatmapMarkerGroup: null,
  32. appendToMyLayer: null,
  33. heatmapMarkerOpacity: 1,
  34. heatmapType: 0,
  35. IDCardPicture1: "",
  36. IDCardPicture2: "",
  37. _uploadTempDir: "",
  38. }
  39. /**
  40. * 模块界面样式 例如:宽,高
  41. * @type {Object}
  42. */
  43. var styles = {}
  44. /**
  45. * 模块状态,用于存储模块的状态 例如:收起,关闭
  46. * @type {Object}
  47. */
  48. var status = {
  49. initialized: false
  50. }
  51. /**
  52. * 初始化并订阅事件
  53. * @return {[type]} [description]
  54. */
  55. function init(modName) {
  56. //未初始化,初始化布局
  57. if (!status.initialized) {
  58. //设置容器布局
  59. setLayout();
  60. bindEvent();
  61. //订阅推送
  62. subscribe();
  63. status.initialized = true;
  64. } else {
  65. $('#userSideBar').show();
  66. }
  67. //设置zIndex 为最高
  68. var zIndex = ONEMAP.M.sideBar.getZIndex();
  69. $('#userSideBar').css({
  70. zIndex: 111111
  71. });
  72. }
  73. /**
  74. * 初始化布局
  75. */
  76. function setLayout() {
  77. $(tplLayout).appendTo($("#wrapper"));
  78. uinfoInit()
  79. //$("#userSideBar .username").html("用户名称:" + ONEMAP.D.user.name);
  80. $("#userSideBar .lgtime").html("登录时间:" + ONEMAP.D.user.current_login_at);
  81. $("#userSideBar .usdLeft li").removeClass("active");
  82. $("#userSideBar .usdLeft li.uInfo").addClass("active");
  83. $("#userSideBar .usdTab li").removeClass("active");
  84. $("#userSideBar .usdTab li.uInfo").addClass("active");
  85. //用户分类
  86. $("#userSideBar .usdLeft li.mng").hide();
  87. if (!ONEMAP.D.user.name) {
  88. ONEMAP.D.user.name = $("#userContent .username").text();
  89. }
  90. //拖拽
  91. $("#userSideBar .popup-ct").dragmove($('#userSideBar'));
  92. return;
  93. //用户中心显隐
  94. var role_list = ONEMAP.D.user.roles;
  95. $.each(role_list, function (i, t) {
  96. switch (t) {
  97. case "gcms chief editor":
  98. case "gcms adv editor":
  99. case "gcms editor":
  100. $("#userSideBar .usdLeft").show();//gcms
  101. break;
  102. case "admin":
  103. $("#userSideBar .usdLeft li.mng.tjUser").show();//数字战场访问统计系统
  104. $("#userSideBar .usdLeft li.mng.registeredheatmap").show();//热力图
  105. $("#userSideBar .usdLeft li.mng.qxUser").show();//全息地图数据管理系统
  106. $("#userSideBar .usdLeft li.mng.tyUser").show();//用户管理系统
  107. break;
  108. case "hmdms admin":
  109. $("#userSideBar .usdLeft li.mng.qxUser").show();//全息地图数据管理系统
  110. break;
  111. case "sys admin":
  112. case "security admin":
  113. $("#userSideBar .usdLeft li.mng.tyUser").show();//用户管理系统
  114. break;
  115. }
  116. })
  117. if (ONEMAP.D.user.roles.indexOf('developer') == -1) {
  118. $("#userSideBar .usdLeft li.mng.developerAuthentication").show();
  119. resetDeveloperAuthentication()
  120. } else {
  121. $("#userSideBar .usdLeft li.mng.developerAuthentication").hide();
  122. }
  123. };
  124. /**
  125. * 窗口布局重置
  126. * @type {Function}
  127. */
  128. function layoutResize() {
  129. };
  130. //获取authorization及用户列表
  131. function getAuthorization() {
  132. $.ajax({
  133. url: onemapUrlConfig.oauthServiceUrl + '/v1.0/account/auth',
  134. type: 'POST',
  135. dataType: 'json',
  136. data: JSON.stringify({
  137. email: ONEMAP.D.user.email,
  138. password: modValue.password
  139. }),
  140. headers: {
  141. "Accept": "application/json",
  142. "Content-type": "application/json"
  143. }
  144. })
  145. .done(function (data) {
  146. // console.log(data);
  147. modValue.Authorization = data.access_token;
  148. modValue.azType = data.token_type;
  149. // $.ajax({
  150. // url: onemapUrlConfig.oauthServiceUrl + '/v1.0/user/list',
  151. // type: 'GET',
  152. // dataType: 'json',
  153. // headers: {
  154. // "Authorization": modValue.azType + " " + modValue.Authorization
  155. // }
  156. // })
  157. // .done(function (data) {
  158. // modValue.listdata = data.data;
  159. // })
  160. })
  161. }
  162. //修改用户信息
  163. function putUserInfo(putdata) {
  164. $.ajax({
  165. url: onemapUrlConfig.oauthServiceUrl + '/v1.0/user?id=' + ONEMAP.D.user.id,
  166. type: 'PUT',
  167. dataType: 'json',
  168. data: putdata,
  169. headers: {
  170. "Authorization": modValue.azType + " " + modValue.Authorization
  171. }
  172. })
  173. .done(function (data) {
  174. if (data.status == 0) {
  175. ONEMAP.C.publisher.publish({
  176. type: 'success',
  177. message: '修改成功'
  178. }, 'noteBar::add');
  179. }
  180. uinfoInit(modValue.userInfoStatu);
  181. if (status.refresh) {
  182. alert("修改用户名/邮箱成功!即将刷新");
  183. ONEMAP.C.logout();
  184. window.location.reload();
  185. }
  186. })
  187. .fail(function (data) {
  188. console.log(data);
  189. data = JSON.parse(data.responseText);
  190. var alertInfos = "";
  191. $.each(data.errors, function (i, t) {
  192. alertInfos = alertInfos + i + ":";
  193. $.each(t, function (index, item) {
  194. alertInfos = alertInfos + item + ";"
  195. })
  196. })
  197. ONEMAP.C.publisher.publish({
  198. type: 'error',
  199. message: alertInfos
  200. }, 'noteBar::add');
  201. })
  202. }
  203. //属性赋值
  204. function shuxingfuzhi(a, b) {
  205. if (b == "" || b == null) {
  206. a.val("")
  207. } else {
  208. a.attr("value", b);
  209. a.val(b)
  210. }
  211. }
  212. //用户信息初始化
  213. function uinfoInit(uStatu) {
  214. $.ajax({
  215. url: onemapUrlConfig.oauthServiceUrl + '/v1.0/user?id=' + ONEMAP.D.user.id,
  216. type: 'GET',
  217. dataType: 'json'
  218. })
  219. .done(function (data) {
  220. _.merge(ONEMAP.D.user, data.data);
  221. // var name = data.data.nickname ? data.data.nickname : data.data.username
  222. shuxingfuzhi($("#userSideBar .baseInfList li.username input"), data.data.username)
  223. shuxingfuzhi($("#userSideBar .baseInfList li.nickname input"), data.data.nickname)
  224. shuxingfuzhi($("#userSideBar .baseInfList li.email input"), ONEMAP.D.user.email);
  225. shuxingfuzhi($("#userSideBar .baseInfList li.real_name input"), ONEMAP.D.user.real_name);
  226. shuxingfuzhi($("#userSideBar .baseInfList li.address input"), ONEMAP.D.user.address);
  227. shuxingfuzhi($("#userSideBar .baseInfList li.mobile input"), ONEMAP.D.user.mobile);
  228. $("#userContent .lgtop .username").html(data.data.nickname || data.data.username)
  229. if (ONEMAP.D.user.roles.indexOf('developer') == -1) {
  230. $("#userSideBar .baseInfList li.developer b").text("否");
  231. } else {
  232. $("#userSideBar .baseInfList li.developer b").text("是");
  233. }
  234. // //获取用户密码
  235. // $.ajax({
  236. // url: onemapUrlConfig.oauthServiceUrl + '/v1.0/user/resource_sharing_api?id=' + ONEMAP.D.user.id,
  237. // type: 'GET',
  238. // dataType: 'json'
  239. // })
  240. // .done(function (data) {
  241. // modValue.password = data.data.password;
  242. // getAuthorization()
  243. // })
  244. })
  245. $("#userSideBar .baseInfList li.org_name b").text(ONEMAP.D.user.org_name);
  246. $("#userSideBar .baseInfList li input").removeClass('edit');
  247. $("#userSideBar .usdTab .tipInfo").removeClass('active');
  248. $("#userSideBar .baseInfList li input").attr('readonly', 'readonly');
  249. $("#userSideBar .passchange li input").attr("value", "");
  250. $("#userSideBar .passchange li input").val("")
  251. if (uStatu == 1) {
  252. $("#userSideBar .usdTab .editInf").removeClass('hd');
  253. $("#userSideBar .usdTab .btns").removeClass('active');
  254. }
  255. }
  256. function compareData(putData, count, msg) {
  257. var ld = modValue.listdata;
  258. var a = 0,
  259. b = 0;
  260. var cd = "ok";
  261. for (var i = 0; i < ld.length; i++) {
  262. if (putData.username == ld[i].username) {
  263. a++;
  264. } else if (putData.email == ld[i].email) {
  265. b++;
  266. }
  267. if ((a + b) > (2 - count)) {
  268. if (a > 0 && msg == "username") cd = "用户名重复";
  269. if (b > 0 && msg == "email") cd = "邮箱重复";
  270. if (a > 0 && b > 0 && msg == "all") cd = "用户名、邮箱重复";
  271. break;
  272. }
  273. }
  274. return cd;
  275. }
  276. /**
  277. * 界面事件绑定
  278. * @return {[type]} [description]
  279. */
  280. function bindEvent() {
  281. //编辑用户信息
  282. $("#userSideBar .usdTab h1.tab span").off("click").on("click", function () {
  283. $("#userSideBar .usdTab h1.tab span").removeClass('active')
  284. $("#userSideBar .usdTab li.uInfo ul,#userSideBar .usdTab .editInf").removeClass('hd');
  285. $(this).addClass('active')
  286. if (!$(this).hasClass('baseInf')) {
  287. $("#userSideBar .baseInfList,#userSideBar .usdTab .editInf").addClass('hd')
  288. $("#userSideBar .usdTab .btns").addClass('active');
  289. modValue.userInfoStatu = 2;
  290. } else {
  291. $("#userSideBar .passchange").addClass('hd')
  292. $("#userSideBar .usdTab .btns").removeClass('active');
  293. modValue.userInfoStatu = 1;
  294. }
  295. uinfoInit();
  296. })
  297. $("#userSideBar .usdTab .editInf").off("click").on("click", function () {
  298. $(this).addClass('hd');
  299. $("#userSideBar .usdTab .btns").addClass('active');
  300. $("#userSideBar .baseInfList li input").addClass('edit');
  301. $("#userSideBar .baseInfList li input").removeAttr('readonly');
  302. $("#userSideBar .baseInfList li.username input").attr('readonly', 'readonly');
  303. $("#userSideBar .baseInfList li.username input").removeClass('edit');
  304. $("#userSideBar .baseInfList li.mobile input").attr('readonly', 'readonly');
  305. $("#userSideBar .baseInfList li.mobile input").removeClass('edit');
  306. $("#userSideBar .baseInfList li.developer").hide()
  307. })
  308. $("#userSideBar .usdTab .btns button.cancel").off("click").on("click", function () {
  309. uinfoInit(modValue.userInfoStatu);
  310. $("#userSideBar .baseInfList li.developer").show()
  311. })
  312. $("#userSideBar .baseInfList li input").on("focus", function () {
  313. $("#userSideBar .usdTab .tipInfo").removeClass('active');
  314. $("#userSideBar .usdTab .tipInfo span").text("")
  315. })
  316. $("#userSideBar .usdTab .btns button.submit").off("click").on("click", function () {
  317. if (modValue.userInfoStatu == 1) {
  318. var putData = {}
  319. //putData.username = $("#userSideBar .baseInfList li.username input").val();
  320. putData.username = ONEMAP.D.user.username;
  321. putData.nickname = $("#userSideBar .baseInfList li.nickname input").val();;
  322. putData.email = $("#userSideBar .baseInfList li.email input").val();
  323. putData.real_name = $("#userSideBar .baseInfList li.real_name input").val();
  324. putData.address = $("#userSideBar .baseInfList li.address input").val();
  325. putData.mobile = $("#userSideBar .baseInfList li.mobile input").val();
  326. var count = 0,
  327. msg = "";
  328. if (putData.username != ONEMAP.D.user.username || putData.email != ONEMAP.D.user.email) {
  329. if (putData.username != ONEMAP.D.user.username) {
  330. count++;
  331. msg = "username";
  332. }
  333. if (putData.email != ONEMAP.D.user.email) {
  334. count++;
  335. msg = "email";
  336. }
  337. if ((putData.email != ONEMAP.D.user.email) && (putData.username != ONEMAP.D.user.username)) {
  338. count++;
  339. msg = "all";
  340. }
  341. //var yz = compareData(putData, count, msg);
  342. var yz = "ok";
  343. if (yz == "ok") {
  344. putUserInfo(putData);
  345. status.refresh = true;
  346. } else {
  347. $("#userSideBar .usdTab .tipInfo").addClass('active');
  348. $("#userSideBar .usdTab .tipInfo span").text(yz)
  349. }
  350. } else {
  351. putUserInfo(putData);
  352. }
  353. } else {
  354. var oldPass = $("#userSideBar .passchange li input.oldPass").val();
  355. var newPass1 = $("#userSideBar .passchange li input.newPass1").val();
  356. var newPass2 = $("#userSideBar .passchange li input.newPass2").val();
  357. if (oldPass != modValue.password) {
  358. if (!$(".tipInfo").hasClass('active')) {
  359. $(".tipInfo").addClass('active');
  360. }
  361. $(".tipInfo span").text("原密码认证失败");
  362. } else if (newPass1 == "" || newPass2 == "") {
  363. if (!$(".tipInfo").hasClass('active')) {
  364. $(".tipInfo").addClass('active');
  365. }
  366. $(".tipInfo span").text("请输入新密码");
  367. } else if (newPass2 != newPass1) {
  368. if (!$(".tipInfo").hasClass('active')) {
  369. $(".tipInfo").addClass('active');
  370. }
  371. $(".tipInfo span").text("您输入的新密码不一致");
  372. } else {
  373. $(".tipInfo").removeClass('active');
  374. var pdata = {};
  375. pdata.password = newPass1;
  376. putUserInfo(pdata)
  377. }
  378. }
  379. })
  380. $("#userSideBar .passchange li input").on("change", function () {
  381. $(".tipInfo").removeClass('active');
  382. })
  383. //用户中心列表点击
  384. $("#userSideBar .usdLeft li").bind("click", function () {
  385. $("#userSideBar .usdLeft li").removeClass("active");
  386. $(this).addClass("active");
  387. $("#userSideBar .usdTab li").removeClass("active");
  388. var mid = $(this).attr("mid");
  389. if (mid == "uInfo") {
  390. $("#userSideBar .usdTab li.uInfo").addClass("active");
  391. } else if (mid == "uFavo") {
  392. $("#userSideBar .usdTab li.uFavo").addClass("active");
  393. } else if (mid == "uSet") {
  394. $("#userSideBar .usdTab li.uSet").addClass("active");
  395. require(['modDir/user/userSetting'], function (userSetting) {
  396. userSetting.init();
  397. });
  398. } else if (mid == "szzcUser") {
  399. $("#userSideBar .usdTab li.szzcUser").addClass("active");
  400. window.open(onemapUrlConfig.szzcUser);
  401. } else if (mid == "tyUser") {
  402. $("#userSideBar .usdTab li.tyUser").addClass("active");
  403. window.open(onemapUrlConfig.tyUser);
  404. } else if (mid == "qxUser") {
  405. $("#userSideBar .usdTab li.qxUser").addClass("active");
  406. window.open(onemapUrlConfig.qxUser);
  407. } else if (mid == "rzUser") {
  408. // $("#userSideBar .usdTab li.rzUser").addClass("active");
  409. // window.open(onemapUrlConfig.rzUser);
  410. } else if (mid == "tjUser") {
  411. $("#userSideBar .usdTab li.tjUser").addClass("active");
  412. window.open(onemapUrlConfig.tjUser);
  413. } else if (mid == "registeredheatmap") {
  414. $("#userSideBar .usdTab li.usigup").addClass("active");
  415. //getHeatmapData();
  416. } else if (mid == "developerAuthentication") {
  417. $("#userSideBar .usdTab li.uDeveloperAuth").addClass("active");
  418. resetDeveloperAuthentication()
  419. }
  420. })
  421. $("#uSigup .time_content input").bind('click', function () {
  422. var mid = $(this).attr('mid');
  423. var cid = $(this).attr('cid');
  424. $("#uSigup .time_content .active").removeClass('active');
  425. $(this).addClass('active');
  426. modValue.getHeatmapTime = mid;
  427. if (cid == 'tile') {
  428. getTileHeatmapData();
  429. } else {
  430. getHeatmapData();
  431. }
  432. })
  433. //在用户中心中展示我的收藏
  434. $("#userSideBar .usdLeft .uFavo").bind("click", function () {
  435. var options = {
  436. // modName: 'userFav',
  437. modName: 'userRoute',
  438. appdDom: 'userSideBar'
  439. }
  440. require(['modDir/user/userCenter'], function (userCenter) {
  441. userCenter.init(options);
  442. });
  443. ONEMAP.C.publisher.publish(options, 'showCenter');
  444. })
  445. //关闭用户中心
  446. $("#userSideBar .close").bind("click", function () {
  447. $("#userSideBar").hide();
  448. })
  449. //开发者用户认证
  450. $('.uDeveloperAuth .attestation').bind('click', function () {
  451. $('.authStep .step2').addClass('nowStep')
  452. $('.authStepContent>div').removeClass('nowStep')
  453. $('.authStepContent .step2').addClass('nowStep')
  454. if ($(this).hasClass('person')) {
  455. //个人 进入第二步
  456. $('.authStepContent .step2 .person').show();
  457. $('.authStepContent .step2 .enterprise').hide();
  458. } else {
  459. //企业 进入第二步
  460. $('.authStepContent .step2 .person').hide();
  461. $('.authStepContent .step2 .enterprise').show();
  462. }
  463. })
  464. $('.authStepContent .step2 .prev').bind("click", function () {
  465. resetDeveloperAuthentication()
  466. })
  467. $('.authStepContent .step2 .next').bind("click", function () {
  468. var ajaxData = {
  469. gcms_title: ONEMAP.D.user.username,
  470. name: $('.developerName').val(),
  471. IDCard: $('.IDNumber').val(),
  472. portrait: modValue.IDCardPicture1.getValue(),
  473. emblem: modValue.IDCardPicture2.getValue()
  474. }
  475. if (ajaxData.name.replace(/ /g, "") == "") {
  476. ONEMAP.C.publisher.publish({
  477. type: 'error',
  478. message: '姓名不能为空!'
  479. }, 'noteBar::add');
  480. return
  481. }
  482. if (ajaxData.IDCard.replace(/ /g, "") == "") {
  483. ONEMAP.C.publisher.publish({
  484. type: 'error',
  485. message: '身份证号不能为空!'
  486. }, 'noteBar::add');
  487. return
  488. }
  489. if (ajaxData.portrait == "") {
  490. ONEMAP.C.publisher.publish({
  491. type: 'error',
  492. message: '身份证人像面未上传!'
  493. }, 'noteBar::add');
  494. return
  495. }
  496. if (ajaxData.emblem == "") {
  497. ONEMAP.C.publisher.publish({
  498. type: 'error',
  499. message: '身份证国徽面未上传!'
  500. }, 'noteBar::add');
  501. return
  502. }
  503. var ajaxUrl = onemapUrlConfigNetwork.gcmsServiceUrl + '/content/developer_renzhen?uploadpath=' + modValue._uploadTempDir;
  504. $.ajax({
  505. url: ajaxUrl,
  506. type: 'POST',
  507. dataType: 'json',
  508. data: ajaxData
  509. })
  510. .done(function (data) {
  511. if (data.code == 4) {
  512. ONEMAP.C.noPermission('addArticle', '无权限添加内容');
  513. }
  514. if (data.code == 3) {
  515. ONEMAP.C.logout('addArticle');
  516. }
  517. if (data.code == 0) {
  518. ONEMAP.C.publisher.publish({ type: 'success', message: '上传认证成功!' }, 'noteBar::add');
  519. $('.authStep .step3').addClass('nowStep')
  520. $('.authStepContent>div').removeClass('nowStep')
  521. $('.authStepContent .step3').addClass('nowStep')
  522. $('.uploadBackMessage').html('上传认证成功,等待人工审核。5s后自动返回')
  523. setTimeout(function () {
  524. if ($('.authStep .step3').hasClass('nowStep')) {
  525. resetDeveloperAuthentication()
  526. }
  527. }, 5000);
  528. } else {
  529. ONEMAP.C.publisher.publish({ type: 'error', message: data['message'] }, 'noteBar::add');
  530. $('.uploadBackMessage').html('上传认证失败,返回重新填写。5s后自动返回')
  531. setTimeout(function () {
  532. if ($('.authStep .step3').hasClass('nowStep')) {
  533. resetDeveloperAuthentication()
  534. }
  535. }, 5000);
  536. }
  537. })
  538. .fail(function () {
  539. ONEMAP.C.publisher.publish({ type: 'error', message: '上传认证失败!' }, 'noteBar::add');
  540. $('.uploadBackMessage').html('上传认证失败,返回重新填写。5s后自动返回')
  541. setTimeout(function () {
  542. if ($('.authStep .step3').hasClass('nowStep')) {
  543. resetDeveloperAuthentication()
  544. }
  545. }, 5000);
  546. });
  547. })
  548. $('.authStepContent .step3 .back').bind("click", function () {
  549. resetDeveloperAuthentication()
  550. })
  551. }
  552. /**
  553. * [getTileHeatmapData description]
  554. * 获取用户访问瓦片统计热力图数据
  555. * @return {[type]} [description]
  556. */
  557. function getTileHeatmapData() {
  558. ONEMAP.V.loading.load();
  559. $.ajax({
  560. type: "get",
  561. dataType: 'json',
  562. url: onemapUrlConfig.getTileHeatmapUrl + "/api/heatmap/" + modValue.getHeatmapTime,
  563. success: function (data) {
  564. if ($("#layerControlMenu .myLayers span[title='瓦片访问热力图']").length != 0)
  565. $($("#layerControlMenu .myLayers span[title='瓦片访问热力图']").siblings(".close")[0]).click()
  566. if ($("#layerControlMenu .myLayers span[title='用户独立访问热力图']").length != 0)
  567. $($("#layerControlMenu .myLayers span[title='用户独立访问热力图']").siblings(".close")[0]).click()
  568. addHeatmapTip('瓦片访问热力图');
  569. modValue.heatmapType = 2;
  570. data = eval("(" + data.data + ")").aggregations.level8bucket.buckets;
  571. var newHeatData = [];
  572. $.each(data, function (i, t) {
  573. var latlng = t.hits.hits.hits[0]._source;
  574. newHeatData.push({
  575. lat: latlng.lat,
  576. lng: latlng.lng,
  577. count: t.doc_count
  578. })
  579. })
  580. modValue.heatData = {
  581. max: 8,
  582. data: newHeatData
  583. }
  584. if (modValue.appendToMyLayer == null) {
  585. var options = {
  586. action: "add",
  587. mod: 'userheatmap',
  588. DOM: {
  589. name: '瓦片访问热力图',
  590. type: "group",
  591. guid: 'userheatmap'
  592. }
  593. }
  594. modValue.appendToMyLayer = ONEMAP.M.myLayers.myLayerControl(options);
  595. ONEMAP.C.publisher.subscribe(controlMyLayer, modValue.appendToMyLayer);
  596. }
  597. modValue.cfg["gradient"] = {
  598. 0.25: "rgb(0,0,255)",
  599. 0.55: "rgb(0,255,0)",
  600. 0.85: "rgb(255,255,0)",
  601. 1.0: "rgb(255,0,0)"
  602. }
  603. modValue.hotLayer = new HeatmapOverlay(modValue.cfg);
  604. modValue.hotLayer.addTo(map2DViewer.map);
  605. modValue.hotLayer.setData(modValue.heatData);
  606. map23DControl.setView({
  607. center: {
  608. lat: 39,
  609. lng: 116
  610. },
  611. zoom: 4
  612. })
  613. },
  614. error: function (errorData) {
  615. ONEMAP.V.loading.loaded();
  616. }
  617. });
  618. }
  619. /**
  620. * [getHeatmapData description]
  621. * 获取热力图数据
  622. * @return {[type]} [description]
  623. */
  624. function getHeatmapData() {
  625. ONEMAP.V.loading.load();
  626. $.ajax({
  627. type: "get",
  628. dataType: 'json',
  629. url: onemapUrlConfig.getUserHeatmapUrl + "/heatmap/" + modValue.getHeatmapTime,
  630. success: function (data) {
  631. if ($("#layerControlMenu .myLayers span[title='瓦片访问热力图']").length != 0)
  632. $($("#layerControlMenu .myLayers span[title='瓦片访问热力图']").siblings(".close")[0]).click()
  633. if ($("#layerControlMenu .myLayers span[title='用户独立访问热力图']").length != 0)
  634. $($("#layerControlMenu .myLayers span[title='用户独立访问热力图']").siblings(".close")[0]).click()
  635. addHeatmapTip('用户独立访问热力图');
  636. modValue.heatmapType = 1;
  637. if (modValue.appendToMyLayer == null) {
  638. var options = {
  639. action: "add",
  640. mod: 'userheatmap',
  641. DOM: {
  642. name: '用户独立访问热力图',
  643. type: "group",
  644. guid: 'userheatmap'
  645. }
  646. }
  647. modValue.appendToMyLayer = ONEMAP.M.myLayers.myLayerControl(options);
  648. ONEMAP.C.publisher.subscribe(controlMyLayer, modValue.appendToMyLayer);
  649. }
  650. var newHeatData = [];
  651. modValue.GroupLayerGuid = map23DControl.group({
  652. action: 'add',
  653. clustering: false //关键 开启聚合
  654. })
  655. $.each(data, function (i, t) {
  656. for (var k = 0; k < t.count; k++) {
  657. newHeatData.push({
  658. lat: t.lat,
  659. lng: t.lon,
  660. })
  661. }
  662. var markerOp = {
  663. action: "add",
  664. groupId: modValue.GroupLayerGuid,
  665. geojson: {
  666. "type": "Feature",
  667. "properties": {
  668. iconUrl: '../../../images/layout/marker/roadsign_icon_1_b.png',
  669. iconSize: [60, 39],
  670. iconAnchor: [30, 39],
  671. popupAnchor: [0, -39],
  672. popupContent: creatPopupHtml(t.count)
  673. },
  674. "geometry": {
  675. "type": "Point",
  676. "coordinates": [t.lon, t.lat]
  677. }
  678. }
  679. }
  680. map23DControl.marker(markerOp);
  681. })
  682. map2DViewer.map.setZoom(4)
  683. modValue.hotLayer = L.heatLayer(newHeatData, {
  684. maxZoom: 7,
  685. radius: 40,
  686. blur: 30,
  687. shadowBlur: 25,
  688. min: 1,
  689. max: 25,
  690. gradient: {
  691. 0.25: "rgb(0,0,255)",
  692. 0.55: "rgb(0,255,0)",
  693. 0.85: "rgb(255,255,0)",
  694. 1.0: "rgb(255,0,0)"
  695. }
  696. });
  697. modValue.hotLayer.addTo(map2DViewer.map);
  698. userHeatlayerMarker(map2DViewer.map.getZoom())
  699. },
  700. error: function (errorData) {
  701. ONEMAP.V.loading.loaded();
  702. }
  703. });
  704. }
  705. function creatPopupHtml(options) {
  706. var popupHtml = '<div class="popup_html mini">' +
  707. ' <div class="popup-lt"></div>' +
  708. ' <div class="popup-lb"></div>' +
  709. ' <div class="popup-rt"></div>' +
  710. ' <div class="popup-rb"></div>' +
  711. ' <div class="popup-ct" style="text-indent:15px;line-height:48px">' +
  712. ' </div>' +
  713. ' <div class="popup-cb" style="padding-bottom:20px;color:#666666 !important"><div class="visitCount">访问次数:' + options + '</div></div>' +
  714. '</div>'
  715. return popupHtml;
  716. }
  717. function userHeatlayerMarker(zoom) {
  718. if (zoom >= 6) {
  719. modValue.markerOpacity = 1
  720. map2DViewer.group({
  721. action: 'show',
  722. guid: modValue.GroupLayerGuid
  723. })
  724. } else {
  725. modValue.markerOpacity = 0
  726. map2DViewer.group({
  727. action: 'hide',
  728. guid: modValue.GroupLayerGuid
  729. })
  730. }
  731. if (modValue.heatmapType == 1) {
  732. var option = {};
  733. if (zoom <= 5) {
  734. option.max = 10;
  735. } else if (zoom > 5 && zoom <= 7) {
  736. option.max = 50;
  737. } else if (zoom > 7) {
  738. option.max = 80;
  739. }
  740. modValue.hotLayer.setOptions(option);
  741. }
  742. }
  743. function controlMyLayer(options) {
  744. switch (options.action) {
  745. case 'remove':
  746. remove();
  747. break;
  748. case 'opacity':
  749. setGropOpacity(options);
  750. break;
  751. }
  752. }
  753. function setGropOpacity(options) {
  754. options = options.options;
  755. if (options.opacity == 1) {
  756. $(".leaflet-heatmap-layer, .heatmap-canvas").show();
  757. if (modValue.GroupLayerGuid)
  758. map2DViewer.group({
  759. action: 'show',
  760. guid: modValue.GroupLayerGuid
  761. })
  762. } else if (options.opacity == 0) {
  763. $(".leaflet-heatmap-layer, .heatmap-canvas").hide();
  764. if (modValue.GroupLayerGuid)
  765. map2DViewer.group({
  766. action: 'hide',
  767. guid: modValue.GroupLayerGuid
  768. })
  769. }
  770. }
  771. function remove() {
  772. if (modValue.hotLayer) {
  773. modValue.hotLayer.onRemove(map2DViewer.map);
  774. }
  775. if (modValue.GroupLayerGuid) {
  776. map2DViewer.group({
  777. action: 'remove',
  778. guid: modValue.GroupLayerGuid
  779. })
  780. }
  781. if ($('#heatmapTip').length > 0)
  782. $('#heatmapTip').remove();
  783. $(".registeredheatmap").removeClass('active');
  784. $("#uSigup .time_content .active").removeClass('active');
  785. modValue.GroupLayerGuid = null
  786. modValue.appendToMyLayer = null;
  787. modValue.hotLayer = null;
  788. //取消订阅
  789. unSubscribe();
  790. }
  791. function addHeatmapTip(text) {
  792. var html = '<div id="heatmapTip">' +
  793. ' <div class="heatmapTipClose">×</div>' + text + '</div>'
  794. $('body').append(html);
  795. $('#heatmapTip .heatmapTipClose').unbind('click').bind("click", function () {
  796. $(this).parent().remove();
  797. })
  798. }
  799. function resetDeveloperAuthentication() {
  800. $('.developAuthContent .nowStep').removeClass('nowStep')
  801. $('.developAuthContent .step1').addClass('nowStep')
  802. $('.developAuthContent input').val('');
  803. $('#portrait').empty()
  804. $('#emblem').empty()
  805. modValue._uploadTempDir = generateMixed(20);
  806. var op1 = {
  807. containId: '#portrait',
  808. id: "portrait",
  809. label: "",
  810. tips: '支持jpg,png,gif格式',
  811. uploadPath: onemapUrlConfigNetwork.gcmsServiceUrl + '/file/upload/tmp?path=' + modValue._uploadTempDir,
  812. verifyEmpty: 0
  813. }
  814. var op2 = {
  815. containId: '#emblem',
  816. id: "emblem",
  817. label: "",
  818. tips: '支持jpg,png,gif格式',
  819. uploadPath: onemapUrlConfigNetwork.gcmsServiceUrl + '/file/upload/tmp?path=' + modValue._uploadTempDir,
  820. verifyEmpty: 0
  821. }
  822. //图片地址
  823. op1['value'] = ""
  824. op2['value'] = ""
  825. modValue.IDCardPicture1 = new ONEMAP.M.field_picture(op1)
  826. modValue.IDCardPicture2 = new ONEMAP.M.field_picture(op2)
  827. }
  828. /** * 获取随机字符串 */
  829. function generateMixed(n) {
  830. var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  831. var res = '';
  832. for (var i = 0; i < n; i++) {
  833. var id = Math.ceil(Math.random() * 35);
  834. res += chars[id];
  835. }
  836. return res;
  837. }
  838. /**
  839. * 注册订阅
  840. * @type {Function}
  841. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  842. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  843. */
  844. function subscribe() {
  845. ONEMAP.C.publisher.subscribe(userHeatlayerMarker, 'userHeatlayerMarker');
  846. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  847. }
  848. /**
  849. * 取消订阅
  850. * @type {Function}
  851. * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  852. */
  853. function unSubscribe() {
  854. //ONEMAP.C.publisher.unSubscribe(remove, 'cleanMap');
  855. ONEMAP.C.publisher.unSubscribe(controlMyLayer, modValue.appendToMyLayer)
  856. }
  857. return ONEMAP.M.userSideBar = {
  858. init: init,
  859. layoutResize: layoutResize
  860. }
  861. });