openlayer4加载百度地图
Posted yang_chuanlong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ) );
以上是关于openlayer4加载百度地图的主要内容,如果未能解决你的问题,请参考以下文章