<%--
  Created by IntelliJ IDEA.
  User: lgj
  Date: 2018/7/27
  Time: 10:46
  闪送根据经纬度显示轨迹
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>闪送地图</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3hFCEOjrMGFeGUR4uLr5XznVnPvi0wZG"></script>
    <script src="http://c.cnzz.com/core.php"></script>
    <style type="text/css">
        body, html {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
        #allmap {position:absolute;left:0px;width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
</head>
<body>
<div id="allmap" ></div>
<script type="text/javascript">
    //var list = [{Long:106.652024,Lat:26.617221},{Long:106.652024,Lat:26.614221},{Long:106.654024,Lat:26.612221},{Long:106.657024,Lat:26.612221}];

    var list = "";
    var urlParameters = location.search;
    var requestParameters = new Object();
    if (urlParameters.indexOf('?') != -1)
    {
        var parameters = decodeURI(urlParameters.substr(1));
        parameterArray = parameters.split('&');
        for (var i = 0; i < parameterArray.length; i++) {
            requestParameters[parameterArray[i].split('=')[0]] = (parameterArray[i].split('=')[1]);
        }
        list = JSON.parse(requestParameters.mapData) ;
    }
//  list = [{Long:106.652024,Lat:26.617221},{Long:106.652024,Lat:26.614221},{Long:106.654024,Lat:26.612221},{Long:106.657024,Lat:26.612221}]
    var listLast = list.length-1;
    // 百度地图API功能
    var map = new BMap.Map("allmap");    // 创建Map实例
    map.centerAndZoom(new BMap.Point(list[0].Long,list[0].Lat), 15);  // 初始化地图,设置中心点坐标和地图级别
    map.addControl(new BMap.MapTypeControl());   //添加地图类型控件

    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放

    setTimeout(drawIcon,500);
    var carMk;
    var myBeginIcon = new BMap.Icon("http://e.hiphotos.baidu.com/image/pic/item/7e3e6709c93d70cfaf72bca2f0dcd100bba12b90.jpg", new BMap.Size(25,37), {imageOffset: new BMap.Size(0, 0)});//人
    var curIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {
        offset: new BMap.Size(10, 25), // 指定定位位置
        imageOffset: new BMap.Size(0, 0 - 11 * 25) // 设置图片偏移
    });
    var myEndIcon = new BMap.Icon("http://b.hiphotos.baidu.com/image/pic/item/b58f8c5494eef01f534c096ae8fe9925bd317dc0.jpg", new BMap.Size(25,37), {imageOffset: new BMap.Size(0, 0)});//人

    function drawGreenLine(i){
        var polyline = new BMap.Polyline([
            new BMap.Point(list[i].Long,list[i].Lat),//起始点的经纬度
            new BMap.Point(list[i+1].Long,list[i+1].Lat)//终点的经纬度
        ], {strokeColor:"green",//设置颜色
            strokeWeight:4, //宽度
            strokeOpacity:1});//透明度
        map.addOverlay(polyline);
    }

    function drawIcon(){
        if(carMk){
            map.removeOverlay(carMk);
        }
        carMk2 = new BMap.Marker(
            new BMap.Point(list[0].Long,list[0].Lat),//起始点的经纬度
            {icon:myBeginIcon});
        map.addOverlay(carMk2);

        carMk = new BMap.Marker(
            new BMap.Point(list[listLast].Long,list[listLast].Lat),//终点的经纬度
            {icon:myEndIcon});
        map.addOverlay(carMk);

        carMk3 = new BMap.Marker(
            new BMap.Point(list[listLast-1].Long,list[listLast-1].Lat),//快递员所在的经纬度
            {icon:curIcon});
        map.addOverlay(carMk3);

        for(var i=0;i<list.length-1;i++){
            drawGreenLine(i);
        }

    }
</script>
</body>
</html>
