tokmz

1.0.6 • Public • Published

tokmz

Convert GeoJsons into KMZ file with layer structure.

kmz

Installation

npm install tokmz

Function

The package provide a promised function

  • tokmz(geojsons, fileName, options)

    Parameters:

    • geojsons - organized GeoJson layers.

    • fileName - file name of saved kmz file. If undefined/null, the function will return an object that is ready to be written into file.

    • options - optional settings:

      • promiseLib - specified promise library. If undefined, the native Promise will be used.

tokmz() accepts GeoJsons organized using two elements:

  • folder
{
    type: 'folder',
    name: 'name_of_folder',
    content: []    // an array containing subfolders and layers
}
  • layer
{
    type: 'layer',
    name: 'name_of_layer',
    features: geojson_object,
    options: {
        symbol: feature_symbol,
        name: feature_name_attribute // in geojson.properties
    }
}

Detail about defining feature symbol can be found at gtran-kml.

Sample

var tokmz = require('tokmz');
 
var polygonJson, polygonSymbol, pointJson, pointSymbol, polylineJson, polylineSymbol;
 
// Some codes to load all GeoJsons and symbols
 
var layers = [
    { type: 'folder', name: 'test', content: [
        { type: 'layer', name: 'polygon_layer', features: polygonJson, options: {symbol: polygonSymbol, name: 'Name'} }
    ] },
    { type: 'layer', name: 'point_layer', features: pointJson, options: { symbol: pointSymbol, name: 'Name' } },
    { type: 'layer', name: 'polyline_layer', features: polylineJson, options: { symbol: polylineSymbol, name: 'Name'} }
];
 
tokmz(layers, 'test.kmz', {
    // if necessary
    promiseLib: require('bluebird')
})
.then(function(fileName) {
    console.log('KMZ file is saved at ' + fileName);
})
.catch(function(err) {
    console.error(err);
});

Readme

Keywords

Package Sidebar

Install

npm i tokmz

Weekly Downloads

4

Version

1.0.6

License

MIT

Last publish

Collaborators

  • haoliang