绘制折线
//绘制折线; function drawLine(data) { //数据格式; //var data = ["116.399, 39.910;116.405, 39.920;116.423493, 39.907445", "116.405, 39.920;116.41248,39.927893"]; var opts = {strokeColor: "blue", strokeWeight: 2, strokeOpacity: 0.5}; for (var j = 0; j < data.length; j++) { var arr = data[j].split(";") var lineArr = []; for (var i = 0; i < arr.length; i++) { lineArr.push(new BMap.Point(arr[i].split(",")[0], arr[i].split(",")[1])) } //创建折线 var polyline = new BMap.Polyline(lineArr, opts); //增加折线 map.addOverlay(polyline); } }
绘制多边形
//绘制多边形; function drawPolygon(arr) { map.clearOverlays(); var ops = { strokeColor: "rgba(0,0,0,1)", fillColor: "rgba(0,0,0,1)", fillOpacity: 0.4, strokeOpacity: 0.1 }; //添加覆盖物; var ply = []; for (var i = 0; i < arr.length; i++) { ply[i] = new BMap.Polygon(arr[i], ops); map.addOverlay(ply[i]); } }
lockdatav Done!