此为个人测试可用,具体情况实时更改优化,仅供参考(版本:ol6):
/**
* 水晶注 标准TMS 84 瓦片
*/
//1.计算每层分辨率 0-20
let resolution = [];
for (var i = 0; i <= 20; i++) {
//256 瓦片宽度
resolution[i] = 180.0 / 256.0 * 1.0 / Math.pow(2, i);
}
let layerTms = new ol.layer.Tile({
source: new ol.source.XYZ({
tileUrlFunction: function(tileCoord) {
let z = tileCoord[0];
let x = tileCoord[1];
let y = Math.pow(2, z) - tileCoord[2] - 1;
//http://127.0.01:22222/mapdata/tms/ 为TMS地址
return 'http://127.0.0.1:22222/mapdata/tms/' + z + '/' + x + '/' + y + '.jpg';
},
projection: 'EPSG:4326',
tileGrid: new ol.tilegrid.TileGrid({
//设置分辨率
resolutiions: resolution,
//设置中点
origin: [-180, 90]
}),
wrapX: !0
}),
zIndex: 0,
visible: true
});
let mhMap = new ol.Map({
view: new ol.View({
center: [110.5, 29.5],
zoom: 3,
minZoom: 3,
maxZoom: 10,
projection:'EPSG:4326'
}),
target:'map',
projection:'EPSG:4326',
layers:[layerTms]
})