map.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. import {
  2. imgUrl
  3. } from "../api/request"
  4. import{
  5. getMapDataType
  6. } from "../api/yxna-api"
  7. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  8. const popType = [
  9. [
  10. [{"name":"受理场所","dictType":"jzs,bms","type":""}, {"name":"查阅场所","dictType":"cycsbms,slcsjzs","type":""},],
  11. [{"name":"区级政务服务中心","dictType":"xzfwzxs","type":""}, {"name":"镇(街道)便民服务中心","dictType":"ggfwzxs","type":""}, {"name":"村(社区)便民服务站","dictType":"bmfwzxs","type":""}, {"name":"生源地助学贷款办理点","dictType":"dkblds","type":""}],
  12. [{"name":"党群服务中心","dictType":"dqfwzxs","type":""}],
  13. [{"name":"职业教育学校","dictType":"zyyxs","type":""}, {"name":"特殊教育学校","dictType":"xxs","type":""}, {"name":"高等院校","dictType":"dxs","type":""}, {"name":"小学","dictType":"xxs","type":"小学"}, {"name":"中学","dictType":"xxs","type":""}, {"name":"幼儿园","dictType":"yeys","type":""}, {"name":"教育考试中心","dictType":"","type":"jykszxs"}]
  14. ],
  15. [
  16. [{"name":"村卫生室","dictType":"","type":"cwsss"}, {"name":"社区卫生服务站","dictType":"","type":"sqwsfwzs"}, {"name":"儿科诊疗服务机构","dictType":"ekzlfwjgs","type":""}, {"name":"狂犬病、破伤风处置门诊","dictType":"kqbpsfczmzs","type":""}, {"name":"免疫规划预防接种门诊","dictType":"myghyfjzmzs","type":""}, {"name":"二级医疗机构","dictType":"ejyljgs","type":""}, {"name":"三级医疗机构","dictType":"sjyljgs","type":""}, {"name":"社区卫生服务机构","dictType":"sqwsfwjgs","type":""}, {"name":"职业病诊断机构","dictType":"zybzdjgs","type":""}, {"name":"助产医疗机构","dictType":"zcyljg","type":""}, {"name":"产科门诊服务机构","dictType":"ckmzfwjgs","type":""}, {"name":"医疗保障事务中心","dictType":"ybs","type":""}],
  17. [{"name":"派出所","dictType":"pcss","type":""}, {"name":"出入境业务办理机构","dictType":"crjywbljgs","type":""}],
  18. [{"name":"交通支大队","dictType":"jtxljcdds","type":""}, {"name":"交通违法处理机构","dictType":"jtwfcljgs","type":""}, {"name":"交通事故处理机构","dictType":"jtsgcljgs","type":""}, {"name":"车管所","dictType":"cgss","type":""}, {"name":"机动车检测场所","dictType":"jdcjccss","type":""}, {"name":"驾驶人体检医院","dictType":"jsrtjzs","type":""}, {"name":"车驾管社会服务站","dictType":"cjgshfwzs","type":""}],
  19. [{"name":"就业和人才中心","dictType":"jyhrczxs","type":""}, {"name":"社会保险事务中心","dictType":"shbxswzxs","type":""}]
  20. ],
  21. [
  22. [{"name":"养老机构","dictType":"ylfwjgs","type":""}],
  23. [{"name":"婚姻登记机构","dictType":"hydjcs","type":""}, {"name":"殡仪服务机构","dictType":"byfwjgs","type":""}],
  24. [],
  25. []
  26. ],
  27. [
  28. [],
  29. [],
  30. [],
  31. [{"name":"图书馆","dictType":"tsgs","type":""}, {"name":"文化馆","dictType":"whgs","type":""}, {"name":"文管所","dictType":"wgss","type":""}, {"name":"公共体育馆","dictType":"ggtys","type":""}, {"name":"旅游景点","dictType":"jqs","type":""}, {"name":"公园","dictType":"gys","type":""}]
  32. ],
  33. [
  34. [{"name":"公证处","dictType":"gzcs","type":""}, {"name":"司法鉴定机构","dictType":"sfjdjgs","type":""}, {"name":"基层司法所","dictType":"jcfwfwss","type":""}, {"name":"法律援助机构","dictType":"flyzzxs","type":""}, {"name":"矫正中心","dictType":"jzzxs","type":""}],
  35. [{"name":"残疾人服务中心","dictType":"cjrfwzxs","type":""}, {"name":"定点残疾人服务机构","dictType":"qtcjrfwzxs","type":""}],
  36. [],
  37. [{"name":"商圈","dictType":"sqs","type":""}, {"name":"购物中心","dictType":"gwzxs","type":""}, {"name":"酒店","dictType":"jds","type":""}]
  38. ],
  39. [
  40. [],
  41. [],
  42. []
  43. ]
  44. ]
  45. let BMap = {};
  46. let x = null;
  47. let y = null;
  48. const INIT_MARKER = {
  49. latitude: 0,
  50. longitude: 0,
  51. iconPath: imgUrl+"/location.png",
  52. width: '34px',
  53. height: '34px',
  54. rotate: 0,
  55. alpha: 1
  56. };
  57. Page({
  58. data: {
  59. imgUrl: imgUrl,
  60. markers: [INIT_MARKER],
  61. latitude: '',
  62. longitude: '',
  63. type: [
  64. [{ "id": 1, "name": "政务公开", "image": "fgk.png","dictType":"" }, { "id": 2, "name": "政务服务", "image": "fzwfw.png" ,"dictType":""}, { "id": 3, "name": "党群服务", "image": "fdqfwzx.png" ,"dictType":""},{ "id": 4, "name": "教育资源", "image": "fjy.png","dictType":"" }],
  65. [{ "id": 1, "name": "医疗卫生", "image": "fyl.png" ,"dictType":""}, { "id": 2, "name": "户籍管理", "image": "fhjgl.png" ,"dictType":""}, { "id": 3, "name": "交通服务", "image": "fjtfw.png" ,"dictType":""},{ "id": 4, "name": "社会保障", "image": "fshbz.png","dictType":"" }],
  66. [{ "id": 1, "name": "养老服务", "image": "fylfw.png" ,"dictType":""}, { "id": 2, "name": "民政服务", "image": "fmzfw.png" ,"dictType":""}, { "id": 3, "name": "办税服务", "image": "fbsfwt.png" ,"dictType":"bsfwts"},{ "id": 4, "name": "市场监管", "image": "fscjd.png","dictType":"scjdgljs" }],
  67. [{ "id": 1, "name": "住房保障", "image": "fgzf.png","dictType":"fwglzxs" }, { "id": 2, "name": "不动产登记", "image": "fbdcdj.png" ,"dictType":"bdcdjzxbsdts"}, { "id": 3, "name": "住房公积金", "image": "fgjj.png" ,"dictType":"gjjs"},{ "id": 4, "name": "文体旅游", "image": "fwtly.png","dictType":"" }],
  68. [{ "id": 1, "name": "司法服务", "image": "fsffw.png" ,"dictType":""}, { "id": 2, "name": "助疾服务", "image": "fcjr.png" ,"dictType":""}, { "id": 3, "name": "产业园区", "image": "fcyy.png" ,"dictType":"cyys"},{ "id": 4, "name": "商业服务", "image": "fbmfw.png","dictType":"" }],
  69. [{ "id": 1, "name": "便民公厕", "image": "fgc.png" ,"dictType":"gcs"}, { "id": 2, "name": "停车泊车", "image": "ftc.png" ,"dictType":"tcs"}, { "id": 3, "name": "直饮水点", "image": "zysd.png" ,"dictType":"zysd"}]
  70. ],
  71. popData: [{ "popName": "", "data": [] }],
  72. showIndex: false,
  73. showSearch: true,
  74. showTraffic: true,
  75. height: 0,
  76. searchVal: '',
  77. loadValue: '',
  78. trafficStart: '',
  79. trafficEnd: '',
  80. index: 0,
  81. isList: true,
  82. showSet: false,
  83. trafficType: 0
  84. },
  85. onLoad: function (options) {
  86. this.setData({
  87. height: wx.getSystemInfoSync().windowHeight
  88. })
  89. console.log(options);
  90. if (options.se) {
  91. this.setData({
  92. loadValue: options.se,
  93. showTraffic: false
  94. });
  95. }else{
  96. this.setData({
  97. showTraffic: true
  98. })
  99. }
  100. // searchVal
  101. },
  102. onReady:function () {
  103. this.loadItem();
  104. this.setMap();
  105. // setTimeout(function () {
  106. // }.bind(this), 1000);
  107. },
  108. async setMap(){
  109. var that = this;
  110. BMap = await new QQMapWX({
  111. key: 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'
  112. });
  113. wx.getLocation({
  114. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  115. success(res) {
  116. const latitude = res.latitude
  117. const longitude = res.longitude
  118. that.setData({
  119. latitude: latitude,
  120. longitude: longitude,
  121. trafficStart: "我的位置",
  122. markers: [{
  123. latitude: latitude,
  124. longitude: longitude,
  125. iconPath: "/location.png",
  126. width: '30px',
  127. height: '30px',
  128. rotate: 0,
  129. alpha: 1
  130. }]
  131. });
  132. }
  133. });
  134. },
  135. popview(e) {
  136. let x = e.currentTarget.dataset.index;
  137. let y = e.currentTarget.dataset.id;
  138. let pop = popType[x][y - 1]
  139. if (pop.length > 0) {
  140. // this.setTypeDateToPop2(pop)
  141. this.setData({
  142. popData: pop,
  143. showIndex: true
  144. });
  145. } else {
  146. let pop = this.data.type[x][y - 1]
  147. // console.log(pop);
  148. this.setDateToPop(pop)
  149. this.setData({
  150. showTraffic: false,
  151. showIndex: false
  152. })
  153. }
  154. },
  155. setTypeDateToPop2: function (pop) {
  156. let arr = [];
  157. pop.forEach(e => {
  158. arr.push({
  159. "popName": e.name
  160. })
  161. })
  162. this.setData({
  163. popData: arr
  164. })
  165. },
  166. setDateToPop: function (pop) {
  167. let arr = [];
  168. let params ={
  169. "dictType": pop.dictType,
  170. "type": "",
  171. "title": "",
  172. } ;
  173. getMapDataType(params).then((res) => {
  174. console.log(res.data[0].tel);
  175. let data = []
  176. res.data.forEach((item) => {
  177. if(item.tel!=null && item.tel!=""){
  178. item.tel = item.tel.split(";")
  179. }
  180. data.push(item)
  181. });
  182. this.setData({
  183. popData: data,
  184. })
  185. });
  186. },
  187. closePopup() {
  188. this.setData({
  189. showIndex: false
  190. })
  191. },
  192. changeInfo(e) {
  193. // console.log(e.currentTarget.dataset.data);
  194. let dataitem = e.currentTarget.dataset.data;
  195. console.log(dataitem);
  196. let params ={
  197. "dictType":dataitem.dictType,
  198. "type": "",
  199. "title": "",
  200. };
  201. getMapDataType(params).then((res) => {
  202. let data = []
  203. switch (dataitem.name) {
  204. case "小学":
  205. case "特殊教育学校":
  206. res.data.forEach((item) => {
  207. if (item.type == dataitem.name) {
  208. data.push(item)
  209. }
  210. });
  211. break;
  212. case "中学":
  213. res.data.forEach((item) => {
  214. if (item.type == dataitem.name||item.specialtype == dataitem.name) {
  215. data.push(item)
  216. }
  217. });
  218. break;
  219. default:
  220. data = res.data;
  221. break;
  222. }
  223. let renderData = []
  224. data.forEach((item) => {
  225. if(item.tel!=null && item.tel!=""){
  226. item.tel = item.tel.split(";")
  227. }
  228. renderData.push(item)
  229. });
  230. this.setData({
  231. popData: renderData,
  232. showTraffic: false,
  233. showIndex: false
  234. })
  235. });
  236. },
  237. /**
  238. * 拨打电话
  239. * @param {*} e
  240. */
  241. callNumber(e) {
  242. let phoneNumber = e.currentTarget.dataset.value;
  243. wx.makePhoneCall({
  244. phoneNumber: phoneNumber,
  245. });
  246. },
  247. /**
  248. * list跳转info
  249. *
  250. */
  251. changeItem(e) {
  252. let that = this;
  253. console.info(e)
  254. let value = e.currentTarget.dataset.value;
  255. if (value === "none") {
  256. that.setData({
  257. isList: false,
  258. showSearch: false,
  259. showSet: false,
  260. });
  261. } else {
  262. // 控制公交自驾选中状态
  263. let type = e.currentTarget.dataset.type;
  264. if (type==0){
  265. if(e.detail.value==0){
  266. changeValue = "transit";
  267. }else{
  268. changeValue = "driving";
  269. }
  270. }
  271. that.setData({
  272. trafficType: type,
  273. showSet: false
  274. });
  275. that.setData({
  276. isList: false,
  277. showSearch: false,
  278. showSet: true
  279. });
  280. }
  281. // 详情赋值
  282. let index = e.currentTarget.dataset.index;
  283. let item = that.data.popData[index];
  284. console.info(item);
  285. let address='';
  286. if (item.address.search("重庆")==-1) {
  287. address = "重庆" + item.address;
  288. }else{
  289. address = item.address;
  290. }
  291. that.setData({
  292. detail_dep: item.dep,
  293. detail_content: item.content,
  294. detail_img: item.img,
  295. detail_address: item.address,
  296. detail_time: item.time,
  297. detail_tel: item.tel,
  298. detail_index: index,
  299. trafficEnd: address
  300. });
  301. BMap.geocoder({
  302. address: address,
  303. success: function (data) {
  304. var res = data.result
  305. that.setData({
  306. latitude: res.location.lat,
  307. longitude: res.location.lng,
  308. markers: [{
  309. latitude: res.location.lat,
  310. longitude: res.location.lng,
  311. iconPath: "/location.png",
  312. width: '30px',
  313. height: '30px',
  314. rotate: 0,
  315. alpha: 1
  316. }]
  317. });
  318. }
  319. });
  320. },
  321. /**
  322. * 打开全景地图
  323. * @param {*} e
  324. */
  325. openVR(e) {
  326. wx.navigateTo({
  327. url: '../map-vr/map-vr',
  328. });
  329. },
  330. getSearchVal(e) {
  331. this.setData({
  332. searchVal: e.detail.value
  333. });
  334. },
  335. loadItem() {
  336. const that = this;
  337. let searchVal = this.data.loadValue;
  338. let datatype = this.data.type;
  339. if (!searchVal) {
  340. return;
  341. }
  342. wx.showToast({
  343. title: '加载中...',
  344. icon: 'loading'
  345. });
  346. let x =-1
  347. let y =-1
  348. for (let i = 0; i < datatype.length; i++) {
  349. for (let j = 0; j < datatype[i].length; j++) {
  350. if (datatype[i][j].name == searchVal) {
  351. x = i
  352. y = j
  353. break;
  354. }
  355. }
  356. if(x!=-1){
  357. break;
  358. }
  359. }
  360. let arr = popType[x][y]
  361. let searcharr = ""
  362. arr.forEach((item) => {
  363. searcharr+= item.dictType+","
  364. })
  365. searcharr = searcharr.substring(0,searcharr.length-1)
  366. let params ={
  367. "dictType": searcharr,
  368. "type": "",
  369. "title": "",
  370. } ;
  371. getMapDataType(params).then((res) => {
  372. let data = []
  373. res.data.forEach((item) => {
  374. if(item.tel!=null && item.tel!=""){
  375. item.tel = item.tel.split(";")
  376. }
  377. data.push(item)
  378. });
  379. this.setData({
  380. // showTraffic: false,
  381. popData: data,
  382. })
  383. });
  384. // 搜索结果
  385. wx.hideToast({
  386. success: (res) => {},
  387. });
  388. },
  389. /**
  390. * 顶部搜索点击事件
  391. * @param {*} e
  392. */
  393. searchTap(e) {
  394. let searchVal = this.data.searchVal;
  395. wx.showToast({
  396. title: '加载中...',
  397. icon: 'loading'
  398. });
  399. let params ={
  400. "dictType": "",
  401. "type": "",
  402. "title": searchVal,
  403. };
  404. this.setData({
  405. showTraffic: false
  406. })
  407. getMapDataType(params).then((res) => {
  408. let data = []
  409. res.data.forEach((item) => {
  410. if(item.tel!=null && item.tel!=""){
  411. item.tel = item.tel.split(";")
  412. }
  413. data.push(item)
  414. });
  415. this.setData({
  416. showTraffic: false,
  417. popData: data,
  418. })
  419. });
  420. // 搜索结果
  421. wx.hideToast({
  422. success: (res) => {},
  423. });
  424. },
  425. getTrafficStart(e) {
  426. this.setData({
  427. trafficStart: e.detail.value
  428. });
  429. },
  430. getTrafficEnd(e) {
  431. this.setData({
  432. trafficEnd: e.detail.value
  433. });
  434. },
  435. /**
  436. * 搜索进行交通路线规划
  437. * @param {*} e
  438. */
  439. searchTrafficTap(e) {
  440. const that = this;
  441. // console.log(that.data.trafficType);
  442. let trafficType = that.data.trafficType;
  443. if (trafficType == 0) {
  444. changeValue = "transit";
  445. } else {
  446. changeValue = "driving";
  447. }
  448. let trafficStart = that.data.trafficStart;
  449. let trafficEnd = that.data.trafficEnd;
  450. if (!trafficStart || !trafficEnd) {
  451. wx.showToast({
  452. title: '请输入起点和终点',
  453. icon: 'none'
  454. });
  455. return;
  456. }
  457. console.info(trafficStart, trafficEnd);
  458. BMap.geocoder({
  459. address: trafficEnd,
  460. success: function (data) {
  461. var res = data.result
  462. // console.log(res);
  463. let key = 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'; //使用在腾讯位置服务申请的key
  464. let referer = '掌上南岸'; //调用插件的app的名称
  465. // 终点
  466. let endPoint = JSON.stringify({
  467. 'name': trafficEnd,
  468. 'latitude': res.location.lat,
  469. 'longitude': res.location.lng
  470. });
  471. wx.navigateTo({
  472. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint + "&mode=" + changeValue
  473. });
  474. }
  475. });
  476. },
  477. backSearch() {
  478. let that =this
  479. if (!that.data.isList) {
  480. this.setData({
  481. isList: true,
  482. showSearch: true,
  483. showSet: false
  484. });
  485. } else {
  486. if (!that.data.showTraffic) {
  487. that.setData({
  488. showTraffic: true,
  489. showSearch: true,
  490. searchVal: ''
  491. });
  492. }
  493. }
  494. wx.getLocation({
  495. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  496. success (res) {
  497. const latitude = res.latitude
  498. const longitude = res.longitude
  499. that.setData({
  500. latitude: latitude,
  501. longitude:longitude,
  502. trafficStart:"我的位置",
  503. markers:[{
  504. latitude: latitude,
  505. longitude: longitude,
  506. iconPath: imgUrl+"/location.png",
  507. width: '34px',
  508. height: '34px',
  509. rotate: 0,
  510. alpha: 1
  511. }]
  512. });
  513. }
  514. })
  515. changeValue = "transit";
  516. },
  517. onchange(e) {
  518. let that = this;
  519. if (e.detail.value == 0) {
  520. that.setData({
  521. trafficType: 0
  522. });
  523. changeValue = "transit";
  524. } else {
  525. that.setData({
  526. trafficType: 1
  527. });
  528. changeValue = "driving";
  529. }
  530. }
  531. });
  532. let changeValue = "transit";