百度地图轨迹

 function guigui(){
     //alert("fdhkj");
      // 百度地图定义中心点
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);
    // 百度地图滚轮可缩放
    map.enableScrollWheelZoom();
    // 复杂的自定义覆盖物(构造函数)
    function ComplexCustomOverlay(point, text, mouseoverText,index,linetext,linecolor){
      this._point = point; // 经纬度
     // this._text = text;  // 显示文字
     // this._overText = mouseoverText; // 鼠标移入后显示的文字
      this._index = index // 表示第几个点
      this._linetext = linetext;
      this._linecolor = linecolor;
    }
    ComplexCustomOverlay.prototype = new BMap.Overlay();// 继承百度覆盖物
    ComplexCustomOverlay.prototype.initialize = function(map){
      this._map = map;
      var div = this._div = document.createElement("div");
      div.style.position = "absolute";
      div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
      div.style.backgroundColor = this._linecolor;
      div.style.color = "red";
      div.style.height = "20px";//圆点的大小
      div.style.width = "20px";//圆点的大小
      div.style.borderRadius = '50%';
      div.style.whiteSpace = "nowrap";
      div.style.MozUserSelect = "none";
      div.style.fontSize = "12px";
      div.style.opacity = 1;
      div.className = 'circleDiv'+this._linetext+this._index +' animated pulse infinite' 
      map.getPanes().labelPane.appendChild(div);
      return div;
    }
    ComplexCustomOverlay.prototype.draw = function(){
      var map = this._map;
      var pixel = map.pointToOverlayPixel(this._point);
      this._div.style.left = pixel.x +40 + "px";
      this._div.style.top  = pixel.y + "px";
    }   
    var date = [{'linedata': [39.91901, 39.918101 ,39.917101, 39.916101, 39.915101, 39.914101, 39.913101, 39.122101, 39.911101, 39.910101, 39.909101, 39.905758],'linecolor':'blue','linetext':'line2'}
                ];
    var date1 = [116.407845, 116.407845 ,116.407845, 116.407845, 116.407845, 116.407845, 116.407845,116.407845, 116.407845, 116.407845, 116.407845,116.428362];
date.forEach(function(value){
    adddot(value)
})
function adddot(data){
     // 一条线路的打点
    var i;
    for (i in data.linedata) {
        //for (var c in data2.lin){
        // 闭包
        (function(i,data) {
            setTimeout(function() {
                // 每隔3s创建一个点
                var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(date1[i],data.linedata[i]), "",'mousetext',i,data.linetext,data.linecolor);
                map.addOverlay(myCompOverlay);
            }, i*(10/data.linedata.length)*3000); 
        })(i,data)
    }
    }
}

 

 

百度地图轨迹_第1张图片

你可能感兴趣的:(百度地图)