diff options
-rwxr-xr-x | bin/convert-style.js | 35 | ||||
-rw-r--r-- | proto/style.proto | 27 |
2 files changed, 47 insertions, 15 deletions
diff --git a/bin/convert-style.js b/bin/convert-style.js index aeabbfe86a..78cc17d5a5 100755 --- a/bin/convert-style.js +++ b/bin/convert-style.js @@ -1,9 +1,11 @@ #!/usr/bin/env node +'use strict'; + var style = require('./style.js'); var Protobuf = require('./protobuf.js'); -var fs = require('fs'); +// var fs = require('fs'); var pbf = new Protobuf(); @@ -17,12 +19,29 @@ var bucket_type = { // enum var cap_type = { round: 1, -} +}; // enum var join_type = { butt: 1, bevel: 2 +}; + + +function createValue(value) { + var pbf = new Protobuf(); + + if (typeof value === 'string') { + pbf.writeTaggedString(1 /* string_value */, value); + } else if (typeof value === 'boolean') { + pbf.writeTaggedBoolean(7 /* bool_value */, value); + } else { + // TODO: + console.warn('encode value: %s', value); + process.exit(); + } + + return pbf; } function createBucket(bucket, name) { @@ -36,7 +55,7 @@ function createBucket(bucket, name) { pbf.writeTaggedString(5 /* source_field */, bucket.field); var values = Array.isArray(bucket.value) ? bucket.value : [bucket.value]; for (var i = 0; i < values.length; i++) { - pbf.writeTaggedString(6 /* source_values */, values[i]); + pbf.writeMessage(6 /* source_value */, createValue(values[i])); } } if (bucket.cap) { @@ -58,7 +77,7 @@ function createStructure(structure) { pbf.writeTaggedString(2 /* bucket_name */, structure.bucket); } else if (structure.layers) { for (var i = 0; i < structure.layers.length; i++) { - pbf.writeMessage(3 /* child_layers */, createStructure(structure.layers[i])); + pbf.writeMessage(3 /* child_layer */, createStructure(structure.layers[i])); } } return pbf; @@ -79,7 +98,7 @@ function createWidth(width) { } else { values.push(width); } - pbf.writePackedFloats(2 /* values */, values); + pbf.writePackedFloats(2 /* value */, values); return pbf; } @@ -113,7 +132,7 @@ function createClass(klass) { var pbf = new Protobuf(); pbf.writeTaggedString(1 /* name */, klass.name); for (var name in klass.layers) { - pbf.writeMessage(2 /* layers */, createLayer(klass.layers[name], name)); + pbf.writeMessage(2 /* layer */, createLayer(klass.layers[name], name)); } return pbf; } @@ -124,7 +143,7 @@ function createClass(klass) { for (var name in style.buckets) { var bucket = style.buckets[name]; - pbf.writeMessage(1 /* buckets */, createBucket(bucket, name)); + pbf.writeMessage(1 /* bucket */, createBucket(bucket, name)); } for (var i = 0; i < style.structure.length; i++) { @@ -134,7 +153,7 @@ for (var i = 0; i < style.structure.length; i++) { for (var i = 0; i < style.classes.length; i++) { var klass = style.classes[i]; - pbf.writeMessage(3 /* classes */, createClass(klass)); + pbf.writeMessage(3 /* class */, createClass(klass)); } process.stdout.write(pbf.finish()); diff --git a/proto/style.proto b/proto/style.proto index cf6a8db6de..c8926c767c 100644 --- a/proto/style.proto +++ b/proto/style.proto @@ -13,6 +13,19 @@ enum join_type { bevel = 2; } +message value { + // Exactly one of these values may be present in a valid message + optional string string_value = 1; + optional float float_value = 2; + optional double double_value = 3; + optional int64 int_value = 4; + optional uint64 uint_value = 5; + optional sint64 sint_value = 6; + optional bool bool_value = 7; + + extensions 8 to max; +} + message bucket { required string name = 1; required bucket_type type = 2; @@ -21,24 +34,24 @@ message bucket { required string source_name = 3; required string source_layer = 4; optional string source_field = 5; - repeated string source_values = 6; + repeated value source_value = 6; // Specifies how the geometry for this bucket should be created optional cap_type cap = 7; optional join_type join = 8; optional string font = 9; - optional float fontSize = 10; + optional float font_size = 10; } message structure { required string name = 1; optional string bucket_name = 2; - repeated structure child_layers = 3; + repeated structure child_layer = 3; } message width { optional string scaling = 1; - repeated float values = 2 [ packed = true ]; + repeated float value = 2 [ packed = true ]; } message layer { @@ -50,12 +63,12 @@ message layer { message class { required string name = 1; - repeated layer layers = 2; + repeated layer layer = 2; } // root level object message style { - repeated bucket buckets = 1; + repeated bucket bucket = 1; repeated structure structure = 2; - repeated class classes = 3; + repeated class class = 3; } |