Reputation: 673
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.
Upvotes: 0
Views: 2903
Reputation: 17954
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.
Upvotes: 2