Browse Source

公交自驾切换 路线规划对应

xyg 2 years ago
parent
commit
f439eb5aa1
2 changed files with 94 additions and 79 deletions
  1. 93 78
      nnzwminiapp/pages/map/map.js
  2. 1 1
      nnzwminiapp/pages/map/map.wxml

+ 93 - 78
nnzwminiapp/pages/map/map.js

@@ -775,45 +775,43 @@ Page({
               });
           }
         });
-        
+
         BMap = new QQMapWX({
-          key: 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'
+            key: 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'
         });
-        
+
         wx.getLocation({
-          type: 'gcj02', //返回可以用于wx.openLocation的经纬度
-          success (res) {
-            
-            const latitude = res.latitude
-            const longitude = res.longitude
-            that.setData({
-              latitude: latitude,
-              longitude:longitude,
-              trafficStart:"我的位置",
-              markers:[{
-                latitude: latitude,
-                longitude: longitude,
-                iconPath: imgUrl+"/location.png",
-                width: '30px',
-                height: '30px',
-                rotate: 0,
-                alpha: 1
-              }]
-            });
-          }
-         })
+            type: 'gcj02', //返回可以用于wx.openLocation的经纬度
+            success(res) {
+                const latitude = res.latitude
+                const longitude = res.longitude
+                that.setData({
+                    latitude: latitude,
+                    longitude: longitude,
+                    trafficStart: "我的位置",
+                    markers: [{
+                        latitude: latitude,
+                        longitude: longitude,
+                        iconPath: imgUrl + "/location.png",
+                        width: '30px',
+                        height: '30px',
+                        rotate: 0,
+                        alpha: 1
+                    }]
+                });
+            }
+        });
         // 初始化数据
-        
-        if(options.se!==null&&options.se!==""){
-          this.setData({
-            searchVal:options.se
-          })
-          setTimeout(() => {
-            this.searchTap();
-          }, 2000);
+
+        if (options.se !== null && options.se !== "") {
+            this.setData({
+                searchVal: options.se
+            });
+            setTimeout(() => {
+                this.searchTap();
+            }, 2000);
         }
         // searchVal
-
     },
     popview(e) {
         let x = e.currentTarget.dataset.index;
@@ -1259,9 +1257,9 @@ Page({
             let type = e.currentTarget.dataset.type;
             if (type==0){
               if(e.detail.value==0){
-                changeValue = "transit"
+                changeValue = "transit";
               }else{
-                changeValue = "driving"
+                changeValue = "driving";
               }
             }
             that.setData({
@@ -1289,25 +1287,26 @@ Page({
             trafficEnd: item.address
         });
         BMap.geocoder({
-          address: item.address,
-          success: function (data) {
-            var res = data.result
-            that.setData({
-              latitude: res.location.lat,
-              longitude: res.location.lng,
-              markers:[{
-                latitude: res.location.lat,
-                longitude: res.location.lng,
-                iconPath: imgUrl+"/location.png",
-                width: '30px',
-                height: '30px',
-                rotate: 0,
-                alpha: 1
-              }]
-            })
-          }
+            address: item.address,
+            success: function (data) {
+                var res = data.result
+                that.setData({
+                    latitude: res.location.lat,
+                    longitude: res.location.lng,
+                    markers: [{
+                        latitude: res.location.lat,
+                        longitude: res.location.lng,
+                        iconPath: imgUrl + "/location.png",
+                        width: '30px',
+                        height: '30px',
+                        rotate: 0,
+                        alpha: 1
+                    }]
+                });
+            }
         });
     },
+
     getSearchVal(e) {
         this.setData({
             searchVal: e.detail.value
@@ -1364,10 +1363,20 @@ Page({
             trafficEnd: e.detail.value
         });
     },
-    
+
+    /**
+     * 搜索进行交通路线规划
+     * @param {*} e 
+     */
     searchTrafficTap(e) {
         const that = this;
         console.log(that.data.trafficType);
+        let trafficType = that.data.trafficType;
+        if (trafficType == 0) {
+            changeValue = "transit";
+        } else {
+            changeValue = "driving";
+        }
         let trafficStart = that.data.trafficStart;
         let trafficEnd = that.data.trafficEnd;
         if (!trafficStart || !trafficEnd) {
@@ -1378,26 +1387,25 @@ Page({
             return;
         }
         console.info(trafficStart, trafficEnd);
-        
+
         BMap.geocoder({
-          address: trafficEnd,
-          success: function (data) {
-            var res = data.result
-            console.log(res);
-            let key = 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'; //使用在腾讯位置服务申请的key
-            let referer = '掌上南岸'; //调用插件的app的名称
-            let endPoint = JSON.stringify({ //终点
-              'name': trafficEnd,
-              'latitude': res.location.lat,
-              'longitude': res.location.lng
-            });
-            wx.navigateTo({
-              url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint+"&mode=" + changeValue
-            });
-          }
+            address: trafficEnd,
+            success: function (data) {
+                var res = data.result
+                console.log(res);
+                let key = 'KN3BZ-KUDND-PGH4Y-POVRP-43KF3-RNF4K'; //使用在腾讯位置服务申请的key
+                let referer = '掌上南岸'; //调用插件的app的名称
+                // 终点
+                let endPoint = JSON.stringify({
+                    'name': trafficEnd,
+                    'latitude': res.location.lat,
+                    'longitude': res.location.lng
+                });
+                wx.navigateTo({
+                    url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint + "&mode=" + changeValue
+                });
+            }
         });
-        
-        
     },
 
     backSearch() {
@@ -1438,15 +1446,22 @@ Page({
             });
           }
          })
-         changeValue = "transit"
+         changeValue = "transit";
     },
 
-    onchange(e){
-      if(e.detail.value==0){
-        changeValue = "transit"
-      }else{
-        changeValue = "driving"
-      }
+    onchange(e) {
+        let that = this;
+        if (e.detail.value == 0) {
+            that.setData({
+                trafficType: 0
+            });
+            changeValue = "transit";
+        } else {
+            that.setData({
+                trafficType: 1
+            });
+            changeValue = "driving";
+        }
     }
 });
 let changeValue = "transit";

+ 1 - 1
nnzwminiapp/pages/map/map.wxml

@@ -35,7 +35,7 @@
 
     <view wx:if="{{showTraffic}}">
       <view class="right-search" style="position: absolute; left: 22rpx; top: 257px; width: 708rpx; height: 300rpx; display: block; box-sizing: border-box; padding-top: 10rpx;">
-        <t-tabs defaultValue="{{trafficType}}" bindchange= "onchange" theme="tag" style="height: 292rpx; ">
+        <t-tabs defaultValue="{{trafficType}}" bindchange="onchange" theme="tag" style="height: 292rpx; ">
           <t-tab-panel label="公交" value="0" style=" height: 180rpx; ">
             <include src="./quert"></include>
           </t-tab-panel>