Previously we shared how to publish the OSM vector tile map locally. The generated vector tiles are stored in the.mbTiles file and then published using tileserver-GL.

Mbtiles is a standard specification for storing map tile data based on an SQllite database. The. Mbtiles file is an SQllite database that implements this specification.

Recently, there was a problem with the need to deploy the vector tiles in. Mbtiles format to the client server and publish them.

I have shared the open source GIS solution I am using before, in which POSTGIS, GeoServer and Tomcat are made into green versions, and they can be registered as system services with one click through batch processing scripts, thus forming a green version installation package of open source GIS, which will be very convenient for deployment.

The overall technical architecture of this installation package is Java oriented, and the Tileserver-GL used in this release of vector tiles is developed based on NodeJS. According to the above idea, nodeJS should also be made green and can be registered as a system service using batch processing.

Because I don’t want to make the installation package too big, and I don’t want to use too many technical systems to complicate maintenance, I want to solve the problem of issuing.mbtiles within the existing technical system.

In this vein, you need to investigate whether there are geoServer plug-ins, or Java software or projects.

The following is the specific process of my research. If you don’t want to see the process, you can skip to the end and see the summary.

Geoserver plug-in

I studied the GeoServer plug-in first.

Geoserver an mbtiles extensions (docs.geoserver.org/latest/en/u…). Support reading and writing to. Mbtiles files.

Geoserver mbtiles plug-in installation tutorial can refer to this article: blog.csdn.net/dyxcome/art…

Download the plugin from the official website, install and test it, and find that it is a little different from what you expected.

After installing the GeoServer plug-in, the new data source interface has two mbTiles related options, as shown below: Publish vector tiles at the top and publish grid tiles at the bottom.

I used the second red box, the publish grid tile option, to publish the lower vector tile, which would give an error.

Using the first red box, the option to publish vector tiles works, but the process is a bit convoluted, requiring the PBF layers to be published one by one.

The.mbTiles file contains the processed PBF files, which the plugin returns to the foreground by querying the PBF file from the SQllite database according to the requested parameters.

Instead, geoServer uses the PBF tiles in the.mbtiles file as a vector data source, similar to reading an.mdb file.

It can be inferred that the internal processing of the GeoServer is something like:

  1. First thepbfTiles are put together to read the original data of each layer after stitching
  2. Publish the layer raw data as a vector tile service for geoServer
  3. When the foreground invokes the vector tile service, the GeoServer processes the data intopbfThe file is returned to the foreground

Well, the result is the same as throwing PBF files directly to the foreground, but it feels like the geoServer play is too much, the internal friction is too much, and the process of issuing the service is too cumbersome.

Suffice it to say that the plugin is designed for vector tiles only to read raw data and is not suitable for publishing data.

Java project

Let’s look at the Java side.

A search on Github turned up the project: Mbtiles4J (github.com/jtreml/mbti…) .

Mbtiles (mbTiles) ¶ Mbtiles (mbtiles) ¶ Mbtiles (mbtiles) ¶ Mbtiles (mbtiles) ¶

This easy to say, have source code, change is.

After the change, I found that the front map was not displayed, and the tile requested address message 404.

Match the number of tiles in the requested address with the number of tiles in the MBTiles library.

Why?

The most important thing is to set up the mapBoxGL request tile scheme. The modes include XYZ and TMS. The default is XYZ.

Is the MBTiles file generated by OpenMaptile stored in TMS? Just try it

Sure enough ~ not so simple, map still not out, but tiles can request, looks like it is TMS.

A quick look at the MBTiles specification makes it clear that the data source is stored in TMS format.

It seems that more study of standard specifications and documentation.

But why hasn’t the map come out yet?

A comparison of the return parameters of Tileserver-GL (left) and MBtiles4J (right) reveals the problem.

The PBF file is compressed by gzip, so it needs to be explicitly told in the return parameter that the type of returned content is gzip. However, after changing PNG in MBTILes4J to PBF, this setting is not added.

Plus try it. Ha ha. Done.

Once this is done, the rest is simple: compile the project into a WAR package and throw it directly into Tomcat.

Large scale map display

I thought I was done, but when I scanned the map, I found another problem.

My map only cut to level 14, because in vector tiles, level 14 is already very thin, so there is no need to cut further.

However, when browsing with the map, after level 14, because there is no corresponding tile in the background, the foreground can not request data, and the map will not be displayed.

Publishing the same MBTiles file with Tileserver-GL and browsing the map with its default map viewer does not have this problem.

It looks like the background needs to process the request parameters that exceed 14 levels, and return the tiles that exceed 14 levels directly.

Looking through tileserver-GL’s code, I couldn’t find the logic.

Alerted by a colleague, TILeserver-GL’s default map viewer found that its foreground requests were at level 14 when they were over level 14, indicating that the logic I was looking for was done at the foreground.

After going through tileserver-GL’s map style configuration and comparing it with my own configuration, I found that setting MaxZoom to the data source solved this problem.

If you set maxZoom to 14, the map will still use tiles at level 14 when the map is larger than 14.

This setup is exactly what I want.

I uploaded the modified background code to Github for the convenience of students who meet the same problem in the future.

Source:

Address: gisarmory. Xyz/blog/index….

Conclusion:

  1. Locally published OSM vector tile maps, the generated vector tiles are stored in the MBTiles file
  2. The main way to publish vector tiles in MbTiles is tileserver-GL, which is based on NodeJS
  3. Geoserver has a plug-in for reading MbTiles, but it is designed for vector tiles to read raw data in PBF and is not suitable for publishing data.
  4. There is a Project on Github for Mbtiles4J, developed in Java, which, with some modifications, can be used to publish MbTiles directly
  5. When mapBoxGL uses published map tiles, the maxZoom property of the data source needs to be set.

The original address: gisarmory. Xyz/blog/index… .

This article is licensed under the Creative Commons Attribution – Noncommercial Use – Share alike 4.0 International License. You are welcome to reprint, use and republish the article under the name “GIS Armory” (including link: gisarmory. Xyz /blog/). It must not be used for commercial purposes, and all works based on this article must be published under the same license.

\