openlayers-3 - 如何通过调用 TMS 来调整旧的 openlayers 代码到 openlayers6
问题描述
如何使这个旧代码适应 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}"
})
});
谢谢你的帮助 !
解决方案
你有一个 XYZ url,所以你不能 WMS。如果你有一个标准的平铺网格,你可以使用一个 {-y} 占位符($ 不再用于占位符):
var layer_ais = new ol.layer.TileLayer({
source: new ol.source.XYZ({
maxZoom: 18,
tileSize: 512,
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}'
})
});
推荐阅读
- powershell - Powershell在退出do-until循环后提前终止
- jquery - 未捕获的类型错误:无法读取未定义的属性 XXX
- sql - SQL:如何以 30 秒为间隔进行分组并标记该分组中的最大时间?
- java - Spring kafka:无法将消息发送到通道有效负载不能为空
- google-cloud-platform - 将参数传递给 GCMLE 预测图
- java - 当类由可变属性组成时如何确保类的不变性
- regex - 正则表达式在具有反应形式的 Angular 2+ 管道内失败
- google-sheets - 如何使用 Google 表格自定义功能来检测是否添加了行?
- r - 是否在 r 中启动包,使用第一个返回(结果)作为观察数据来计算置信区间
- php - 对组感到困惑,并在 php 中有子句