//百度地图瓦片图加载示例代码(前端)
var fileHost = 'http://file.weijingtong.net';
var tileLayer = new BMap.TileLayer({isTransparentPng: true});
tileLayer.getTilesUrl = function(tileCoord, zoom) {
var x = tileCoord.x;
var y = tileCoord.y;
var imagePath;
var hasImg = true;
if (false) {}
//超出瓦片图范围
else if( zoom == 10 && (x < 182 || x > 182 || y < 52 || y > 53 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 11 && (x < 364 || x > 364 || y < 105 || y > 106 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 12 && (x < 728 || x > 728 || y < 211 || y > 212 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 13 && (x < 1457 || x > 1457 || y < 423 || y > 424 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 14 && (x < 2914 || x > 2915 || y < 847 || y > 848 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 15 && (x < 5829 || x > 5830 || y < 1695 || y > 1696 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 16 && (x < 11658 || x > 11661 || y < 3390 || y > 3392 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 17 && (x < 23316 || x > 23323 || y < 6780 || y > 6785 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 18 && (x < 46632 || x > 46647 || y < 13560 || y > 13570 ) ){
hasImg = false;
}
//超出瓦片图范围
else if( zoom == 19 && (x < 93265 || x > 93294 || y < 27121 || y > 27142 ) ){
hasImg = false;
}
if (!hasImg) {
imagePath = fileHost + "/uploades/images/image/37/20210713/160026_732753.png"; //透明占位图
}
else{
imagePath = fileHost + "/uploades/map/map_37/" + zoom + "/tile" + x + "_" + y + '.png?v=2021-08-07-00-14-02'; //根据当前坐标,选取合适的瓦片图
}
return imagePath;
}
var map = new BMap.Map('allmap', {enableMapClick: false, minZoom: 10, maxZoom: 19});
map.addTileLayer(tileLayer);