https://github.com/haoliangyu/tokmz
Convert GeoJsons into KMZ file with folder structure
https://github.com/haoliangyu/tokmz
converter geojson kmz
Last synced: 6 months ago
JSON representation
Convert GeoJsons into KMZ file with folder structure
- Host: GitHub
- URL: https://github.com/haoliangyu/tokmz
- Owner: haoliangyu
- License: mit
- Created: 2015-11-08T05:26:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-10T00:15:22.000Z (over 8 years ago)
- Last Synced: 2024-10-13T16:43:32.633Z (7 months ago)
- Topics: converter, geojson, kmz
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tokmz
Convert GeoJsons into KMZ file with layer structure.

## Installation
``` javascript
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
``` javascript
{
type: 'folder',
name: 'name_of_folder',
content: [] // an array containing subfolders and layers
}
```* layer
```javascript
{
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**](https://github.com/haoliangyu/gtran-kml).
## Sample
```javascript
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);
});
```