如何使这个旧代码适应 openlayers 6
var layer_ais = new OpenLayers.Layer.TMS(
"Traffic maritime",
"https://tiles.marinetraffic.com/ais_helpers/shiptilesingle.aspx?output=png&sat=1&grouping=shiptype&tile_size=512&legends=1&zoom=${z}&X=${x}&Y=${y}",
{
"layerId":2,
"displayOutsideMaxExtent":true,
"isBaseLayer":false,
"numZoomLevels":18,
"type":"png",
"url":"https:\/\/tiles.marinetraffic.com\/ais_helpers\/shiptilesingle.aspx?output=png&sat=1&grouping=shiptype&tile_size=512&legends=1&zoom=${z}&X=${x}&Y=${y}" ,
'getURL': getTileURLMarine,
'tileSize': new OpenLayers.Size(512,512)
});
我必须使用 XYZ 或 WMS 源吗?
我必须像本例中那样使用 tileUrlFunction 重新排序 zxy 参数吗?
https://openlayers.org/en/latest/examples/xyz-esri-4326-512.html
根据@Mike帮助这里是ol 6.2的工作代码
var defaultGrid = new ol.tilegrid.createXYZ({ tileSize: 256, maxZoom: 18 });
var layer_ais = new ol.layer.Tile({
source: new ol.source.XYZ({
tileGrid: new ol.tilegrid.TileGrid({
tileSize: 512,
resolutions: defaultGrid.getResolutions(),
extent: defaultGrid.getExtent()
}),
url: "https://tiles.marinetraffic.com/ais_helpers/shiptilesingle.aspx?output=png&sat=1&grouping=shiptype&tile_size=512&legends=1&zoom={z}&X={x}&Y={y}"
})
});
谢谢你的帮助 !