map.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. page:0,
  85. limit:15
  86. },
  87. onLoad: function (options) {
  88. this.setData({
  89. height: wx.getSystemInfoSync().windowHeight
  90. })
  91. console.log(options);
  92. if (options.se) {
  93. this.setData({
  94. loadValue: options.se,
  95. showTraffic: false
  96. });
  97. }else{
  98. this.setData({
  99. showTraffic: true
  100. })
  101. }
  102. // searchVal
  103. },
  104. onReady:function () {
  105. this.loadItem();
  106. this.setMap();
  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. wx.showToast({
  174. title: '加载中...',
  175. icon: 'loading'
  176. });
  177. getMapDataType(params).then((res) => {
  178. console.log(res.data[0].tel);
  179. let data = []
  180. res.data.forEach((item) => {
  181. if(item.tel!=null && item.tel!=""){
  182. item.tel = item.tel.split(";")
  183. }
  184. data.push(item)
  185. });
  186. this.setData({
  187. popData: data,
  188. })
  189. wx.hideToast({
  190. success: (res) => {},
  191. });
  192. });
  193. },
  194. closePopup() {
  195. this.setData({
  196. showIndex: false
  197. })
  198. },
  199. changeInfo(e) {
  200. // console.log(e.currentTarget.dataset.data);
  201. let dataitem = e.currentTarget.dataset.data;
  202. console.log(dataitem);
  203. let params ={
  204. "dictType":dataitem.dictType,
  205. "type": "",
  206. "title": "",
  207. };
  208. wx.showToast({
  209. title: '加载中...',
  210. icon: 'loading'
  211. });
  212. getMapDataType(params).then((res) => {
  213. let data = []
  214. switch (dataitem.name) {
  215. case "小学":
  216. case "特殊教育学校":
  217. res.data.forEach((item) => {
  218. if (item.type == dataitem.name) {
  219. data.push(item)
  220. }
  221. });
  222. break;
  223. case "中学":
  224. res.data.forEach((item) => {
  225. if (item.type == dataitem.name||item.specialtype == dataitem.name) {
  226. data.push(item)
  227. }
  228. });
  229. break;
  230. default:
  231. data = res.data;
  232. break;
  233. }
  234. let renderData = []
  235. data.forEach((item) => {
  236. if(item.tel!=null && item.tel!=""){
  237. item.tel = item.tel.split(";")
  238. }
  239. renderData.push(item)
  240. });
  241. this.setData({
  242. popData: renderData,
  243. showTraffic: false,
  244. showIndex: false
  245. })
  246. wx.hideToast({
  247. success: (res) => {},
  248. });
  249. });
  250. },
  251. /**
  252. * 拨打电话
  253. * @param {*} e
  254. */
  255. callNumber(e) {
  256. let phoneNumber = e.currentTarget.dataset.value;
  257. wx.makePhoneCall({
  258. phoneNumber: phoneNumber,
  259. });
  260. },
  261. /**
  262. * list跳转info
  263. *
  264. */
  265. changeItem(e) {
  266. let that = this;
  267. console.info(e)
  268. let value = e.currentTarget.dataset.value;
  269. if (value === "none") {
  270. that.setData({
  271. isList: false,
  272. showSearch: false,
  273. showSet: false,
  274. });
  275. } else {
  276. // 控制公交自驾选中状态
  277. let type = e.currentTarget.dataset.type;
  278. if (type==0){
  279. if(e.detail.value==0){
  280. changeValue = "transit";
  281. }else{
  282. changeValue = "driving";
  283. }
  284. }
  285. that.setData({
  286. trafficType: type,
  287. showSet: false
  288. });
  289. that.setData({
  290. isList: false,
  291. showSearch: false,
  292. showSet: true
  293. });
  294. }
  295. // 详情赋值
  296. let index = e.currentTarget.dataset.index;
  297. let item = that.data.popData[index];
  298. console.info(item);
  299. let address='';
  300. if (item.address.search("重庆")==-1) {
  301. address = "重庆" + item.address;
  302. }else{
  303. address = item.address;
  304. }
  305. console.log(item.time);
  306. that.setData({
  307. detail_dep: item.dep,
  308. detail_content: item.content,
  309. detail_img: item.img,
  310. detail_address: item.address,
  311. detail_time: item.time,
  312. detail_tel: item.tel,
  313. detail_index: index,
  314. trafficEnd: address
  315. });
  316. BMap.geocoder({
  317. address: address,
  318. success: function (data) {
  319. var res = data.result
  320. that.setData({
  321. latitude: res.location.lat,
  322. longitude: res.location.lng,
  323. markers: [{
  324. latitude: res.location.lat,
  325. longitude: res.location.lng,
  326. iconPath: "/location.png",
  327. width: '30px',
  328. height: '30px',
  329. rotate: 0,
  330. alpha: 1
  331. }]
  332. });
  333. }
  334. });
  335. },
  336. /**
  337. * 打开全景地图
  338. * @param {*} e
  339. */
  340. openVR(e) {
  341. wx.navigateTo({
  342. url: '../map-vr/map-vr',
  343. });
  344. },
  345. getSearchVal(e) {
  346. this.setData({
  347. searchVal: e.detail.value
  348. });
  349. },
  350. loadItem() {
  351. let searchVal = this.data.loadValue;
  352. let datatype = this.data.type;
  353. if (!searchVal) {
  354. return;
  355. }
  356. wx.showToast({
  357. title: '加载中...',
  358. icon: 'loading'
  359. });
  360. let x =-1
  361. let y =-1
  362. for (let i = 0; i < datatype.length; i++) {
  363. for (let j = 0; j < datatype[i].length; j++) {
  364. if (datatype[i][j].name == searchVal) {
  365. x = i
  366. y = j
  367. break;
  368. }
  369. }
  370. if(x!=-1){
  371. break;
  372. }
  373. }
  374. let searcharr = ""
  375. if (datatype[x][y].dictType != "") {
  376. searcharr = datatype[x][y].dictType
  377. } else {
  378. let arr = popType[x][y]
  379. arr.forEach((item) => {
  380. searcharr += item.dictType + ","
  381. })
  382. searcharr = searcharr.substring(0, searcharr.length - 1)
  383. }
  384. let params ={
  385. "dictType": searcharr,
  386. "type": "",
  387. "title": "",
  388. } ;
  389. getMapDataType(params).then((res) => {
  390. let data = []
  391. res.data.forEach((item) => {
  392. if(item.tel!=null && item.tel!=""){
  393. item.tel = item.tel.split(";")
  394. }
  395. data.push(item)
  396. });
  397. this.setData({
  398. // showTraffic: false,
  399. popData: data,
  400. })
  401. wx.hideToast({
  402. success: (res) => {},
  403. });
  404. });
  405. // 搜索结果
  406. },
  407. /**
  408. * 顶部搜索点击事件
  409. * @param {*} e
  410. */
  411. searchTap(e) {
  412. let searchVal = this.data.searchVal;
  413. wx.showToast({
  414. title: '加载中...',
  415. icon: 'loading'
  416. });
  417. let params ={
  418. "dictType": "",
  419. "type": "",
  420. "title": searchVal,
  421. };
  422. this.setData({
  423. showTraffic: false
  424. })
  425. getMapDataType(params).then((res) => {
  426. let data = []
  427. res.data.forEach((item) => {
  428. if(item.tel!=null && item.tel!=""){
  429. item.tel = item.tel.split(";")
  430. }
  431. data.push(item)
  432. });
  433. this.setData({
  434. showTraffic: false,
  435. popData: data,
  436. })
  437. wx.hideToast({
  438. success: (res) => {},
  439. });
  440. });
  441. // 搜索结果
  442. wx.hideToast({
  443. success: (res) => {},
  444. });
  445. },
  446. getTrafficStart(e) {
  447. this.setData({
  448. trafficStart: e.detail.value
  449. });
  450. },
  451. getTrafficEnd(e) {
  452. this.setData({
  453. trafficEnd: e.detail.value
  454. });
  455. },
  456. /**
  457. * 搜索进行交通路线规划
  458. * @param {*} e
  459. */
  460. searchTrafficTap(e) {
  461. const that = this;
  462. // console.log(that.data.trafficType);
  463. let trafficType = that.data.trafficType;
  464. if (trafficType == 0) {
  465. changeValue = "transit";
  466. } else {
  467. changeValue = "driving";
  468. }
  469. let trafficStart = that.data.trafficStart;
  470. let trafficEnd = that.data.trafficEnd;
  471. if (!trafficStart || !trafficEnd) {
  472. wx.showToast({
  473. title: '请输入起点和终点',
  474. icon: 'none'
  475. });
  476. return;
  477. }
  478. console.info(trafficStart, trafficEnd);
  479. BMap.geocoder({
  480. address: trafficEnd,
  481. success: function (data) {
  482. var res = data.result
  483. // console.log(res);
  484. let key = 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'; //使用在腾讯位置服务申请的key
  485. let referer = '掌上南岸'; //调用插件的app的名称
  486. // 终点
  487. let endPoint = JSON.stringify({
  488. 'name': trafficEnd,
  489. 'latitude': res.location.lat,
  490. 'longitude': res.location.lng
  491. });
  492. wx.navigateTo({
  493. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint + "&mode=" + changeValue
  494. });
  495. }
  496. });
  497. },
  498. backSearch() {
  499. let that =this
  500. if (!that.data.isList) {
  501. this.setData({
  502. isList: true,
  503. showSearch: true,
  504. showSet: false
  505. });
  506. } else {
  507. if (!that.data.showTraffic) {
  508. that.setData({
  509. showTraffic: true,
  510. showSearch: true,
  511. searchVal: ''
  512. });
  513. }
  514. }
  515. wx.getLocation({
  516. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  517. success (res) {
  518. const latitude = res.latitude
  519. const longitude = res.longitude
  520. that.setData({
  521. latitude: latitude,
  522. longitude:longitude,
  523. trafficStart:"我的位置",
  524. markers:[{
  525. latitude: latitude,
  526. longitude: longitude,
  527. iconPath: imgUrl+"/location.png",
  528. width: '34px',
  529. height: '34px',
  530. rotate: 0,
  531. alpha: 1
  532. }]
  533. });
  534. }
  535. })
  536. changeValue = "transit";
  537. },
  538. onchange(e) {
  539. let that = this;
  540. if (e.detail.value == 0) {
  541. that.setData({
  542. trafficType: 0
  543. });
  544. changeValue = "transit";
  545. } else {
  546. that.setData({
  547. trafficType: 1
  548. });
  549. changeValue = "driving";
  550. }
  551. },
  552. /**
  553. * 用户点击右上角分享
  554. */
  555. onShareAppMessage() {
  556. return {
  557. title: '地图服务'
  558. }
  559. },
  560. onShareTimeline(){
  561. return {
  562. title: '地图服务'
  563. }
  564. }
  565. });
  566. let changeValue = "transit";