1. 程式人生 > >mui 地圖軌跡回放

mui 地圖軌跡回放

ava 4.2 行數 jquer ctype tom move state 根據

<!doctype html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" href="fonts1/iconfont.css" />
<style type="text/css">
#map {
width: 100%;
position: fixed;
top: 44px;
bottom: 0px;
line-height: 200px;
text-align: center;
background: #FFFFFF;
}
.bhj{
height: 40px;
width: 40px;
line-height: 40px;
}
</style>
</head>

<body>
<div class="mui-content">
<div id="maps" style="width: 100%;height: 31rem;">

</div>
</div>
<nav class="mui-bar mui-bar-tab" style="background: #FFFFFF;text-align: center;padding-top: 0.5rem;">
<div class="mui-input-row mui-input-range field-contain">
<div style="float:left" class="iconfont icon-bofang1 bhj" id="bofang"></div>
<div style="float:left" class="iconfont icon-zhongbo bhj" id="chongbo"></div>
</div>

</nav>
<script src="js/mui.js"></script>
<script src="js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=4IU3oIAMpZhfWZsMu7xzqBBAf6vMHcoa"></script><!--ak值可以自己百度地圖申請-->
<script type="text/javascript">
mui.init();
var map = null;
var playSpeed = 160; //正常播放間隔是160毫秒,可以根據自己需求設置播放速率
var pointstart = [];//開始點
var pointend = [];//結束點
var stopoff=false;//暫停開關false暫停 true開始
var points = [];//所有線軌跡點集合
var numi = 0;//當前執行數目
var timer = null;//定時器
var onwpoint=null;//軌跡播放時的當前點
mui.plusReady(function() {
plusReady();
});
function plusReady() {
var view = plus.webview.currentWebview();
map = new plus.maps.Map(‘maps‘); // 創建地圖實例
Geolocation()//設置地圖
getGuiJiData()//模擬服務器請求數據
function getGuiJiData(){
var data={//服務器請求來的數據格式
"rows": [{
"POINT_Y": "108.916889",
"POINT_X": "34.259502"
}, {
"POINT_Y": "108.916889",
"POINT_X": "34.259502"
}, {
"POINT_Y": "108.916889",
"POINT_X": "34.259502"
}, {
"POINT_Y": "108.916889",
"POINT_X": "34.259502"
}, {
"POINT_Y": "108.916571",
"POINT_X": "34.259776"
}, {
"POINT_Y": "108.916591",
"POINT_X": "34.259779"
}, {
"POINT_Y": "108.916625",
"POINT_X": "34.25982"
}, {
"POINT_Y": "108.916657",
"POINT_X": "34.25992"
}, {
"POINT_Y": "108.916677",
"POINT_X": "34.260004"
}, {
"POINT_Y": "108.916703",
"POINT_X": "34.260071"
}, {
"POINT_Y": "108.916749",
"POINT_X": "34.260137"
}, {
"POINT_Y": "108.916784",
"POINT_X": "34.260157"
}],
"result": "success"
}
guiJiTotal = data.rows.length;
if (data.rows.length>=2) {
pointstart.push(new plus.maps.Point(data.rows[0].POINT_Y,data.rows[0].POINT_X));//把軌跡的第一個點設置為起點
//設置起點marker
var marker = new plus.maps.Marker(new plus.maps.Point(data.rows[0].POINT_Y, data.rows[0].POINT_X));
marker.setIcon("images/start.png");
marker.setLabel("起點");
map.addOverlay(marker);

pointend.push(data.rows[data.rows.length - 1].POINT_Y,data.rows[data.rows.length - 1].POINT_X);//把軌跡的最後一個點設置為終點
//設置終點marker
var marker = new plus.maps.Marker(new plus.maps.Point( data.rows[data.rows.length - 1].POINT_Y,data.rows[data.rows.length - 1].POINT_X));
marker.setIcon("images/end.png");
marker.setLabel("終點");
map.addOverlay(marker);
}
//把請求的點集合存到points集合裏
for (var i = 0; i < data.rows.length; i++) {
var longtitude =data.rows[i].POINT_Y;
var latitude = data.rows[i].POINT_X;
points.push(new plus.maps.Point(longtitude, latitude));
}
//開始畫軌跡
timer = setInterval(clock, playSpeed);
}

//定時繪制軌跡
function showLine() {
if(stopoff==false){
return;
}
//兩點畫一個線
var polylineObj = null;
var point_line = [];
point_line[0] = new plus.maps.Point(points[numi].longitude, points[numi].latitude);
point_line[1] = new plus.maps.Point(points[numi+1].longitude, points[numi+1].latitude);
map.setCenter((point_line[1])); //設置當前點為地圖中心點
polylineObj = new plus.maps.Polyline(point_line);
polylineObj.setLineWidth(6);//設置線的粗細(Android和ios顯示粗細不一樣)
polylineObj.setStrokeColor("#c3421a");//設置線的顏色
map.addOverlay(polylineObj);
//設置當前運行點的marker
var marker = new plus.maps.Marker(point_line[1]);
marker.setIcon("images/1.png");
map.removeOverlay(onwpoint)
onwpoint=marker;
map.addOverlay(marker);
numi++;
}
function clock() {
showLine();
if (numi >= guiJiTotal - 1) {
stopoff=false;
$("#bofang").removeClass("icon-bofang ");
$("#bofang").addClass("icon-bofang1");
clearInterval(timer);
}

}
//開始/暫停播放切換
mui(".mui-bar").on("tap","#bofang",function(){//設置暫停,開始的圖標,用阿裏適量圖。可以自己阿裏適量圖庫下載
if(stopoff){
$("#bofang").removeClass("icon-bofang ");
$("#bofang").addClass("icon-bofang1");
}else{
$("#bofang").removeClass("icon-bofang1");
$("#bofang").addClass("icon-bofang ");
}
stopoff=!stopoff;
})
//重播
mui(".mui-bar").on("tap","#chongbo",function(){
clearInterval(timer);
pointstart=[];
points=[];
pointend=[];
numi=0;
stopoff=true;
$("#bofang").removeClass("icon-bofang1");
$("#bofang").addClass("icon-bofang ");
map.clearOverlays();//刪除地圖所有覆蓋物
getGuiJiData();
})
}

function Geolocation() {
map.setZoom(18);//顯示層級
map.showUserLocation(true);
map.showZoomControls(true);
map.getUserLocation(function(state, point) {
if (0 == state) {
if (point.latitude == ‘5e-324‘) {
mui.toast("獲取位置信息失敗:請開啟定位服務,進入系統【設置】>【隱私】>【定位服務】中打開開關!");
} else {
map.setCenter(point);
geoInf(point);

}
} else {
mui.toast("獲取位置信息失敗:請開啟定位服務,進入系統【設置】>【隱私】>【定位服務】中打開開關!");
}

});
}

function geoInf(point) {
plus.maps.Map.reverseGeocode(point, {}, function(event) {
//獲取當前地理位置
addressd = event.address; // 轉換後的地理位置
var longit = point.longitude;//
var latid = point.latitude; //緯度

});

}

</script>
</body>

</html>

mui 地圖軌跡回放