In the previous article (Advanced Geoserver: tiling (principles) we have explored the different concepts regarding the tiling mapping.
In this article we will discuss how to implement those applications using Geoserver.
In order to run the tiling, Geoserver uses an external module called GeoWebCache.
What Is GeoWebCache?
Maps are often static. Since most mapping clients supplyWMS (Web Map Service) data every time they are queried, unnecessary processing and delays can occur. GeoWebCache optimizes this experience by saving (caching) map images, or tiles, as they are requested, in short acting as a proxy between client (such as OpenLayers or Google Maps) and server (such as GeoServer, or any WMS-compliant server). As new maps and tiles are requested, GeoWebCache intercepts these calls and returns pre-rendered tiles (if stored), or calls the server to render new tiles if they are needed. Thus, once tiles are stored, the speed of map rendering increases significantly, creating a highly improved user experience.
In the picture above, the blue box on the GeoWebCache device represents the tile storage. Ideally, most requests are answered using the data stored without consulting the WMS server(s). Hence the arrow to the clients is drawn much larger, because GeoWebCache can answer hundreds or thousands of requests per second.
Also,GeoWebCache can even be used when maps aren’t completely static, since it allows for the selective expiration of tiles, so that data remains current. In this respect GeoWebCache therefore acts as an all-purpose accelerator for map rendering.
Integration within Geoserver
The GeoWebCache module is delivered with the installation of Geoserver. It is installed and enabled by default. You can check it by going to Service Status-> Modules.
On the other hand, vector tile is not installed by default. To check, select Cached layers in the left menu. Then open a vector type layer. You have some installed by default in Geoserver (tiger:poi, sf:archsites, sf:bugsites, topp:tasmania_cities)
Go to the Tiles cache tab
If you do not see the vector formats (geojson, topojson, mapbox-vector) among the available options, the extension is not installed.
To install it:
Go to http://geoserver.org/release/stable/
In Extensions -> Output formats, click Vector Tiles to download the files to install.
Copy the four downloaded files into the Geoserver / webapps / geoserver / WEB-INF / lib directory.
That’s all. The extension is installed.
Restart Geoserver (If not, the extension will not be active): If you are in Windows you have two possibilities.
- If you have configured manual Geoserver startup: Open the programmes start panel and click Stop Geoserver, then Start Geoserver
- if you have configured Geoserver as a service: Open the Computer Management -> Services panel, find the Geoserver service and open the context menu; click Restart
To check the correct installation, redo the previous manipulation (Cached layers-> a vector layer -> Tiles cache tab)
And now, you will see the tiles vector formats available.
Setting up GeoWebCache
Actually everything is already set in GeoWebCache and Geoserver. The only thing left to set up is tracking the disk space used by the cache.
By default, this monitoring is disabled. This means there is no space limit for the tile cache. Depending on your configuration, this may be acceptable. But in most cases, you will face serious risks of performance drops or even server crashes.
If you go to Cached Layers , you’ll see two columns: Space limit and Quota used . Both contain N / A. This indicates that the disk quota is not enabled.
To activate it:
Select Disk Space from the menu and click the Enable Disk Space Limit check box.
Indicate the maximum size dedicated and the type of action to be taken when this size is reached.
You have the option to request the removal from the cache the images that are called less frequently, or those that have not been called for quite a long time.
By default Geoserver configures GeoWebCache to use a H2 database located in the cache directory.
If you do not need to manage cache operation information, this option is perfect.
On the other hand, if you want to keep the operating history, the use of the tiles, etc., you can select the external database of your choice.
One final option , potentially interesting, is the Space limit column on the Cached layers page. If you look in the Geoserver documentation, you will find that this column indicates the specific cache space limit for the layer. Indeed, the independent version of GeoWebCache makes it possible to define quotas per layer. But this is not the case with the built-in Geoserver version. You do not have a way to set specific quotas. This column will remain frustatingly with N / A.
Do not try to apply these definitions directly in the geowebcache-diskquota.xml file, it will not work .
Once tracking is enabled , you will observe the space of each layer in the cache:
Configuration of a layer cache
You’ll find the Tile Cache tab on the Edit Layer page.
The first two check boxes determine whether the cache is enabled for this layer and whether tiling is enabled.
You must check the desired tile formats. Only when the server receives requests for this format (output), GeoWebCache will use the cached tiles.
At the bottom of the page you can select the zoom levels to be used by the cache.
You can only cache the most frequently used zoom levels.
The following table can be used as a guide to determine which zoom level to use:
For each zoom level (first column) you can find the corresponding geographic scale.
If you want GeoWebCache to produce the tiles, it is not enough to activate the tiling of a layer.
The tiles will be generated when a request from the server client is placed. If this is not the case, then you can request a preview of the tiles using the Hidden Layers Page. The drop-down menu allows you to choose the desired output format.
As this preview is a request made to the server, the corresponding tiles will be generated.
Last option to generate the tiles, select Generate from the Layer Actions list (last column of the table).
A page where you can define the parameters to generate the tiles will be displayed.
Good job !!!
Thanks, A lot of important information 😉
Thank you so much for this, very helpful introduction
how to solve problem long startup time in geoserver (almost 5 minuts)? is it because of geowebache enabled??
Sorry, but there may be dozens of reasons. This may come from your hardware configuration or other installed software.