Baidu map values are plotted trajectory based on latitude and longitude coordinates.

Map new new BMap.Map = var ( "Map");
var = new new BMap.Point Point (116.404, 39.915);
map.centerAndZoom (Point, 15);
map.enableScrollWheelZoom (); // open the mouse wheel zooming
map.addControl (new BMap.ScaleControl ()); // add scale control

var pointStr = "104.038748,30.641821,104.047789,30.648128,104.063959,30.655336,104.067264,30.660307,104.067264,30.664438,104.064008,30.665316".split(",");
var pointArr = [];

for (var k = 0; k < pointStr.length; k += 2) {
pointArr.push({
lng: pointStr[k],
lat: pointStr[k + 1]
});
}

// 生成坐标点
var trackPoint = [];
for (var i = 0, j = pointArr.length; i < j; i++) {
trackPoint.push(new BMap.Point(pointArr[i].lng, pointArr[i].lat));
}

map.centerAndZoom(trackPoint[0], 15);

// 画线
var polyline = new BMap.Polyline(trackPoint, {
strokeColor: "#1869AD",
strokeWeight: 3,
strokeOpacity: 1
});
map.addOverlay(polyline);

// 配置图片
var size = new BMap.Size(26, 26);
var offset = new BMap.Size(0, -13);
var imageSize = new BMap.Size(26, 26);
var icon = new BMap.Icon("./express-position.png", size, {
imageSize: imageSize
});

// 画图标
for (var i = 0, j = trackPoint.length; i < j; i++) {
var marker = new BMap.Marker(trackPoint[i], {
icon: icon,
offset: offset
}); // 创建标注
map.addOverlay(marker);

}

// Calculate the blooming level based on latitude and longitude extremes. (Copied from the Internet)
function getZoom (maxLng, minLng, maxLat, minLat) {
var Zoom = [ "50", "100", "200 is", "500", "1000", "2000", "5000", " 10000 "," 20000 "," 25000 "," 50000 "," 100000 "," 200000 "," 500000 "," 1000000 "," 2000000 "]; // level 18-3.
var pointA = new BMap.Point (maxLng, maxLat); // create point coordinate A
var = pointB new new BMap.Point (minLng, minLat); // Creates a new Point B
var map.getDistance Distance = (PointA, pointB). toFixed (1); // Get distance between two points, to two decimal places
for (var I = 0, = zoomLen zoom.length; I <zoomLen; I ++) {
IF (Zoom [I] - distance> 0) {
return 18 - i + 3; // The reason more than 3, because the scope of the map is often more than 10 times the distance scale. It will increase the level 3.
}
}
}

// (copied from the Internet)
function the setZoom (Points) {
if (points.length > (http://www.amjmh.com/v/BIBRGZ_558768/)0) {
var maxLng = points[0].lng;
var minLng = points[0].lng;
var maxLat = points[0].lat;
var minLat = points[0].lat;
var res;
for (var i = points.length - 1; i >= 0; i--) {
res = points[i];
if (res.lng > maxLng) maxLng = res.lng;
if (res.lng < minLng) minLng = res.lng;
if (res.lat > maxLat) maxLat = res.lat;
if (res.lat < minLat) minLat = res.lat;
}
var cenLng = (parseFloat(maxLng) + parseFloat(minLng)) / 2;
var cenLat = (parseFloat(maxLat) + parseFloat(minLat)) / 2;
var zoom = getZoom(maxLng, minLng, maxLat, minLat);
map.centerAndZoom (new new BMap.Point (cenLng, cenLat), Zoom);
} the else {
// no coordinates, displaying all Chinese
map.centerAndZoom (new new BMap.Point (103.388611, 35.563611),. 5);
}
}

setZoom (Pointarr)

 

Guess you like

Origin www.cnblogs.com/ly570/p/11488509.html