如何以表演方式使用Mapbox矢量图块?

发布于 2025-02-06 03:36:18 字数 1283 浏览 2 评论 0原文

我对Mapbox MVT有些困惑。如我所知,瓷砖是一小块地图,如拼图难题。

不完全确定MVT的工作。

https://docs.maps.mapbox .com/data/tilesets/guides/vector-tiles-intoduction/#向量范围

在这里,它说矢量图块真的很小,可以实现全局高分辨率地图,快速地图负载,快速地图负载,

,所以我正在尝试从数据库中获取所有坐标,这些坐标可能超过10k ,目前使用PostGIS使用:

    with connection.cursor() as cursor:
        cursor.execute(query)
        rows = cursor.fetchall()
        mvt = bytes(rows[-1][-1])

    return Response(
        mvt, content_type="application/vnd.mapbox-vector-tile", status=200
    )

现在我想知道关于性能问题,由于用户每次访问它都会给数据库带来压力。

我遇到的另一个问题是,当我使用vector图块作为源时,它每次移动地图时都会调用源URL并(击中DB)。

        type: 'vector',
        tiles: [
          'http://url/{z}/{x}/{y}.mvt'
        ]

是否可以以特定的缩放级别调用源URL,直到那时所有点仍保留在地图上?

例如。

Mapbox should call source url (only one time from zoom level 1-7) at zoom level 1 and draw points on to the map and when zoom level reach 7 then mapbox should call the source url(only one time from zoom level 7-22) and update the map. 

如果有人能提供帮助,真的很感激。

I am a bit confused about Mapbox MVT. As I understood, a tile is a little piece of map, as in a jigsaw puzzle.

Not completely sure about the working of MVT.

https://docs.mapbox.com/data/tilesets/guides/vector-tiles-introduction/#benefits-of-vector-tiles

Here, it says Vector tiles are really small, enabling global high resolution maps, fast map loads, and efficient caching.

So the thing is I am trying to get all the coordinates from db which can go up to more than 10K and currently getting the data from postgis using:

    with connection.cursor() as cursor:
        cursor.execute(query)
        rows = cursor.fetchall()
        mvt = bytes(rows[-1][-1])

    return Response(
        mvt, content_type="application/vnd.mapbox-vector-tile", status=200
    )

Now I am wondering about the performance issues, as everytime a user will visit it will put stress on db.

And another problem I am having is when using vector tiles as a source, it calls the source url and (hitting the db) everytime I move the map.

        type: 'vector',
        tiles: [
          'http://url/{z}/{x}/{y}.mvt'
        ]

Is it possible to call the source url at a specific zoom level and until then all the points remains on the map?

for eg.

Mapbox should call source url (only one time from zoom level 1-7) at zoom level 1 and draw points on to the map and when zoom level reach 7 then mapbox should call the source url(only one time from zoom level 7-22) and update the map. 

Really be grateful if anyone can help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁与争疯 2025-02-13 03:36:18

当涉及到瓷砖数据(向量,栅格,任何格式)时,您几乎总是需要一种具有缓存策略的服务,尤其是如果数据库中的数据实时创建瓷砖。直接呼叫到DB,以便在需要每个瓷砖的时候只能在开发/测试期间或简单演示进行。仅矢量瓷砖不是解决方案,您需要端到端体系结构来服务数据。以下是缓存策略的几个示例:

  • 如果您的数据不断变化第二或更快,则通常不需要在地图上快速显示更新。如果您有很多用户,则15秒的高速缓存到期,可以大大减少必须创建瓷砖的次数。 Azure Maps为他们的创建者平台做到了这一点,该平台旨在在数字双胞胎方案中显示近实时传感器的读数。它能够支持数十亿个传感器每15秒更新地图。如果您确实需要在发生时看到更新,那么向量图块可能不是正确的方法,而是考虑使用SignalR等流服务,并根据边界框和缩放级别限制发送到地图的数据。
  • 在大多数应用程序中,数据不会迅速更新,因此可以使用更长的缓存标头。
  • 在某些情况下,数据很少发生(或根本没有)变化,以至于预先生成一次瓷砖,托管这些并直接服务的更有意义。您仍然会有一种缓存策略,以便用户不断地从您的服务器中要求相同的瓷砖,而他们可以简单地将其从浏览器缓存中提取。在这种情况下,将瓷砖放入基本上是具有标准化结构的SQLite DB中是有用的。将瓷砖放入mbtile文件中的良好是您只需要移动一个文件,而不是数千个瓷砖(移动这许多文件会产生大量的io读取/写入,从而使部署的部署非常慢)。

同样重要的是要注意,您应该优化瓷砖中的数据。例如,如果您正在使用高分辨率多边形,那么对于被缩放的瓷砖,您可能会发现有很多适合同一像素内部的坐标,因此,当您从数据库中请求多边形时,请将其分辨率减少到将其分辨率降低至匹配瓷砖的分辨率。这将大大降低瓷砖的大小,以及数据库输出的数据量。

您可以在此处找到很多用于矢量瓷砖的工具和文章: https://github.com/ Mapbox/Awesome-vector Tiles

关于如何服务矢量瓷砖和创建管道的博客也有很多博客。

When it comes to tiling data (vector, raster, whatever format), you will almost always want a service that has a caching strategy, especially if the tiles are being created in real time from data in a database. Calling directly into the DB for when every tile is needed should only be done during development/testing, or for simple demos. Vector tiles alone are not the solution, you need an end-to-end architecture for serving the data. Here are a couple of examples of caching strategies:

  • If your data is constantly changing by the second or faster, you often don't need to show the update that quickly on a map. If you have a lot of users a 15 second cache expiry on tiles can drastically reduce the number of times a tile has to be created. Azure Maps does this for their creator platform which is designed to show the near real time sensor readings in a digital twin scenario. It is capable of supporting billions of sensors updating the map every 15 seconds. If you truly need to see updates as they happen, then vector tiles likely isn't the right approach, instead consider using a stream service like SignalR, and limiting the data sent to the map based on bounding box and zoom level.
  • In most applications the data doesn't update that quickly, so a longer cache header can be used.
  • In some cases, the data changes so infrequently (or not at all) that it makes more sense to pre-generate the tiles once, host those, and serve those directly. You would still have a caching strategy so that users aren't constantly requesting the same tiles from your server when they could simply pull it from their browser cache. In this case, it is useful to put the tiles into a MBTile file which is basically a Sqlite DB with a standardized structure. The benifit of putting the tiles in an MBTile file is you only have to move one file around, instead of thousands of tiles (moving this many files creates a ton of IO read/writes that can make deploying extremely slow).

It's also important to note that you should optimize the data in your tiles. For example, if you are working with high resolution polygons, for tiles that are zoomed out, you will likely find there are a lot of coordinates that fit inside the same pixel, so when you request the polygon from the database, reduce its resolution to match the resolution of the tile. This will drastically reduce the size of the tile, and the amount of data the database is outputting.

You can find a lot of tools and articles for vector tiles here: https://github.com/mapbox/awesome-vector-tiles

There are also lots of blogs out there on how to serve vector tiles and create pipelines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文