busline

          ;(function(){
              var MapShare = App.MapShare, mapView= MapShare.mapView,
                  detailView= MapShare.detailView,
                  searchView= MapShare.searchView,
                  // locationModel=MapShare.locationModel,
                  routPathView = null, //來自后面實(shí)例化的。。。
                  configLan=MapShare.configLan,
                  topHeight=MapShare.topHeight;
              var AMap = window.AMap;    
              
              var loadingMov = {
                  loadingBegin : App.loadingBegin,
                  loadingFinish : App.loadingFinish
              };  
              var hasResulted = false;  
              var mapObj=mapView.getMapObj();    
              var SearchPathModel = PackTools.Model.extend({
                  defaults: {
                      busInfo: {start: {name:'', x:0, y:0}, end: {name:'', x:0, y:0}},
                      busSearchOpt02:{
                          type: 0x02,
                          batch: 1,
                          number: 100
                      },
                      autoCompleterOpt:{
                          range: 10000,
                          sort: 0,
                          retvalue: 1
                      }
                  }
              })
              var searchPathModel=new SearchPathModel();
              var SearchPathView = PackTools.View.extend({
                  el: $("#querypath"),    
                  model: searchPathModel,
                  initialize : function() {
                      var $root = this.el;
                      var $busList = $("#buslist");
                      _.extend(this,{
                          $root : $root,
                          $startPlace : $root.find("#startPlace"),    //起點(diǎn)節(jié)點(diǎn)
                          $endPlace : $root.find("#endPlace"),        //終點(diǎn)節(jié)點(diǎn)
                          $searchBusLineBtn : $root.find(".pathform-seach-transit"),  //查詢公交的按鈕
                          $switchBtn : $root.find(".exchange_key"),         //切換起點(diǎn)和終點(diǎn)的按鈕
                          $searchSelfDriving : $root.find(".pathform-seach-selfdriving"),                
                          topbarback : $root.find('.position_box p'),
                          
                          $busList : $busList,
                          topbar:$busList.find('.position_box'),
                          busSearchBar : $busList.find('#busSearchBar'),
                          $listWrap : $busList.find("#listWrap"),
                          busBarPan: $busList.find("#busBarPan"),
                          $busStartTip : $busList.find("#busBarPan #startPlace"), //$busList.find(".bus-position-qi"),
                          $busEndTip : $busList.find('#busBarPan #endPlace'), //$busList.find(".bus-position-zhong"),
                          $busItemContainer : $busList.find(".bus-list"),
                          listTopbarback : $busList.find('.position_box p')
                      });
                      this.changeToCarBtn = this.topbar.find('.by_way ul li').eq(1);
                      
                      // this.busSearchBar = this.$listWrap.find('#busSearchBar');
                      var view = this;
                      this.changeToCarBtn.click(function(){
                          var busInfo = view.model.get('busInfo');
                          var startXY = new AMap.LngLat(busInfo.start.x, busInfo.start.y),
                              endXY = new AMap.LngLat(busInfo.end.x, busInfo.end.y);
                          searchPathView.el.hide();
                          searchPathView.$busList.hide();
                          if(!routPathView) routPathView = MapShare.routPathView;
                          routPathView.getRouteDetails(startXY, endXY, busInfo);
                      });
                      
                      var spans = this.busSearchBar.find('span.text');
                      for(var i=0,len=spans.length; i<len; i++){
                          spans.eq(i).tap((function(i){
                              return function(){
                                  spans.removeClass('current');
                                  if(i==0){
                                      $(this).addClass('current');
                                      searchPathView.model.set('busSearchOpt02',{
                                          type: 0x00,
                                          batch: 1,
                                          number: 100
                                      })
                                      searchPathView.searchBusLine();
                                  }else if(i==1){
                                      $(this).addClass('current');
                                      searchPathView.model.set('busSearchOpt02',{
                                          type: 0x02,
                                          batch: 1,
                                          number: 100
                                      })
                                      searchPathView.searchBusLine();
                                  }else if(i==2){
                                      $(this).addClass('current');
                                      searchPathView.model.set('busSearchOpt02',{
                                          type: 0x03,
                                          batch: 1,
                                          number: 100
                                      })
                                      searchPathView.searchBusLine();
                                  }else if(i==3){
                                      $(this).addClass('current');
                                      searchPathView.model.set('busSearchOpt02',{
                                          type: 0x01,
                                          batch: 1,
                                          number: 100
                                      })
                                      searchPathView.searchBusLine();
                                  }
                              }
                          })(i));
                      }
                      
                      var busInfo = view.model.get('busInfo');
                      this.topbarback.tap(function(){
                          hasResulted = false;
                          if(detailView.model.get('pageFrom')==detailView.name){
                               view.el.hide();
                               detailView.el.show();
                               //uPAResizePage();
                          }else{
                               searchPathView.backToSearchMain();
                          }
                          
                      });
                      this.$searchSelfDriving.on("click", function(e){
                          if(!view.$startPlace.text()){
                              mapView.showMapTip(configLan.Tip, configLan.putInStartPlace);
                              return;
                          }
                          if(!view.$endPlace.text()){
                              mapView.showMapTip(configLan.Tip, configLan.putInEndPlace);
                              return;
                          }
                          reviseBusInfo(busInfo.start);
                          var startXY = new AMap.LngLat(busInfo.start.x, busInfo.start.y),
                              endXY = new AMap.LngLat(busInfo.end.x, busInfo.end.y);
                          searchPathView.el.hide();
                          if(!routPathView) routPathView = MapShare.routPathView;
                          routPathView.getRouteDetails(startXY, endXY, busInfo);
                      });
                      //切換起點(diǎn)和終點(diǎn)
                      this.$switchBtn.on("click", function(e){
                          if(!view.$startPlace.text()){
                              mapView.showMapTip(configLan.Tip, configLan.putInStartPlace);
                              return;
                          }
                          if(!view.$endPlace.text()){
                              mapView.showMapTip(configLan.Tip, configLan.putInEndPlace);
                              return;
                          }
                          var tempVal = view.$startPlace.text();
                          view.$startPlace.text(view.$endPlace.text());
                          view.$endPlace.text(tempVal);
                          reviseBusInfo(busInfo.start);
                          tempVal = busInfo.start; // MapShare.clone
                          busInfo.start = busInfo.end;
                          busInfo.end = tempVal;
                          return false;
                      });
                      
                      //查詢公交路線
                      this.$searchBusLineBtn.on("click", function() {
                          if(!view.$startPlace.text()){
                              mapView.showMapTip(configLan.Tip, configLan.putInStartPlace);
                              return;
                          }
                          if(!view.$endPlace.text()){
                              mapView.showMapTip(configLan.Tip, configLan.putInEndPlace);
                              return;
                          }
                          searchPathView.model.set('busSearchOpt02',{
                              type: 0x02,
                              batch: 1,
                              number: 100
                          })
                          searchPathView.searchBusLine();
                      });//查詢公交路線
                      
                      this.listTopbarback.tap(function(){                
                          searchPathView.showSearchBus();
                      });
                      /* 暫時(shí)失效
                      var isInList = true;
                      this.$busItemContainer.on("click", ".bus-item", function(e) {
                          var $target = $(e.currentTarget), lineData = JSON.parse($target.attr("lineData"));
                          //console.dir(lineData);
                          isInList = false;
                          hasResulted = false;
                          searchPathView.showSearchMap(lineData);
                      });
                      */
                  }, //initial
                  setSearchInput : function(start, end){
                      //start:起點(diǎn)名稱和位置 {name:'',x:number經(jīng)度, y:number:緯度}, end終點(diǎn)的
                      var busInfo = searchPathView.model.get('busInfo');
                      if(start){
                          busInfo.start = {
                              name:start.name,
                              x:start.x,
                              y:start.y
                          };
                          this.$startPlace.text(start.name);
                      }else{
                          this.$startPlace.text('');
                      }
                      if(end){
                          busInfo.end = {
                              name:end.name,
                              x:end.x,
                              y:end.y
                          }
                          this.$endPlace.text(end.name);
                      }else{
                          this.$endPlace.text('');
                      }
                      this.el.show();
                      //uPAResizePage();
                  },
                  backToSearchMain : function(){
                      // mapView.getMapObj().clearMap();
                      mapView.showCenterMap();
                      searchPathView.el.hide();
                      searchPathView.$busList.hide();
                      mapView.el.show();    
                      //uPAResizePage();
                  },
                  searchBusLine : function(){
                      loadingMov.loadingBegin();
                      var busInfo = searchPathView.model.get('busInfo');
                      reviseBusInfo(busInfo.start);
                      
                      var startXY = new AMap.LngLat(busInfo.start.x, busInfo.start.y),
                          endXY = new AMap.LngLat(busInfo.end.x, busInfo.end.y),
                          busSearcher = new AMap.BusSearch(searchPathView.model.get('busSearchOpt02')),
                          city = mapView.model.city || '';
                      
                      searchPathView.$busStartTip.html(busInfo.start.name);
                      searchPathView.$busEndTip.html(busInfo.end.name);
                      searchPathView.$busItemContainer.empty();
                      busSearcher.byTwoPoi([startXY, endXY], city, function(data) {
                          var list = data.list, line = [], currPaths, items = [], currItem, title, itemPath, content;
                          if(list && list.length) {
                              for(var i = 0, len = list.length; i < len; i ++) {
                                  currItem = $('<div class="bus-item"/>');
                                  title = $('<div class="bus-item-title"/>');
                                  content = $('<div class="bus-item-content"/>');
                                  itemPath = $('<div class="bus-item-path"/>');
                                  line = list[i];
                                  currPaths = line.segmentList;
                                  title.html('<p class="bus-item-no">' +
                                  leftPad("0", 2, ""+(i+1))
                                  +'</p>');
                                  for(var j = 0, jLen = currPaths.length; j < jLen; j ++) {
                                      itemPath.append('<p class="bus-item-path-text">' +
                                          currPaths[j].busName
                                      +'</p>\
                                      <p class="bus-item-path-remark">' +
                                          currPaths[j].startName+' '+currPaths[j].passDepotName+' '+currPaths[j].endName
                                      + '</p>');
                                  }
                                  title.append(itemPath).append('<p class="bus-item-icon">&nbsp;</p>');
                                  currItem.append(title).append(content);
                                  items.push(currItem[0]);
                                  currItem.attr("lineData", JSON.stringify(line)); //attr
                              }
                              searchPathView.$busItemContainer.append(items);
                          }
                          
                          // searchPathView.$busList.css({
                              // position:'relative',
                              // top: 'auto'
                          // });
                          // $root.hide();
                          // $busList.show();
                          // uPAResizePage();
                          searchPathView.showSearchList();
                          loadingMov.loadingFinish();
                      }); //byTwoPoi    
                  },
                  showSearchMap : function(lineData){
                      searchPathView.$busList.css({
                          position:'absolute',
                          top: topHeight+'px',
                          'z-index': 501
                      });    
                      
                      if(!hasResulted){
                         mapObj.clearMap();
                         searchPathView.drawBusLine(lineData);
                         hasResulted = true;
                      }
                      mapView.showCenterMap(true);
                      // searchPathView.el.hide();
                      searchPathView.busSearchBar.hide();
                      searchPathView.$listWrap.hide();
                      mapView.el.show();    
                      searchPathView.busBarPan.css({
                          position:'absolute',
                          'z-index': 501,
                          'margin-top': mapView.el.height()-searchPathView.topbar.height()-searchPathView.busBarPan.height()+'px'
                      });
                      //162 底部欄高度不知為何得不到
                      //uPAResizePage();
                  },
                  showSearchList : function(){
                      searchPathView.$busList.css({
                          position:'relative',
                          top: 'auto'
                      });    
                      searchPathView.$root.hide();
                      searchPathView.busSearchBar.show();
                      searchPathView.$listWrap.show();
                      mapView.el.hide();  
                      searchPathView.$busList.show();  
                      searchPathView.busBarPan.css({
                          position:'relative',
                          'margin-top':'0px'
                      });
                      //uPAResizePage();
                      // $busList.hide();
                      // mapView.showCenterMap();
                      // mapView.el.show();    
                      // searchPathView.$root.hide();
                      // uPAResizePage();
                  },
                  showSearchBus : function(){
                      searchPathView.$busList.hide();
                      // mapView.showCenterMap();
                      mapView.el.hide();    
                      searchPathView.$root.show();
                      //uPAResizePage();
                  },
                  /**
                   * 畫地圖上的線的方法
                   * @param lineData 數(shù)據(jù)
                   */
                  drawBusLine:function(lineData){
                      var lineList = lineData.segmentList, aLine, tempBusXY,
                          busXY = [],     //公交經(jīng)過的線路的經(jīng)緯度數(shù)組
                          tempBusXY_xy,
                          view=this;
                      if(lineList && lineList.length) {
                          for(var i = 0, iLen = lineList.length; i < iLen; i ++) {
                              aLine = lineList[i];
                              tempBusXY = aLine.coordinateList.split(";");
                              for(var j = 0, jLen = tempBusXY.length; j < jLen; j ++) {
                                  tempBusXY_xy = tempBusXY[j].split(',')
                                  busXY.push(new AMap.LngLat(tempBusXY_xy[0], tempBusXY_xy[1]));
                                  if(j === 0 || jLen === j+1) {
                                      view.drawBusStation(new AMap.LngLat(tempBusXY_xy[0], tempBusXY_xy[1]), i, j,
                                          j === 0 &&("名稱:" + aLine.startName + "<br/>類型: 公交站<br/>公交路線名:" + aLine.busName)||("名稱:" + aLine.endName + "<br/>類型: 公交站<br/>公交路線名:" + aLine.busName));
                                  }
                              }
                          }
                          var line = new AMap.Polyline({
                              map: mapObj,
                              path : busXY, //線經(jīng)緯度數(shù)組
                              strokeColor : "#005cb5", //線顏色
                              strokeOpacity : 0.8, //線透明度
                              strokeWeight : 6 //線寬
                          });
                          //mapObj.setFitView();
                      }
                  },
                  /**
                   * 標(biāo)示公交站
                   * @param data 數(shù)據(jù)
                   */
                  drawBusStation : function(change, i, j,  name){
                      var marker = new AMap.Marker({
                          map: mapObj,
                          draggable: 0,
                          icon : "http://webapi.amap.com/images/bx11.png", //復(fù)雜圖標(biāo)
                          visible : true, //可見
                          position : change
                      });
                      var infoWindow = new AMap.InfoWindow({
                          size: new AMap.Size(400, 150),
                          offset: new AMap.Pixel(0, -30), //new AMap.Pixel(0, -30),
                          content: name
                      });
                      if(i === j && 0 === i) {
                          infoWindow.open(mapObj, marker.getPosition());
                      }
                      mapObj.bind(marker, 'click', function() {
                          if(infoWindow.getIsOpen()) {
                              infoWindow.close();
                          } else {
                              infoWindow.open(mapObj, marker.getPosition());
                          }
                      });
                  }
              });
              var searchPathView = new SearchPathView();
              function leftPad(theChar, num, str) {
                  if(str.length >= num){
                       return str;
                  }else {
                      for(var i = str.length; i < num; i ++) {
                          str = theChar + str;
                      }
                      return str;
                  }
              }
              function reviseBusInfo(place){
                  if(!place.x || !place.y){
                      var aroundLocal=mapView.model.get('aroundLocal');
                      place.name = aroundLocal.name;
                      place.x=aroundLocal.pos.lng;
                      place.y=aroundLocal.pos.lat;
                  }
              }
              App.MapShare.searchPathView = searchPathView;
              App.MapShare.searchPathModel = searchPathModel;
          })();

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


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


          網(wǎng)站導(dǎo)航:
           
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          db2

          dos

          Groovy

          Hibernate

          java

          WAS

          web application

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 潮州市| 咸宁市| 出国| 卢湾区| 阿图什市| 中牟县| 平罗县| 亚东县| 泾源县| 西乌| 乃东县| 武冈市| 乌兰察布市| 钟山县| 平利县| 沙坪坝区| 江北区| 阿巴嘎旗| 巴楚县| 黄梅县| 和顺县| 南宁市| 彰武县| 广宁县| 长阳| 都昌县| 平顺县| 胶南市| 定结县| 满城县| 东乌珠穆沁旗| 玛纳斯县| 凤城市| 承德县| 阿荣旗| 顺平县| 札达县| 嘉黎县| 丹江口市| 栾川县| 天津市|