Guidesv3.2 API Referencev3.1 API Reference
Guides

Map data sources

 The 3.1 version is deprecated

📘

Note

The 3.1 version of this API has been deprecated. For continued support and feature development, upgrade to the latest 3.2 version.

As stated in the Scene structure overview, the sources section is mandatory. This section always contains one source that describes data format provided by a provider. Currently, the available data formats include: GeoJSON and OMV - a format that follows Vector Tile Specification.

A source section contains the following parameters:

  • type - Specifies the format provided by the provider. It can be either OMV or GeoJSONTileSource.
  • extra_data (optional) - Contains any additional data that to pass to the transform function.
  • transform (optional) - Enables processing tile data right in the style through either of the following methods:
    • A single function, for example:

      sources:
        omv:
          type: OMV
          transform: |
            function(data, extraData, tileInfo) {
              if (data.water) {
                for (let i = 0; i < data.water.features.length; i++) {
                  data.water.features[i].properties.myProperty1 = 'myValue1';
                }
              }
              return data;
            }
    • Multiple functions, sorted by their names and called in the corresponding sequence, for example:

      sources:
        omv:
          type: OMV
          transform:
            f1: |
              function(data, extraData, tileInfo) {
                if (data.water) {
                  for (let i = 0; i < data.water.features.length; i++) {
                    data.water.features[i].properties.myProperty1 = 'myValue1';
                  }
                }
                return data;
              }
            f2: |
              function(data, extraData, tileInfo) {
                if (data.water) {
                  for (let i = 0; i < data.water.features.length; i++) {
                    data.water.features[i].properties.myProperty2 = 'myValue2';
                  }
                }
                return data;
              }

As demonstrated in the preceding examples, each transform function accepts the following arguments:

  • data - object that contains data from the current tile. This object contains a list of layers (pois, roads, etc.), where each layer is a GeoJSON FeatureCollection. Some providers (for example, H.service.traffic.flow.Provider) provide only one GeoJSON FeatureCollection per tile, in such cases this GeoJSON FeatureCollection passes as data instead list of layers.
  • extraData - content of the extra_data optional parameter defined in the source section.
  • tileInfo - object that contains information about the current tile, for example tile coordinates. Each transform function must return the modified version of the data parameter.

Next steps

For more information, see Vector map types