;(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;
})();