Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v2.3.0
- Update dependabot security advisories
- lodash
- minimist
- eslint
- Update geobuf dependency to latest 3.x version
- stringify any numeric feature IDs to be consistent with v2.x even though the geobuf specification allows integer IDs
- update all `featureToGeobuf` methods to `encode`
- update all `geobufToFeature` methods to `decode`
- install `pbf` dependency

## v2.2.5
- update dyno and minimist versions to resolve critical dependencies

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var queue = require('queue-async');
var Dyno = require('@mapbox/dyno');
var AWS = require('aws-sdk');
var geobuf = require('geobuf');
var Pbf = require('pbf');

var stream = require('stream');

var MAX_GEOMETRY_SIZE = 1024 * 10; // 10KB
Expand Down Expand Up @@ -121,7 +123,7 @@ function Cardboard(config) {
if (encoded[1]) q.defer(config.s3.putObject.bind(config.s3), encoded[1]);
q.defer(config.dyno.putItem, {Item: encoded[0]});
q.await(function(err) {
var result = geobuf.geobufToFeature(encoded[0].val || encoded[1].Body);
var result = geobuf.decode(new Pbf(encoded[0].val || encoded[1].Body));
result.id = utils.idFromRecord(encoded[0]);
callback(err, result);
});
Expand Down
7 changes: 5 additions & 2 deletions lib/batch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var queue = require('queue-async');
var geobuf = require('geobuf');
var Pbf = require('pbf');
var _ = require('lodash');
var Dyno = require('@mapbox/dyno');
var AWS = require('aws-sdk');
Expand Down Expand Up @@ -60,7 +61,9 @@ module.exports = function(config) {
var unprocessed = res.UnprocessedItems ? res.UnprocessedItems[table] : null;

if (!unprocessed) {
var features = geobufs.map(geobuf.geobufToFeature.bind(geobuf));
var features = geobufs.map(function(f) {
return geobuf.decode(new Pbf(f));
});
return callback(null, { type: 'FeatureCollection', features: features });
}

Expand All @@ -70,7 +73,7 @@ module.exports = function(config) {
return utils.idFromRecord(record) === id;
});

collection.features.push(geobuf.geobufToFeature(geobufs[i]));
collection.features.push(geobuf.decode(new Pbf(geobufs[i])));
return collection;
}, { type: 'FeatureCollection', features: [] });

Expand Down
5 changes: 4 additions & 1 deletion lib/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var SphericalMercator = require('sphericalmercator');
var merc = new SphericalMercator();
var _ = require('lodash');
var geobuf = require('geobuf');
var Pbf = require('pbf');

module.exports = Metadata;

Expand Down Expand Up @@ -56,7 +57,7 @@ function Metadata(dyno, dataset) {
metadata.getFeatureInfo = function(feature) {
var bounds = extent(feature);
return {
size: geobuf.featureToGeobuf(feature).toBuffer().length,
size: Buffer.from(geobuf.encode(feature, new Pbf())).length,
bounds: bounds,
west: bounds[0],
south: bounds[1],
Expand Down Expand Up @@ -326,6 +327,7 @@ function Metadata(dyno, dataset) {
* @returns {object} same metadata with additional information appended
*/
function prepare(info) {
console.log(info);
var range = zoomRange(info.size, [info.west, info.south, info.east, info.north]);
var result = _.clone(info);
result.minzoom = range.min;
Expand All @@ -346,6 +348,7 @@ function prepare(info) {
* @returns {object} an object with `min` and `max` properties corresponding to an ideal min and max zoom
*/
function zoomRange(bytes, extent) {
console.log(bytes, extent);
var maxSize = 500 * 1024;
var maxzoom = 14;
for (var z = 22; z >= 0; z--) {
Expand Down
17 changes: 14 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var queue = require('queue-async');
var geobuf = require('geobuf');
var Pbf = require('pbf');
var url = require('url');
var geojsonNormalize = require('geojson-normalize');
var _ = require('lodash');
Expand Down Expand Up @@ -30,7 +31,7 @@ function Utils(config) {
var feature;
if (val) {
try {
feature = geobuf.geobufToFeature(val);
feature = geobuf.decode(new Pbf(val));
} catch(e) {
return next(e);
}
Expand All @@ -44,7 +45,7 @@ function Utils(config) {
}, function(err, data) {
if (err) return next(err);
try {
feature = geobuf.geobufToFeature(data.Body);
feature = geobuf.decode(new Pbf(data.Body));
} catch(e) {
return next(e);
}
Expand Down Expand Up @@ -77,6 +78,16 @@ function Utils(config) {
utils.toDatabaseRecord = function(feature, dataset) {
if (feature.id === 0) feature.id = '0';
var f = feature.id ? _.clone(feature) : _.extend({}, feature, { id: cuid() });

// ID converted to string to preserve functionality from v2.2.2
// in v2.3.0 we updated geobuf which includes an updated geobuf.proto
// specification, which allows the id to be oneof sint64 or string
// https://github.com/mapbox/geobuf/blob/daad5e039f842f4d4f24ed7d59f31586563b71b8/geobuf.proto#L18-L21
//
// former specification
// https://github.com/mapbox/geobuf/blob/a5cec56488185bff8fa38007979e00a121f442a0/geobuf.proto#L35-L37
f.id = f.id.toString();

var primary = f.id;

if (!f.geometry) {
Expand All @@ -92,7 +103,7 @@ function Utils(config) {
}

var info = Metadata(config.dyno, dataset).getFeatureInfo(f);
var buf = geobuf.featureToGeobuf(f).toBuffer();
var buf = Buffer.from(geobuf.encode(f, new Pbf()));
var tile = tilebelt.bboxToTile([info.west, info.south, info.east, info.north]);
var cell = tilebelt.tileToQuadkey(tile);
var useS3 = buf.length >= config.MAX_GEOMETRY_SIZE;
Expand Down
Loading