javascript - Inverted Y axis of custom tile images names
问题描述
There is a know problem of Leaflet that when you use a custom tile provider, not with real earth images, set crs: L.CRS.Simple, Leaflet queries for images where Y coordinate is inverted in comparison to the math axis. So the first top-right image's location is 1x-1 instead of 1x1.
In the internet topics about inverting Y axis are rather old, so my question is: nowadays is there a normal short and built-in way to invert queried Y axis?
The only old solutions I've found were rewriting Leaflet internal objects, like extending L.CRS.Simple.
解决方案
如WMS/TMS 的 Leaflet 教程中所述,将 Y 坐标反转为瓦片坐标的规范方法是使用{-y}
而不是{y}
在瓦片 URL 模板中。例如:
var layer = L.tileLayer('http://base_url/tms/1.0.0/tileset/{z}/{x}/{-y}.png');
但是请注意,(从 Leaflet 1.3.1 开始)仅适用于具有非无限坐标系的地图。
在您的情况下,您可能希望通过创建自己的L.TileLayer
. 有一个关于扩展层的 Leaflet 教程的完整指南,但是 TL;DR 版本的 tilelayer 可以改变其 tile 坐标是:
L.TileLayer.CustomCoords = L.TileLayer.extend({
getTileUrl: function(tilecoords) {
tilecoords.x = tilecoords.x + 4;
tilecoords.y = tilecoords.y - 8;
tilecoords.z = tilecoords.z + 1;
return L.TileLayer.prototype.getTileUrl.call(this, tilecoords);
}
});
var layer = new L.TileLayer.CustomCoords(....);
仅反转 Y 坐标的具体情况是:
L.TileLayer.InvertedY = L.TileLayer.extend({
getTileUrl: function(tilecoords) {
tilecoords.y = -tilecoords.y;
return L.TileLayer.prototype.getTileUrl.call(this, tilecoords);
}
});
var layer = new L.TileLayer.InvertedY(....);
推荐阅读
- php - password_verify() 如何使用相同的密码?
- scala - Spark SQL中数据库名称中的转义关键字
- javascript - 如何在大多数 cypress 测试之前运行,但不是全部
- unity3d - 返回主菜单后如何保存我的硬币数量
- java - 从列表中过滤对象
- google-sheets - 快速宏 - 复制和粘贴
- node.js - npm 创建别名而不是复制粘贴自定义依赖项(就像 yarn 一样)
- excel - 如何为下一个空单元格生成选定的列表框值?
- blockchain - 如果智能合约存储在区块链中的区块上,它的状态如何更新?
- excel - 尝试以编程方式删除表格样式时出现无限循环,但当手动恢复循环时它可以工作