autoTravel

          ;(function() {
              var MapShare = App.MapShare, mapView= MapShare.mapView,
                  detailView= MapShare.detailView,
                  searchView= MapShare.searchView,
                  // locationModel=MapShare.locationModel,
                  searchPathView = MapShare.searchPathView,
                  searchPathModel = MapShare.searchPathModel,
                  configLan=MapShare.configLan,
                  topHeight=MapShare.topHeight;
              var loadingMov = {
                  loadingBegin : App.loadingBegin,
                  loadingFinish : App.loadingFinish
              };     
              var hasResulted = false;
              var mapObj = mapView.getMapObj(),
                  startPos,endPos,info;
                  
              var RoutPathView = PackTools.View.extend({
                  el: $("#drivepath"),    
                  model: searchPathModel,
                  initialize : function() {
                      this.topbar= this.el.find('.position_box');
                      this.topbarback = this.topbar.find('.backArrow');
                      this.changeToBusBtn = this.topbar.find('.by_way ul li').eq(0);
                      this.busBarPan = this.el.find("#busBarPan");
                      this.startPlace = this.busBarPan.find("#startPlace");
                      this.endPlace = this.busBarPan.find("#endPlace");
                      this.$listWrap = this.el.find("#listWrap");
                      this.$busItemContainer = this.$listWrap.find(".drive-path-list");
                      this.otherInfo = this.busBarPan.find('.otherInfo');
                      this.changeToBusBtn.click(function(){
                          routPathView.el.hide();
                          searchPathView.searchBusLine();
                      });
                      this.topbarback.tap(function(){
                          // searchPathView.el.show();
                          // routPathView.el.hide();
                          routPathView.showSearchBus();
                      });
                  },
                  showSearchBus : function(){
                      routPathView.el.hide();
                      //searchPathView.$completeList.empty();
                      searchPathView.$busList.hide();
                      mapView.el.hide();
                      searchPathView.el.show();
                      //uPAResizePage();
                  },
                  showOtherInfo : function() {
                      //加載駕車路徑規劃服務插件
                      var driving;
                      mapObj.plugin(["AMap.Driving"],function(){
                          var drivingOptions = {
                              policy:AMap.DrivingPolicy.LEAST_TIME
                          };
                          driving = new AMap.Driving(drivingOptions);
                          AMap.event.addListener(driving, "complete", function(data) {
                              var routes = data.routes;
                              if (routes.length <= 0) {
                                  routPathView.otherInfo.hide();
                              } else {
                                  var distance = 0;
                                  var time = 0;
                                  for (var i = 0; i < routes.length; i ++) {
                                      distance += routes[i].distance;
                                      time += routes[i].time;
                                  }
                                  routPathView.otherInfo.empty()
                                              .text((time/60).toFixed(2).toString() + "分鐘/" + (distance/1000).toFixed(2).toString() + "公里");
                              }
                          });
                          driving.search(startPos, endPos);
                      });
                  },
                  drawTravelLine : function() {
                      var routeSearchOption = {
                          routeType : 1
                      };
                      loadingMov.loadingBegin();
                      routPathView.showOtherInfo();
                      var routeSearch = new AMap.RouteSearch(routeSearchOption);            
                      routeSearch.getNaviPath([startPos, endPos], function(data){
                          routPathView.showRouteDetails(data);
                          loadingMov.loadingFinish();
                      });
                  },
                  showSearchMap : function(data){
                      routPathView.el.css({
                          position:'absolute',
                          'z-index': 501,
                          top: topHeight+'px'
                      });    
                      
                      if(!hasResulted){
                           mapObj.clearMap();
                           routPathView.drawLine(data);
                           hasResulted = true;
                      }
                      mapView.showCenterMap(true);
                      routPathView.$listWrap.hide();
                      mapView.el.show();    
                      routPathView.busBarPan.css({
                          position:'absolute',
                          'z-index': 501,
                          'margin-top': mapView.el.height()-routPathView.topbar.height()-routPathView.busBarPan.height()+'px'
                      });
                      //routPathView.busBarPan.css('margin-top', mapView.el.height()-routPathView.topbar.height()-routPathView.busBarPan.height()+'px');
                      //162 底部欄高度不知為何得不到
                      //uPAResizePage();
                  },
                  showSearchList : function(){
                      routPathView.el.css({
                          position:'relative',
                          top: 'auto'
                      });    
                      routPathView.$listWrap.show();
                      mapView.el.hide();  
                      // routPathView.el.show();  
                      routPathView.busBarPan.css({
                          position:'relative',
                          'margin-top':'0px'
                      });
                      //uPAResizePage();
                  },
                  showRouteDetails : function(data){
                      //debugger;
                      if(data && data.list.length > 0){
                          var details = '<p>起點:'+info.start.name+'</p>';
                          for(var i = 0,len = data.list.length;i < len;i++){
                              details += '<p>'+data.list[i].textInfo+'</p>';
                          }
                          details += '<p>終點:'+info.end.name+'</p>';
                          this.$busItemContainer.html(details);
                          /* 暫時失效
                          var isInList = true;
                          this.$busItemContainer.click(function (e){
                               isInList = false;
                               routPathView.showSearchMap(data);
                          });
                          */
                          hasResulted = false;  
                          routPathView.showSearchList();
                      }
                  },        
                  drawLine : function(data){
                      var coords = [];
                      var poi_xy_r = data.coors.split(";");
              
                      for (var j = 0, len = poi_xy_r.length; j < len; j++) {
                          var arr_lnglat = new Array();
                          arr_lnglat = poi_xy_r[j].split(",");
                          coords.push(new AMap.LngLat(arr_lnglat[0], arr_lnglat[1]));
                      }
                      var line = new AMap.Polyline({
                          map: mapObj,
                          path : coords,
                          strokeColor : "#003366",
                          strokeOpacity : 0.8,
                          strokeWeight : 4,
                          strokeDasharray : [10, 5]
                      });
              
                      var marker1=new AMap.Marker({
                          map: mapObj,
                          draggable: 0,
                          position : startPos,
                          icon : "http://webapi.amap.com/images/qd.png"
                          //offset : new AMap.Pixel(-15, -36)
                      });
              
                      var marker2=new AMap.Marker({
                          map: mapObj,
                          draggable: 0,
                          position : endPos,
                          icon : "http://webapi.amap.com/images/zd.png"
                          //offset : new AMap.Pixel(-15, -36)
                      });
              
                      // mapObj.setFitView();
                  },
                  getRouteDetails : function(_startPos, _endPos, busInfo){
                      routPathView.el.css({
                          position:'relative',
                          top: 'auto'
                      });    
                      routPathView.busBarPan.css({
                          position:'relative',
                          'margin-top':'0px'
                      });
                      this.el.show();
                      info = busInfo;
                      startPos = _startPos;
                      endPos = _endPos;
                      this.startPlace.text(info.start.name);
                      this.endPlace.text(info.end.name);
                      this.drawTravelLine();
                  }
              });
              var routPathView = new RoutPathView();
              App.MapShare.routPathView = routPathView;
          })();

          posted on 2014-04-22 09:45 koradji 閱讀(201) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          db2

          dos

          Groovy

          Hibernate

          java

          WAS

          web application

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鄂温| 平陆县| 珲春市| 积石山| 武隆县| 稷山县| 英超| 新晃| 营口市| 平谷区| 汽车| 泸定县| 玉溪市| 沂源县| 松溪县| 抚远县| 临泽县| 通城县| 黔东| 建水县| 岳西县| 牡丹江市| 锦州市| 宜良县| 灵石县| 于田县| 海城市| 梓潼县| 敦煌市| 溧阳市| 新泰市| 昭苏县| 温州市| 石阡县| 弥渡县| 米泉市| 正宁县| 武威市| 宁强县| 湟源县| 象州县|