openlayer4加载百度地图
var resolutions = []; for(var i=0; i<= 18; i++) { resolutions[i] = Math.pow(2, 18 - i); } var tileGrid = new ol.tilegrid.TileGrid({ origin:[0, 0], resolutions: resolutions }); var baiduSource = new ol.source.TileImage({ projection: "EPSG:3857", tileGrid: tileGrid, tileUrlFunction: function(tileCoord, pixelRatio, proj) { if(!tileCoord){ return ""; } var [z, x, y] = tileCoord; if(x < 0) { x = `M${-x}`; } if(y < 0) { y = `M${-y}`; } var num = Math.floor(Math.random() * 5); return `http://online${num}.map.bdimg.com/tile/?qt=tile&x=${x}&y=${y}&z=${z}&styles=pl&scaler=2&udt=20180303`; } }); var baiduLayer = new ol.layer.Tile({ source: baiduSource }); var map = new ol.Map({ target:"map", layers:[ baiduLayer ], view: new ol.View({ center: ol.proj.fromLonLat([121.48, 31.22]), zoom: 8 }) });
转载自:https://blog.csdn.net/yang_chuanlong/article/details/79933378