我已经使用第一个代码在OpenLayers中显示Bergfex图层,这适用于高变焦图层,而我无法在Shift 12上方使用Leaflet图层。
有人知道这是限制还是需要其他元素?我已经尝试过它作为基础层或叠加层。这两组代码都在下面。
的OpenLayers:
bergfex = new OpenLayers.Layer.XYZ("Bergfex Topo Austria",
"http://static7.bergfex.at/images/amap/${z}$folder/${z}_${x}_${y}.png", {
sphericalMercator: true,
buffer: 0,
opacity: 0.5,
isBaseLayer: false,
visibility: false,
attribution: "© 2008, 2013 BEV,<a href='http://www.bergfex.at'>bergfex GmbH</a>",
getURL: function(bounds) {
var path = OpenLayers.Layer.XYZ.prototype.getURL.apply(this, arguments);
var parts = path.split("$folder/");
var z = parseInt(parts[0].substr(-2));
path = path.replace("$folder", z >= 14 ?
"/" + parts[1].substr(3, 2 + z - 14) : "");
return path;
}
});
单张:
bf = L.tileLayer('http://static7.bergfex.at/images/amap/{z}/{z}_{x}_{y}.png', {
maxZoom: 18,
attribution: bergfexAttribution,
detectRetina: true
})
答案 0 :(得分:1)
您的宣传单代码('http://static7.bergfex.at/images/amap/{z}/{z}_{x}_{y}.png'
)中使用的网址模板的图块仅在奥地利上方可用,并且从缩放级别8到13(包括在内)。从缩放0到7(包括),以及缩放14及以上,没有任何图块(404错误)。
为避免不必要的网络请求,您可能有兴趣使用minZoom
和bounds
平铺图层选项:
bf = L.tileLayer('http://static7.bergfex.at/images/amap/{z}/{z}_{x}_{y}.png', {
maxZoom: 13,
minZoom: 8,
bounds: [
[45, 10], // I just used arbitrary bounds, you should adjust them.
[50, 15]
],
attribution: bergfexAttribution,
detectRetina: true
});
现在,要超越缩放级别13,您的OpenLayers代码会动态更改该网址模板(请参阅getURL
选项),因此它看起来像'http://static7.bergfex.at/images/amap/{z}/{x2}/{z}_{x}_{y}.png'
,其中x2
是前2位数字缩放14的x
和缩放15的前3个(可能等等)。
您需要为Leaflet执行类似的“URL模板动态调整”。不幸的是,Leaflet没有公开与OpenLayers类似的getURL
选项。不过,您可以修改bf
Tile Layer实例的getTileUrl
method,以便进行调整(您必须调整OpenLayers代码):
var bf2 = L.tileLayer('http://static7.bergfex.at/images/amap/{z}/{x2}/{z}_{x}_{y}.png', {
maxZoom: 18, // Looks like tiles are available only up to 15 included, or the URL template changes again?
minZoom: 14,
bounds: [
[45, 10], // I just used arbitrary bounds, you should adjust them.
[50, 15]
],
attribution: bergfexAttribution,
detectRetina: true
});
bf2.getTileUrl = function (tilePoint) {
var x2 = Math.floor(tilePoint.x / 100);
return L.Util.template(this._url, L.extend({
s: this._getSubdomain(tilePoint),
z: tilePoint.z,
x: tilePoint.x,
y: tilePoint.y,
x2: x2
}, this.options));
};
bf2.addTo(map);