npm install @mapbox/vtcomposite --savevtcomposite is a tool to combine multiple vector tiles into a single tile. It allows you to ...
- Merge tiles. Combine 2 or more tiles into a single tile at the same zoom level.
- Overzoom tiles. For displaying data at a higher zoom level than that the tile's original zoom level.
- Clip tiles. Clips the extraneous buffer of a tile that’s been overzoomed to match a tile's extent or to retain data beyond the extent.
- Drop layers. Remove any layers from a tile.
- Localize. Modify localization-related features and properties such as language and worldview properties.
You can learn more about compositing in TUTORIAL.md. This module is a Node.js Addon and will install prebuilt binaries for your version of Node.js and computer architecture. Uncommon setups will build from source when installed via NPM.
Combine multiple vector tiles from different zooms into a single tile at one zoom. This function will overzoom geometries to match the extent of the destination zoom.
tilesArray(Object) an array of tile objectsbufferBuffer a vector tile buffer, gzip compressed or notzNumber z value of the input tile bufferxNumber x value of the input tile bufferyNumber y value of the input tile bufferlayersArray an array of layer names to keep in the final tile. An empty array is invalid. (optional, default keep all layers)
zxyObject the output tile zxy location, used to determine if the incoming tiles need to overzoom their datazNumber z value of the output tile bufferxNumber x value of the output tile bufferyNumber y value of the output tile buffer
optionsObjectoptions.compressBoolean a boolean value indicating whether or not to return a compressed buffer. Default is to return a uncompressed buffer. (optional, defaultfalse)options.buffer_sizeNumber the buffer size of a tile, indicating the tile extent that should be composited and/or clipped. Default isbuffer_size=0. (optional, default0)
callbackFunction callback function that returnserr, andbufferparameters
const { composite } = require('@mapbox/vtcomposite');
const fs = require('fs');
const tiles = [
{ buffer: fs.readFileSync('./path/to/tile.mvt'), z: 15, x: 5238, y: 12666 },
{ buffer: fs.readFileSync('./path/to/tile.mvt'), z: 15, x: 5238, y: 12666, layers: ['building'] }
];
const zxy = { z: 5, x: 5, y: 12 };
const options = {
compress: true,
buffer_size: 0
};
composite(tiles, zxy, options, function(err, result) {
if (err) throw err;
console.log(result); // tile buffer
});A filtering function for modifying a tile's features and properties to support localized languages and worldviews. This function requires the input vector tiles to match a specific schema for language translation and worldviews.
paramsObjectparams.bufferBuffer a vector tile buffer, gzip compressed or not.params.compressBoolean a boolean value indicating whether or not to return a compressed buffer.- Default value:
false(i.e. return an uncompressed buffer).
- Default value:
params.hidden_prefixString prefix for any additional properties that will be used to override non-prefixed properties.- Default value:
_mbx_. - Any property that starts with this prefix are considered hidden properties and thus will be dropped.
- Default value:
params.languagesArray<Optional> array of IETF BCP 47 language codes or the stringlocal, used to search for matching translations available in a feature's properties.- Optional parameter.
- All language-related properties must match the following format:
{hidden_prefix}{language_property}_{language}. - Default properties are
_mbx_name_{language}; for example, the_mbx_name_jpproperty contains the Japanese translation for the value inname. locallanguage code represents "{language_property}is in a script that is not in theparams.omit_scriptslist".- The script of
{language_property}, if available, must be stored in the{language_property}_scriptproperty. - If
{language_property}_scriptnot in theparams.omit_scriptslist, use{language_property}when searching for matching translation. - If
{language_property}_scriptis in theparams.omit_scriptslist, skip{language_property}when searching for matching translation.
- The script of
alllanguage code returns{language_property},{language_property}_localand all possible language properties that have different values than{language_property}
params.omit_scriptsArray<Optional> array of scripts to skiplocallanguage code.params.language_propertyString the primary property in features that identifies the feature in a language.- Default value:
name. - This values is used to search for additional translations that match the following format
{language_property}_{language}.
- Default value:
params.worldviewsArray<Optional> array of ISO 3166-1 alpha-2 country codes used to filter out features of different worldviews.- Optional parameter.
- For now, only the first item in the array will be processed; the rest are discarded (TODO in the future: expand support for more than one worldviews).
- When there is only the single value
ALL, all the different worldviews are returned.
params.worldview_propertyString the name of the property that specifies in which worldview a feature belongs.- Default value:
worldview. - The vector tile encoded property must contain a single ISO 3166-1 alpha-2 country code or a comma-separated string of country codes that define which worldviews the feature represents (for example:
JP,IN,RU,US).
- Default value:
params.worldview_defaultString default worldview to assume whenparams.worldviewsis not provided.- Default value:
US.
- Default value:
params.class_propertyString the name of the property that specifies the class category of a feature.- Default value:
class.
- Default value:
callbackFunction callback function that returnserrandbufferparameters
The existence of the parameters params.languages and params.worldviews determines the type of features that will be returned:
-
Non-localized feature: when
params.languagesandparams.worldviewsboth do not exist.- No new language property.
- The property
{language_property}retains its original value. - Properties like
{language_property}_{language}are kept. - Properties like
{hidden_prefix}{language_property}_{language}are dropped. - All features with
{worldview_property}are kept. - All features with
{hidden_prefix}{worldview_property}are dropped except for those that have the valueall. - Property
{class_property}retains its original value. - Property
{hidden_prefix}{class_property}is dropped.
-
Localized feature: when either
params.languagesorparams.worldviewsexists.- A new
{language_property}_localproperty is created to keep the original value of{language_property} - The value of
{language_property}is replaced with the first translation found by looping throughparams.languages.- First searches for
{language_property}_{language}and then{hidden_prefix}{language_property}_{language}before moving on to the next language inparams.languages.
- First searches for
- Properties like
{language_property}_{language}are dropped. - Properties like
{hidden_prefix}{language_property}_{language}are dropped. - All features with
{worldview_property}are dropped except for those that have the valueall. - Features with
{hidden_prefix}{worldview_property}are kept if their{hidden_prefix}{worldview_property}value isall, or- a comma-separated list that contains the first item of
parmas.worldviews, in which a property{worldview_property}is created from that one single worldview country code and the property{hidden_prefix}{worldview_property}is dropped.
- If
{hidden_prefix}{class_property}exists,- Property
{class_property}is replaced with the value in{hidden_prefix}{class_property}. - Property
{hidden_prefix}{class_property}is dropped.
- Property
- A new
Example 1: a tile of non-localized features
const { localize } = require('@mapbox/vtcomposite');
const params = {
// REQUIRED
buffer: require('fs').readFileSync('./path/to/tile.mvt'),
};
localize(params, function(err, result) {
if (err) throw err;
console.log(result); // tile buffer
});Example 2: a tile of localized features in Japan worldview
const { localize } = require('@mapbox/vtcomposite');
const params = {
// REQUIRED
buffer: require('fs').readFileSync('./path/to/tile.mvt'),
// OPTIONAL (defaults)
languages: ['ja']
worldviews: ['JP'],
compress: true
};
localize(params, function(err, result) {
if (err) throw err;
console.log(result); // tile buffer
});This project is based off the node-cpp-skel framework, which is licensed under CC0.