Hi, Habr.
Today I will tell you how you can efficiently download a large number of points on the map (web or in mobile applications).
From the point of view of most modern mapping solutions, several basic approaches to drawing a map can be distinguished:
Here you need to make a remark, a tile, for those who are not vkurse, this is a special block grid (along with tiles, static images are also called), which is characterized by three coordinates (z - zoom, x, y), at each level the number of tiles
The most interesting today is the vector format.
Why? Actually, you need to start with the problems associated with the raster format:
What perspectives does the vector format offer? Actually, there are several:
Actually, everything with a vector format is good, but there are also disadvantages. At a minimum, the vector format is more difficult to cache, it is not as obvious as in most cases with a raster format, where enough pre-generated tiles are folded onto a CDN, set up TTL and regeneration and no longer think about it.
In general, it is possible to talk about this for a very long time, my task was to give a brief description of the actual work mechanisms, now we can proceed to the topic of the post.
Actually, in terms of possible solutions, there are several approaches that have different support among the ready-made libraries (services):
Download the whole GeoJSON and render it (most fall off on this option :)). Actually, the advantage is that almost all popular libraries of Google Maps, Yandex Maps, Mapbox, Leaflet, etc., are supported in one way or another. However, not everyone does it efficiently, for example, on request to Google about an effective solution for loading a large number of points in Mapbox, the first link will be their solution - supercluster, which in fact is a server utility that loads, prepares GeoJSON data and returns it to the client.
Download only located in viewport. The idea is quite simple, we only load what is in the viewport (* in some cases, nearby tiles are lazily loaded). Realization of this is in the box, for example in Yandex Maps - LoadingObjectManager , including it can do clustering on the client. They also have RemoteObjectManager, which already expects clustered data from the server.
Pregenerating static tiles and loading them. It also takes place, especially in the case of high-load services, but not very interesting. Tiles are most often generated using a tool, such as Mapnik, and uploaded to a CDN, or a third-party utility / library is used, which does all this work on its own.
This format is perfectly supported by solutions from Mapbox, there are also libraries for Leaflet.
From the point of view of storage for GIS data, which would also make it possible to effectively carry out operations on them, you can choose PostGIS, which by the way gives all the necessary operations for the above, including the generation of MVT (Mapbox Vector Tiles):
@
operatorThank you for your attention, I hope for a constructive feedback, if it is interesting, I can tell you about some points of working with maps!
Source: https://habr.com/ru/post/352330/
All Articles