userSideBar.js 39 KB

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