Mapbox vector datasets

From Maria GDK Wiki
Jump to navigation Jump to search

From version 4.3

Maria Map Maker supports the Mapbox vector tiles format, as well as a subset of the Mapbox JSON style specification. This article explains the process of importing and styling vector data with these formats.

Import

Format

Zoomlevels.jpeg

When Maria Map Maker imports vector data, it is translated to Mapbox vector tiles (.mbtiles). This is a very high-performant format, but the translation process requires some tuning and know-how to get the desired result.

The MBTiles format splits the vector data into tiles and zoom levels. Each tile contains 4096 x 4096 nodes, which are roughly equivalent to a pixel in a raster image. When vector data is converted to MBTiles, all vertices are snapped to the nearest node in a tile, losing some precision in the process.

Each tile belongs to a zoom level. Zoom level 0 is a single tile which covers the entire Earth (in Web Mercator projection). With every increasing zoom level, each tile is divided into four. As an example, zoom level 15 roughly equals map scale 1:15 000 at the equator. At this level, the entire Earth consists of around one billion tiles.

When importing vector data to MBTiles, you need to decide which zoom levels (z) to create. This zoom extent is not possible to change later. The vector data simply does not exist on the levels outside the zoom extent you choose. This means that you have to be familiar with your source data and how they are going to be used. Using zoom levels which are not appropriate for the source data can have some negative effects:

Using too low zoom level - too much data is stored in each tile, which would lead to poor performance. To prevent this, after a tile reaches a threshold of 500 KB or 200 000 features, additional features destined for that tile will either be simplified or dropped. Using too high zoom level - large, simple features are split across an exaggerated number of small tiles, which leads to unnecessary large files and long processing time.

For information about the accuracy of vector tiles at a given zoom level, see the article Vector tiles accuracy

Import dialog

The vector data import dialog lists all the layers in the source dataset, with a zoom selector for each. The checkboxes controls wether or not the layer is included in the resulting MBTiles dataset. You can use the top All layers control to set a common zoom extent.

You can choose the style format for the output dataset - the Mapbox JSON format described in this article, or the legacy MARIA GDK XML format. The MARIA GDK style will be phased out starting with version 4.3.

M3 vectorimport mbtiles.PNG

Style layers

M3 vectorstyle layerlist.PNG

To work with the vector dataset, open the overlay that it was added to (Add to in the previous screenshot).

Style layers are listed by expanding the dataset in a basemap/overlay. The list has several functions:

  • Drag-drop layers to change the drawing order (the top layer in the list will be drawn on top in the map).
  • Show or hide layers with the checkbox.
  • Single-click a layer twice (slow double-click) to change its name

Create new layer

To create a new layer, simply right-click anywhere in the Style layers list, and then select the layer type from the New layer submenu. A new layer will be created at that position. Finally, go to the Data tab to select a Source layer.

Style tab

Styles are configured by double-clicking a layer and selecting the Style tab. Style properties are documented by mousing over the property name. The style properties vary by the type of layer:

Fill

A fill style layer renders one or more filled (and optionally stroked) polygons on a map.

Line

A line style layer renders one or more stroked polylines on the map.

Symbol

A symbol style layer renders icon and text labels at points or along lines on a map. The Image property allows you to select a PNG or SVG file to use as an icon. Additional icons can be imported into the dataset with the Add symbols button. This will open the Symbol libraries browser. Here, you can import symbols from any installed symbol library. Some SVG symbols can also be styled before they are imported.

Background

A layer which covers the entire dataset. Useful if your content does not cover everything and you want to configure a background color.

Label

A text label can be configured on any type of layer. Click the Label tab and select an attribute for the Text field property to activate the label. You can then configure the appearance of the label with various properties.

M3 vectorstyle label.PNG

Data

Setting a filter on a style layer.

The Data tab contains settings related to the data source of the style layer.

Source layer

Source layers are the named layers in the MBTiles data file. A style layer must always reference a source layer (except for the background layer). The source layer type is indicated with an icon in the list (either Line, Fill, or Symbol).

Layer type

Layer type for this Style layer. This does not have to match the type of source layer it is referencing. By using a different type, you get some additional style options:

Source layer type Style layer type Result
Polygon Line Outline of polygons are drawn
Polygon Symbol Text labels or icons are drawn within the polygon
Line Symbol Text labels or icons are drawn along the line

Filters

A filter is a requirement that a feature must meet to be drawn in the map. When you create a new filter, you must select an attribute, an operator and a value. The value menu contains a small sample of values from the selected attribute, but you can also type in any value. Only features which match the filter will be drawn.

You can create multiple filters on a layer, and set the logical operator to connect them (AND/OR). You can also Add filter group to create groups of filters. The result (either true or false) is first evaluated for each group using the inner AND/OR, then between the groups using the outer AND/OR, to finally determine if an object should be drawn or not.

Zoom selector

Each style layer's visibility can be controlled with the Zoom selector at the bottom of the Layers list. The Zoom selector consists of two sliders which represent the max and minimum zoom levels where the layer is visible. If the map is zoomed outside the area between the sliders, the layer will be hidden. Setting the maxzoom to z20 effectively means that the layer will not disappear while zooming in.

The zoom selector is automatically adjusted so that its not possible to set a minzoom where the source layer does not exist. This is represented as a scribbled area. The "Valid" area is the interval between minzoom and (maxzoom + overzoom).

M3 vectorstyle zoom selector.PNG

Layers can still be shown when zooming in past the max level that exists in the data file. This is called Overzoom. The number of levels to overzoom can be set by double-clicking the root Vector layer. The default is 6 levels.

M3 vectorstyle overzoom.PNG

Advanced styling

Grouping

Layers can be grouped together by selecting multiple layers with Ctrl+left click. Right-click the selection, and click Group layers. This allows the layers to be moved and and turned on and off as a single unit.

M3 vectorstyle group layers.PNG

Duplicate layer

Any layer can be duplicated, where the only difference from the original is the name. This is useful if you for example want to style a line with an inner color and a different outline color. You would then place the duplicate below the original in the layer list, and set a slightly larger width.

Fanout

From version 4.4

M3 can automatically set up a new set of layers based on the attribute values in a layer. Right click any layer and click Fanout to open this dialog. The Color ramp options control the colors of the first and last layer created, and a color ramp is calculated linearly for all the layers in between. There are two modes when using fanout:

  • Category - A new layer is created for each unique value in the selected attribute. Both string and numerical attributes are supported.
  • Graduated - The full range of numerical values in the selected attribute is split into classes. The number of classes is controlled by the Classes option. The method to use when calculating these classes can be further controlled with the Graduated type option:
    • Equal interval - The full range of values is split into equally sized classes.
    • Equal count - Classes are calculated such that there will be an equal number of objects in each class. This requires the application to scan through all features in the dataset, so it can take a long time. Suitable for attributes where the values strongly deviate from a normal distribution.
    • Display precision - Number of decimal points to use for the layer names.

M3 vectorstyle fanout dialog.PNG M3 vectorstyle fanout group.PNG

Style across zoom ranges

Many style properties have the ability to change according to the current map zoom level. For instance, this allows a smooth transition of line width or color as you zoom in and out.

Click Style across zoom range on a property to activate the feature. You can then set up a list of zoom stops with corresponding value for the property. Rate of change controls the exponential change between stops. The default is 1.0, which increases values linearly. To disable this function, delete all zoom stops.

M3 vectorstyle zoomstops.PNG

Creating repeating fill patterns

To create fill patterns which repeat seamlessly across tiles in the map, you need to first create the repeating pattern in a graphics software, for instance Inkscape. You can create a pattern in Inkscape by clicking New → New from Template → Other → Seamless Pattern). The image should be exported to PNG with dimensions of powers of 2, up to the size of a tile (i.e. 16x16, 32x32, 64x64, 128x128, 256x256).

To add it to your dataset in M3, open the properties of a fill style layer, click StylePattern → Add symbols from file.

M3 mapbox style repeating pattern.png

Duplicating datasets

From version 4.4

In some cases you may want to create multiple styles which the user can choose from, without duplicating the data file (.mbtiles). This can be achieved by first importing the data as described in this article, and then creating a style. In the product window, you can right-click the dataset and select Duplicate Dataset. This results in a new dataset which is identical to the original, except that it references the original's data file instead of duplicating it. The duplicate dataset can then be added to an overlay and styled independently.

M3 multiple styles in overlay.png

M3 duplicate vector dataset.png

Note that using the Update function on any dataset with a shared data file will affect all the datasets using that file. Deleting a dataset which contains a shared data file will not delete the actual data file. The data file is only deleted when the last dataset using it is deleted.