View Code
var tileLayer = new BMap.TileLayer(); tileLayer.getTilesUrl = function (tileCoord, zoom) { var x = tileCoord.x; var y = tileCoord.y; var url = GetPyPx(x, y, zoom); return url; } var MyMap = new BMap.MapType('MyMap', tileLayer, { minZoom: 1, maxZoom: 3 });//定义缩放级别(目前到3级) var map = new BMap.Map('container', { mapType: MyMap }); map.addControl(new BMap.NavigationControl()); map.centerAndZoom(new BMap.Point(0,0), 1);
/*添加标注*/ map.addEventListener("click", showInfo); var ptY, ptX = ''; var marker = new BMap.Marker(new BMap.Point(ptY, ptX)); function showInfo(e) { document.getElementById("info").innerHTML = e.point.lng + ", " + e.point.lat; //var marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat)); //collectClick = e; marker.point.lng = e.point.lng; marker.point.lat = e.point.lat; map.addOverlay(marker); }
///坐标系坐标转化为矩阵坐标 function GetPyPx(x, y, zoom) { var level = map["zoomLevel"]; var px, py = ''; var url = ''; if (level == 1) { if (x >= -2 && x <= 1 && y >= -2 && y <= 1) { px = Math.abs(y - 1); py = Math.abs(x + 2); if (px >= 0 && px <= 3 && py >= 0 && py <= 3) { url = '...图层地址/Images/flw/' + zoom + '/' + zoom + '_' + px + '_' + py + '.jpg'; } else { url = ''; } } return url; } if (level == 2) { if (x >= -4 && x <= 3 && y >= -4 && y <= 3) { px = Math.abs(y - 3); py = Math.abs(x + 4); if (px >= 0 && px <= 7 && py >= 0 && py <= 7) { url = '...图层地址/Images/flw/' + zoom + '/' + zoom + '_' + px + '_' + py + '.jpg'; } else { url = ''; } } return url; } if (level == 3) { if (x >= -8 && x <= 7 && y >= -8 && y <= 7) { px = Math.abs(y - 7); py = Math.abs(x + 8); if (px >= 0 && px <= 15 && py >= 0 && py <= 15) { url = '..图层地址/Images/flw/' + zoom + '/' + zoom + '_' + px + '_' + py + '.jpg'; } else { url = ''; } } return url; } }
GetPyPx(x, y, zoom) 这个是用来将谷歌的切图工具转为 百度的坐标系 可以将图完整的展现.