function resetWin(){
|
document.getElementsByTagName('body')[0].style.height = (window.innerHeight)+'px';
|
document.getElementsByTagName('body')[0].style.width = (window.innerWidth)+'px';
|
$("#map").height($("body").height());
|
$("section").height($("body").height());
|
}
|
//
|
var routeQueryParams = {
|
type : '1',//默认驾车,1 驾车,2公交,3步行;
|
drving_policy : BMAP_DRIVING_POLICY_LEAST_TIME,//驾车策略 :默认:驾车最少时间;
|
transit_policy : BMAP_TRANSIT_POLICY_LEAST_TIME//公共交通策略:公交默认最少时间
|
};
|
$(function(){
|
resetWin();
|
});
|
// 百度地图API功能
|
var pointArray;
|
var map = new BMap.Map("map", {
|
enableMapClick : true,
|
minZoom : 10,
|
maxZoom : 19
|
}); // 创建Map实例
|
map.centerAndZoom(new BMap.Point(121.4097683, 31.29586563),13);
|
var mapStyle ={
|
features: ["road", "building","water","land"],//隐藏地图上的poi
|
style : "dark" //设置地图风格为高端黑
|
}
|
map.setMapStyle({
|
styleJson:[
|
{
|
"featureType": "road",
|
"elementType": "all",
|
"stylers": {
|
"lightness": 20
|
}
|
},
|
{
|
"featureType": "highway",
|
"elementType": "geometry",
|
"stylers": {
|
"visibility": "off"
|
}
|
},
|
{
|
"featureType": "railway",
|
"elementType": "all",
|
"stylers": {
|
"visibility": "off"
|
}
|
},
|
{
|
"featureType": "local",
|
"elementType": "labels",
|
"stylers": {
|
"visibility": "off"
|
}
|
},
|
{
|
"featureType": "water",
|
"elementType": "all",
|
"stylers": {
|
"color": "#d1e5ff"
|
}
|
},
|
{
|
"featureType": "poi",
|
"elementType": "labels",
|
"stylers": {
|
"visibility": "off"
|
}
|
}
|
]
|
});
|
map.enableScrollWheelZoom(true);
|
|
var bottom_right_navigation = new BMap.NavigationControl({
|
anchor : BMAP_ANCHOR_BOTTOM_RIGHT,
|
type : BMAP_NAVIGATION_CONTROL_SMALL
|
}); // 右下角
|
map.addControl(bottom_right_navigation);
|
|
//map.addEventListener("zoomend", checkLevel);//缩放监听事件
|
//地图缩放触发
|
|
var layer_load ;
|
|
var markerClusterer;// 点聚合对象
|
var markers = [];// 点集合数组
|
var select = false;
|
|
|
// 对结果的截取,不选()后和null
|
function split_str(a){
|
if(a == "null" || a == null){
|
return "无";
|
}else if(a.split("(")[0] != ""){
|
return a.split("(")[0];
|
}else{
|
return a;
|
}
|
}
|
|
|
var layer_bot;//单个点的底部
|
var layer_route;//三种出行方式的底部
|
var layer_planlist;//三种出行方式的规划路线底部
|
|
//右上角定位
|
function positioning() {
|
$(".range_box").hide();
|
if($("#tab").is(":hidden")){
|
layer_load = layer.open({
|
type : 2,
|
content : '加载中'
|
});
|
map.centerAndZoom(new BMap.Point(121.4071683, 31.22786563),13);
|
map.clearOverlays();
|
map.addOverlay(changning_polygon);
|
boundaryLabel();
|
full_pos();
|
}else{
|
search_leader();
|
}
|
}
|
//底部框的导航
|
function search_leader(){
|
if(routeQueryParams.type == '1'){
|
$(".driving_plan").show();
|
$(".transit_plan").hide();
|
}else if(routeQueryParams.type == '2'){
|
$(".driving_plan").hide();
|
$(".transit_plan").show();
|
}else{
|
$(".driving_plan").hide();
|
$(".transit_plan").hide();
|
}
|
layer_load = layer.open({
|
type : 2,
|
content : '加载中'
|
});
|
geciPos();
|
map.clearOverlays();
|
}
|
|
|
//出行方式切换
|
var tab = new auiTab({
|
element:document.getElementById("tab"),
|
},function(ret){
|
routeQueryParams.type = String(ret.index);
|
search_leader();
|
});
|
|
//驾车策略切换
|
function driving_Policychange(me,ind){
|
$(me).addClass("self-active").siblings().removeClass("self-active");
|
if(ind == '1'){
|
routeQueryParams.drving_policy = BMAP_DRIVING_POLICY_LEAST_TIME;//最少时间
|
}else if(ind == '2'){
|
routeQueryParams.drving_policy = BMAP_DRIVING_POLICY_LEAST_DISTANCE;//最短距离
|
}else{
|
routeQueryParams.drving_policy = BMAP_DRIVING_POLICY_AVOID_HIGHWAYS;//避开高速
|
}
|
search_leader();
|
}
|
|
//公共交通策略切换
|
function transit_Policychange(me,ind){
|
$(me).addClass("self-active").siblings().removeClass("self-active");
|
if(ind == '1'){
|
routeQueryParams.transit_policy = BMAP_TRANSIT_POLICY_LEAST_TIME;//最少时间
|
}else if(ind == '2'){
|
routeQueryParams.transit_policy = BMAP_TRANSIT_POLICY_LEAST_TRANSFER;//最少换乘
|
}else{
|
routeQueryParams.transit_policy = BMAP_TRANSIT_POLICY_LEAST_WALKING;//最少步行
|
}
|
search_leader();
|
}
|
|
//规划路线面板
|
function route_plan(output){
|
$("#route_detail").html(output);
|
layer.close(layer_route);
|
var box = $("#RoutePlan").html();
|
layer.close(layer_route);
|
layer_route = layer.open({
|
type : 1,
|
content : box,
|
anim : 'up',
|
shade : false,
|
shadeClose : false,
|
style : 'position:fixed; bottom:0; left:0; width: 100%; height: 60px;border:none;'
|
});
|
|
}
|
|
//查看路线详情
|
function showPlan_list(){
|
layer.close(layer_planlist);
|
var box = $("#Plan_list").html();
|
layer_planlist = layer.open({
|
type : 1,
|
content : box,
|
anim : 'up',
|
shade: 'background-color: rgba(0,0,0,.6)', //自定义遮罩的透明度
|
shadeClose : true,
|
style : 'position:fixed; bottom:0; left:0; width: 100%; height:70%;border:none;'
|
});
|
}
|
var output = "";//规划路线返回时间和总程;
|
var output_route = "";
|
function getQueryString(name) {
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); // 匹配目标参数
|
var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
|
if (result != null) {
|
return decodeURIComponent(result[2]);
|
} else {
|
return null;
|
}
|
}
|
//导航路线搜索完毕后加载路线详情
|
var searchComplete = function (results){
|
output = "约";
|
output_route = "";
|
var plan = results.getPlan(0);//获取第一条方案
|
var route = plan.getRoute(0);//获取方案的驾车线路
|
var s = "";
|
if(routeQueryParams.type == '2'){//公交出行
|
$(".aui-timeline-item-header").hide();
|
$(".routeMsg").removeClass("aui-timeline");
|
for (i = 0; i < results.getNumPlans(); i++){//返回方案个数
|
var Dochtml = results.getPlan(i).getDescription(false).split(",");
|
var bus_jingguo = 0;
|
var p = /[0-9]/;
|
for(var k = 0;k<Dochtml.length;k++){
|
if(Dochtml[k].indexOf("经过") != -1 ){
|
bus_jingguo += parseFloat(Dochtml[k].substring(2,Dochtml[k].length-1));
|
}
|
}//站数统计
|
s += '<div class="bus_list">';
|
s += '<div class="bus_fl"><p>'+results.getPlan(i).getDuration(true)+'</p><p>'+ Dochtml[0] + '</p></div>';//总时长+步行
|
s += '<div class="bus_fr"><p><span class="fa fa-bus bus_icon"></span>'+results.getPlan(i).getLine(i).title+'</p><p class="sub_msg"><span>'+ results.getPlan(i).getDistance(true) +'</span><span class="aft_dot"></span><span>'+ bus_jingguo+'站</span></p></div>';//交通路线,距离,站数
|
s += '</div>';
|
s += '<div class="aui-timeline timeline_bus">';
|
s += '<div class="aui-timeline-item timeline_msg" style="margin: 0 0 0.25rem 1.45rem;"><div class="self-dot self-dotbegin"></div><div class="aui-label aui-labelendbeg">起点:'+myAdd_str+'</div></div>';
|
for(var i=0;i<Dochtml.length;i++){
|
s += '<div class="aui-timeline-item timeline_msg" style="margin: 0 0 0.25rem 1.45rem;"><div class="self-dot"></div><div class="aui-label">' + Dochtml[i] + '</div></div>';
|
}
|
s += '<div class="aui-timeline-item timeline_msg" style="margin: 0 0 0.25rem 1.45rem;"><div class="self-dot self-dotend"></div><div class="aui-label aui-labelendbeg">终点:'+getQueryString("end_place")+'</div></div>';
|
s += '</div>';
|
}
|
}else{
|
$(".aui-timeline-item-header").show();
|
$(".routeMsg").addClass("aui-timeline");
|
s += '<div class="aui-timeline-item timeline_msg"><div class="self-dot self-dotbegin"></div><div class="aui-label aui-labelendbeg">起点:'+myAdd_str+'</div></div>';
|
for(var j = 0;j < plan.getNumRoutes(); j++){
|
var route = plan.getRoute(j);
|
for (var i = 0; i < route.getNumSteps(); i++){//result.getPlan(i).getDescription(false));
|
var step = route.getStep(i);
|
s += '<div class="aui-timeline-item timeline_msg"><div class="self-dot"></div><div class="aui-label">';
|
s += step.getDescription();
|
s += '</div></div>';
|
}
|
}
|
s += '<div class="aui-timeline-item timeline_msg"><div class="self-dot self-dotend"></div><div class="aui-label aui-labelendbeg">终点:'+getQueryString("end_place")+'</div></div>';
|
}
|
output_route = s;
|
console.log(output_route);
|
$("#routeMsg").html(output_route);
|
$("#route_time").html(" "+plan.getDuration(true));
|
$("#route_long").html(" "+plan.getDistance(true));
|
output += plan.getDuration(true) + " ";//获取时间
|
output += plan.getDistance(true);//获取距离
|
}
|
|
function back_index(){
|
window.history.back();
|
|
}
|
var myAdd_str = "";//本人地址字符串;
|
function geciPos(){
|
var pos_data = eval('(' + sessionStorage.getItem("leaderData") + ')');
|
myAdd_str = "";
|
//通用设置
|
var startIcon = new BMap.Icon("./image/begin.png", new BMap.Size(26, 26), {
|
anchor: new BMap.Size(20, 25), // 指定定位位置
|
});
|
var endIcon = new BMap.Icon("./image/end.png", new BMap.Size(26, 26), {
|
anchor: new BMap.Size(20, 25), // 指定定位位置
|
});
|
var geolocation = new BMap.Geolocation();
|
geolocation.getCurrentPosition(function(r){
|
if(this.getStatus() == BMAP_STATUS_SUCCESS){//获取经纬度成功
|
var mk = new BMap.Marker(r.point);//本人位置
|
var add = r.address;
|
myAdd_str = add.district + add.street + add.street_number;
|
console.log(myAdd_str);
|
var start = new BMap.Point(r.point.lng,r.point.lat);//起始
|
var end = new BMap.Point(pos_data.b_x,pos_data.b_y);//终点
|
switch(routeQueryParams.type){
|
case '1':
|
var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map},
|
policy : routeQueryParams.drving_policy,
|
onSearchComplete: searchComplete,
|
onPolylinesSet: function(){
|
route_plan(output);
|
}
|
});
|
driving.clearResults();
|
driving.setLocation("上海市");
|
driving.search(start, end);//驾车搜索
|
driving.setMarkersSetCallback(function(result){
|
result[0].marker.setIcon(startIcon);
|
result[1].marker.setIcon(endIcon);
|
});
|
break;//驾车
|
case '2':
|
var transit = new BMap.TransitRoute(map, {renderOptions: {map: map},
|
pageCapacity : 1,
|
policy : routeQueryParams.transit_policy,
|
onSearchComplete: searchComplete,
|
onPolylinesSet: function(){
|
route_plan(output);
|
}
|
});
|
transit.clearResults();
|
transit.setLocation("上海市");
|
transit.search(start, end);
|
transit.setMarkersSetCallback(function(result){
|
result[0].marker.setIcon(startIcon);
|
result[1].marker.setIcon(endIcon);
|
});
|
break;//公交
|
case '3':
|
var walking = new BMap.WalkingRoute(map, {renderOptions:{map: map, autoViewport: true},
|
onSearchComplete: searchComplete,
|
onPolylinesSet: function(){
|
route_plan(output);
|
}
|
});
|
walking.clearResults();
|
walking.setLocation("上海市");
|
walking.search(start, end);
|
walking.setMarkersSetCallback(function(result){
|
result[0].marker.setIcon(startIcon);
|
result[1].marker.setIcon(endIcon);
|
});
|
break;//步行
|
}
|
layer.close(layer_load);
|
}
|
else {
|
layer.open({
|
content: '位置获取失败',
|
skin: 'msg',
|
time: 2 //2秒后自动关闭
|
});
|
}
|
},{enableHighAccuracy: true})
|
}
|