Last active
August 15, 2016 01:07
-
-
Save davidtheclark/3859542cba61ca8b00d3927700c99737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const mapnik = require('mapnik'); | |
const VectorTile = require('vector-tile').VectorTile; | |
const Protobuf = require('pbf'); | |
const fs = require('fs'); | |
mapnik.register_default_input_plugins(); | |
const geojson = fs.readFileSync('original-russian-triangle.geojson', 'utf8'); | |
const LAYER = 'triangles'; | |
function getTiledFeatureGeoJson(z, x, y) { | |
const mapnikTile = new mapnik.VectorTile(z, x, y); | |
mapnikTile.addGeoJSON(geojson, LAYER); | |
const tilePbf = mapnikTile.getDataSync(); | |
const tile = new VectorTile(new Protobuf(tilePbf)); | |
const layer = tile.layers[LAYER]; | |
return layer.feature(0).toGeoJSON(x, y, z); | |
} | |
const featureA = getTiledFeatureGeoJson(6, 0, 15); | |
const featureB = getTiledFeatureGeoJson(6, 63, 15); | |
const result = { | |
type: 'FeatureCollection', | |
features: [featureA, featureB], | |
}; | |
fs.writeFileSync('tiled-russian-triangle.geojson', JSON.stringify(result, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment