Making Interactive Reveal Maps (QGIS3)

This tutorial shows how to use a dynamic mask layer in a layer group along with expressions to make an interactive map that reveal the layers beneath the current layer as you move your cursor around. This is done using the new mask blending modes in QGIS along with technique for adding interactivity shown in the previous tutorial on Making Interactive Canvas Maps (QGIS3).

This tutorial is inspired from Hamish Campbell who shared his interactive visualization on LinkedIn.

Overview of the task

We will load 2 raster tile layers and use a mask layer with geometry generator symbology to reveal the below layer as the cursor moves around on the canvas.

../../_images/output2.gif

Procedure

  1. We will start by loading 2 raster layers. One layer at the top and another one at the bottom that will be revealed by the mask layer. We will get these from the QuickMapServices plugin. Search and install the QuickMapServices plugin from the QGIS Official Plugin Repository. See Using Plugins (QGIS3) for instructions on installing plugins. Once installed, we will need to add some additional service to this plugin. Go to Web ‣ QuickMapServices ‣ Settings.

../../_images/1104.png
  1. In the QuickMapServices Settings dialog, switch to the More Services tab and click the Get contributed pack button. This step is required to get access to the Google Satellite basemap.

../../_images/2100.png
  1. Now we are ready to add the layers. The top layer in our map will be the OpenStreetMap layer. Go to Web ‣ QuickMapServices ‣ OSM ‣ OSM Standard to add it. Zoom and center the map to any location of your choice.

../../_images/338.png
  1. Next add the Google Satellite layer from Web ‣ QuickMapServices ‣ Google ‣ Google Satellite. This will be the bottom layer that will be revealed using the mask.

../../_images/419.png
  1. We will create a new layer that will act as the mask. Go to Layer ‣ Create Layer ‣ New GeoPackage Layer….

../../_images/518.png
  1. In the New GeoPackage Layer dialog, click the button for Database and browse to a directory on your computer. Save the layer as mask.gpkg. Change the Geometry type to Polygon and the CRS to be Project CRS: EPSG:3857 - WGS84 / Pseudo-Mercator. Having this layer in a Projected CRS is helpful as it allows us to specify the radius of the mask in meters as opposed to degrees. Click OK.

../../_images/618.png
  1. A new layer mask will be added to the Layers panel. Click the Open the Layer Styling Panel button. Click on Single Symbol to see additional options for renderers.

../../_images/717.png
  1. Select Inverted Polygons as the renderer. Scroll down and click on the Simple Fill to see additional symbol layer types.

../../_images/817.png

참고

The inverted polygon renderer is used to show regions outside the feature. In our case, the mask layer is empty so the inverted region is the whole canvas. That is why you see the whole canvas rendered using the chosen symbology. We use this renderer for the tutorial since it can render the map without needing any features being present in the layer and will work anywhere in the world.

  1. Select Geometry Generator as the Symbol layer type. We will now enter an expressions to change how the layer is rendered. Click the Expression button.

../../_images/917.png
  1. Enter the following expression in the Expression Builder dialog. This expression will create a buffer polygon with a radius of 5000 meters around the current position of the cursor. Click OK.

buffer(@canvas_cursor_point, 5000)
../../_images/1023.png
  1. You will see a circular polygon rendered wherever you click on the canvas. Adjust the size of the buffer if required for your region and close the Layer Styling Panel. To use the mask blending modes, we must create a layer group. Hold the Ctrl key and select the mask and the OSM Standard layers. Right-click on the selected layers and choose Group Selected.

../../_images/1126.png
  1. A new layer group will be created. Enter the name as mask_group. Click the Open the Layer Styling Panel button.

../../_images/1224.png
  1. Check the Render Layers as a Group button. This step enables the mask blending modes for the layers in this group.

../../_images/1322.png
  1. Select the mask layer from mask_group. In the Layer Styling panel, scroll down and expand the Layer Rendering section.

../../_images/1420.png
  1. Click the dropdown selector for the Layer Blending Mode. Select the Inverse Mask Below blending mode. The layer below the layer group will now be revealed in the portion covered by the buffer polygon.

../../_images/1517.png
  1. The map canvas doesn’t yet respond to the cursor movement because it doesn’t refresh unless you move the map. Let’s make it auto-refresh. Right-click the point layer and select Properties.

../../_images/1616.png
  1. Switch to the Rendering tab. Scroll down and check the Refresh layer at interval. Set the interval to a small number such as 0.1 (i.e. 100ms) and click OK.

../../_images/1717.png
  1. Now as you move your cursor, the region below your cursor position will be interactively revealed.

../../_images/output2.gif

If you want to give feedback or share your experience with this tutorial, please comment below. (requires GitHub account)