Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Style-specific layer order/instances #147

Merged
merged 3 commits into from

1 participant

@yhahn
Owner

#133

Adds handling of an optional layers property in project.yml.

Styles can now reorder and create multiple instances of layers. Suppose a source has the layers

a
b
c

A style can define its own order and instances of the layers with the following property:

layers:
- b
- a.data
- c
- a.label

Where a.label refers to <id>.<class> in carto. Note that while it's possible to do something like

layers:
- a
- a.label

where one of the layer instances is classed and the other is not, in practice it is very hard to use.

No UI for this yet, will meditate on what makes sense here (reordering is straightforward, reinstancing ... not as much).

cc @ajashton @springmeyer

@yhahn yhahn merged commit 54f0388 into master

1 check passed

Details default The Travis CI build passed
@yhahn yhahn deleted the layer-instance branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 1 deletion.
  1. +6 −1 lib/style.js
  2. +22 −0 test/style.test.js
View
7 lib/style.js
@@ -31,6 +31,7 @@ var defaults = {
format:'png8:m=h',
template:'',
interactivity_layer:'',
+ layers:null,
_properties: {},
_prefs: {
saveCenter: true
@@ -175,9 +176,13 @@ style.toXML = function(data, callback) {
opts.srs = tm.srs['900913'];
// Convert datatiles sources to mml layers.
- opts.Layer = _(backend.data.vector_layers).map(function(layer) { return {
+ var layers = data.layers ? data.layers.map(function(l) {
+ return { id: l.split('.')[0], 'class': l.split('.')[1] }
+ }) : backend.data.vector_layers;
+ opts.Layer = layers.map(function(layer) { return {
id:layer.id,
name:layer.id,
+ 'class':layer['class'],
// Styles can provide a hidden _properties key with
// layer-specific property overrides. Current workaround to layer
// properties that could (?) eventually be controlled via carto.
View
22 test/style.test.js
@@ -143,6 +143,28 @@ describe('style.toXML', function() {
assert.ok(/<Layer name="water"/.test(xml), 'includes layer');
assert.ok(/group-by="layer"/.test(xml), 'includes layer properties');
assert.ok(/<PolygonSymbolizer fill="#ffffff"/.test(xml), 'includes rule');
+ assert.ok(xml.indexOf('<Layer name="road"') < xml.indexOf('<Layer name="bridge"'));
+ done();
+ });
+ });
+ it('compiles layer order + classed layers', function(done) {
+ style.toXML({
+ id:'tmstyle:///tmp-1234',
+ source:'mapbox:///mapbox.mapbox-streets-v2',
+ styles:{'style.mss': '#water { polygon-fill:#fff } #road.line::line { line-width:0.5 } #road.label::label { line-width:1 }'},
+ layers:[ 'water', 'bridge', 'poi_label', 'road.line', 'tunnel', 'road.label' ],
+ _properties:{bridge:{'group-by':'layer'}}
+ }, function(err, xml) {
+ assert.ifError(err);
+ assert.ok(/<Map srs/.test(xml), 'looks like Mapnik XML');
+ assert.ok(/<Layer name="water"/.test(xml), 'includes layer');
+ assert.ok(/group-by="layer"/.test(xml), 'includes layer properties');
+ assert.ok(/<PolygonSymbolizer fill="#ffffff"/.test(xml), 'includes rule');
+ // Moves specified layers last, in order.
+ assert.ok(xml.indexOf('<Layer name="road"') > xml.indexOf('<Layer name="poi_label"'));
+ assert.ok(xml.indexOf('<Layer name="road"') > xml.indexOf('<Layer name="road_label"'));
+ assert.ok(xml.indexOf('<Layer name="tunnel"') > xml.indexOf('<Layer name="road"'));
+ assert.ok(xml.indexOf('<StyleName>road-label</StyleName>') > xml.indexOf('<StyleName>road-line</StyleName>'));
done();
});
});
Something went wrong with that request. Please try again.