Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vt-pbf

Package Overview
Dependencies
Maintainers
36
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vt-pbf - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

19

index.js

@@ -25,9 +25,15 @@ var Pbf = require('pbf')

* @param {Object} layers - An object mapping layer names to geojson-vt-created vector tile objects
* @param {Object} [options] - An object specifying the vector-tile specification version and extent that were used to create `layers`.
* @param {Number} [options.version=1] - Version of vector-tile spec used
* @param {Number} [options.extent=4096] - Extent of the vector tile
* @return {Buffer} uncompressed, pbf-serialized tile data
*/
function fromGeojsonVt (layers) {
function fromGeojsonVt (layers, options) {
options = options || {}
var l = {}
for (var k in layers) {
l[k] = new GeoJSONWrapper(layers[k].features)
l[k] = new GeoJSONWrapper(layers[k].features, options)
l[k].name = k
l[k].version = options.version
l[k].extent = options.extent
}

@@ -137,5 +143,7 @@ return fromVectorTileJs({layers: l})

pbf.writeVarint(command(1, count)) // moveto
for (var i = 0; i < ring.length; i++) {
// do not write polygon closing path as lineto
var lineCount = type === 3 ? ring.length - 1 : ring.length
for (var i = 0; i < lineCount; i++) {
if (i === 1 && type !== 1) {
pbf.writeVarint(command(2, ring.length - 1)) // lineto
pbf.writeVarint(command(2, lineCount - 1)) // lineto
}

@@ -149,2 +157,5 @@ var dx = ring[i].x - x

}
if (type === 3) {
pbf.writeVarint(command(7, 0)) // closepath
}
}

@@ -151,0 +162,0 @@ }

@@ -9,3 +9,4 @@ 'use strict'

// conform to vectortile api
function GeoJSONWrapper (features) {
function GeoJSONWrapper (features, options) {
this.options = options || {}
this.features = features

@@ -16,6 +17,6 @@ this.length = features.length

GeoJSONWrapper.prototype.feature = function (i) {
return new FeatureWrapper(this.features[i])
return new FeatureWrapper(this.features[i], this.options.extent)
}
function FeatureWrapper (feature) {
function FeatureWrapper (feature, extent) {
this.id = typeof feature.id === 'number' ? feature.id : undefined

@@ -25,3 +26,3 @@ this.type = feature.type

this.properties = feature.tags
this.extent = 4096
this.extent = extent || 4096
}

@@ -28,0 +29,0 @@

{
"name": "vt-pbf",
"version": "3.0.1",
"version": "3.1.0",
"description": "Serialize mapbox vector tiles to binary protobufs in javascript.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -118,1 +118,29 @@ var fs = require('fs')

})
test('Pass options to fromGeojsonVt()', function (t) {
var version = 2
var extent = 8192
var orig = JSON.parse(fs.readFileSync(__dirname + '/fixtures/rectangle.geojson'))
var tileindex = geojsonVt(orig, { extent: extent })
var tile = tileindex.getTile(1, 0, 0)
var options = { version: version, extent: extent }
var buff = serialize.fromGeojsonVt({ 'geojsonLayer': tile }, options)
var vt = new VectorTile(new Pbf(buff))
var layer = vt.layers['geojsonLayer']
var features = []
for (var i = 0; i < layer.length; i++) {
var feat = layer.feature(i).toGeoJSON(0, 0, 1)
features.push(feat)
}
t.equal(layer.version, options.version, 'version should be equal')
t.equal(layer.extent, options.extent, 'extent should be equal')
orig.features.forEach(function (expected) {
var actual = features.shift()
t.ok(eq.compare(actual, expected))
})
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc