Thursday, 15 October 2020

MapGuide 4.0 showcase: Supercharged tile sets part 2

Previously, we showcased the new tile capabilities of MapGuide Open Source 4.0.

Since the last preview release, we've now introduced a new tile format that will open up new web mapping possibilities not previously possible: Support for Mapbox Vector Tiles.

Vector Tiles are a way to deliver geographic data in small chunks to a browser or other client application Vector Tiles are similar to raster tiles, but instead of raster images, the data returned is a vector representation of the features in the tile.

As a result, Vector Tiles relieves the burden of rendering/stylization on the MapGuide Server as stylization is now a responsibility of client mapping applications, allowing for much richer and interactive user/application experiences as in this case, the MapGuide Server only has to focus on the encoding and delivery of vector tiles.

Consider this new Mapbox Vector Tile sample that ships with the preview 2 release.

In this example, the MapGuide Server is delivering the Mapbox Vector Tiles. The styling and labeling of the features is all done client-side through OpenLayers style functions.

Here's an interesting exercise for the reader (if I don't beat you to it first :)) Implement a JS library that automatically translates our basic Vector Layer Definition documents in MapGuide in clean JSON format, to OL style functions for automatic client-side styling of MVT tiles.

Mapbox Vector Tiles has been around for a while, so what took so long for support to finally land in MapGuide? A few factors.

  • The lack of a consensus around a "standard" around vector tiles. Our usual go-to for geo standards (the OGC) have been somewhat silent on vector tiles (last I checked) and if they actually did push any kind of standard for vector tiles, it certainly wasn't reflected in support in the popular GIS/Mapping software out there. Over time, it was clear that Mapbox Vector Tiles is the de-facto standard for vector tiles and if MapGuide was to ever support vector tiles, it should be supporting Mapbox Vector Tiles.
  • MapGuide had not yet standardized on adopting C++11 as the base language version of C++, which limited the range of existing MVT encoding libraries available for us to use. Now that we have adopted the use of C++11, it was a case of what MVT encoding library to use for MVT support in MapGuide. I had initially tried using vtzero for MVT encoding, but the low-levelness of the library and uncertainty around how coordinate systems are meant to be handled meant that I had to look for an alternate library. In the end, we chose to graft the MVT tile encoder code from GDAL/OGR's MVT vector driver, which was a much more simpler affair.

So how can you start pumping out MVT tiles for your own MapGuide Open Source 4.0 Preview 2 install? Simply create a new XYZ tile set definition with a tile format of MVT

Then you can start fetching MVT tiles with your favorite web mapping library, whether that be OpenLayers or Leaflet or anything else on this big list!

And because MVT support in MapGuide is through XYZ tile access semantics, you can use MgTileSeeder or any other XYZ tile seeder to pre-load your MVT tile cache.

No comments: