如何以表演方式使用Mapbox矢量图块?
我对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当涉及到瓷砖数据(向量,栅格,任何格式)时,您几乎总是需要一种具有缓存策略的服务,尤其是如果数据库中的数据实时创建瓷砖。直接呼叫到DB,以便在需要每个瓷砖的时候只能在开发/测试期间或简单演示进行。仅矢量瓷砖不是解决方案,您需要端到端体系结构来服务数据。以下是缓存策略的几个示例:
同样重要的是要注意,您应该优化瓷砖中的数据。例如,如果您正在使用高分辨率多边形,那么对于被缩放的瓷砖,您可能会发现有很多适合同一像素内部的坐标,因此,当您从数据库中请求多边形时,请将其分辨率减少到将其分辨率降低至匹配瓷砖的分辨率。这将大大降低瓷砖的大小,以及数据库输出的数据量。
您可以在此处找到很多用于矢量瓷砖的工具和文章: 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:
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.