可以从VectorTiles源生成范围吗?

huangapple go评论49阅读模式
英文:

Is it possible to generate extent from VectorTiles source?

问题

I'm building an app where users can upload any map in the format of vector tiles. These maps are often small and I'd like to limit the zoom and pan, so users view will be always within the map bounds.

我正在开发一个应用程序,用户可以上传任何矢量瓦片格式的地图。这些地图通常很小,我想限制缩放和平移,以确保用户的视图始终在地图范围内。

I don't know the extent of the uploaded maps. I tried multiple methods in layer/VectorTile, source/VectorTile and View, but as far as I know I need to first define extent to make it work.

我不知道上传地图的范围。我尝试了多种方法在图层/矢量瓦片、源/矢量瓦片和视图中,但据我所知,我需要首先定义范围才能使其正常工作。

Is there any way to generate extent based on edge coordinates of features in vector source? I'm using OpenLayers v7.2.2

是否有一种方法可以根据矢量源中要素的边缘坐标生成范围?我正在使用OpenLayers v7.2.2。

英文:

I'm building an app where users can upload any map in the format of vector tiles. These maps are often small and I'd like to limit the zoom and pan, so users view will be always within the map bounds.

I don't know the extent of the uploaded maps. I tried multiple methods in layer/VectorTile, source/VectorTile and View, but as far as I know I need to first define extent to make it work.

Is there any way to generate extent based on edge coordinates of features in vector source? I'm using OpenLayers v7.2.2

答案1

得分: 0

简短回答,不行。

矢量瓦片中的要素使用相对于矢量瓦片原点的坐标,通常在[4096, 4096]范围内。矢量瓦片本身不知道其坐标。如果您不知道瓦片集的范围,您无法解码其中的信息。

有三个元素定义了矢量瓦片集的范围:最左经度、最高纬度和最左经度与最右经度之间的距离。由于所有矢量瓦片都是正方形,它们使用2的幂级别的缩放级别,这应该允许您计算其他所有内容。

如果您自己生成矢量瓦片,我建议您始终使用Web墨卡托3857经典的世界范围:

tile_dimension_zoom_0: 20037508.34 * 2,
tile_origin_upper_left_x: -20037508.34,
tile_origin_upper_left_y: 20037508.34

然后您将得到从500到505的瓦片,而不是从0到5。

如果您使用他人的瓦片并且不知道这三个数字,您无法进行地理参考这些瓦片。

英文:

Short answer, no.

Features in vector tiles use coordinates relative to the origin of the vector tile, usually in the [4096, 4096] range. The vector tile itself does not know its coordinates. If you do not know the extent of your tileset, you cannot decode the information.

There are three elements that define the extent of a vector tileset: the leftmost longitude, the topmost latitude and the distance between the leftmost longitude and rightmost longitude. As all vector tiles are square and they use power of 2 zoom levels, this should allow you to calculate everything else.

If you are generating your vector tiles yourself, I suggest that you always use the classical world extent for Web Mercator 3857:

tile_dimension_zoom_0: 20037508.34 * 2,
tile_origin_upper_left_x: -20037508.34,
tile_origin_upper_left_y: 20037508.34

You will then have tiles that go from 500 to 505 instead of 0 to 5.

And if you are using someone else's tiles and you do not know those three numbers, you cannot georeference these tiles.

huangapple
  • 本文由 发表于 2023年2月23日 23:12:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定