Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Commit

Permalink
add label priority migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored and jfirebaugh committed Aug 13, 2015
1 parent 87c4620 commit d6a0c08
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 40 deletions.
26 changes: 26 additions & 0 deletions migrations/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,31 @@ module.exports = function(style) {
});
});

// Reverse order of symbol layers. This is an imperfect migration.
//
// The order of a symbol layer in the layers list affects two things:
// - how it is drawn relative to other layers (like oneway arrows below bridges)
// - the placement priority compared to other layers
//
// It's impossible to reverse the placement priority without breaking the draw order
// in some cases. This migration only reverses the order of symbol layers that
// are above all other types of layers.
//
// Symbol layers that are at the top of the map preserve their priority.
// Symbol layers that are below another type (line, fill) of layer preserve their draw order.

var firstSymbolLayer = 0;
for (var i = style.layers.length - 1; i >= 0; i--) {
var layer = style.layers[i];
if (layer.type !== 'symbol') {
firstSymbolLayer = i + 1;
break;
}
}

var symbolLayers = style.layers.splice(firstSymbolLayer);
symbolLayers.reverse();
style.layers = style.layers.concat(symbolLayers);

return style;
};
68 changes: 34 additions & 34 deletions test/fixture/v7-migrate/style-basic.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,6 @@
"line-width": 1
}
},
{
"id": "poi",
"type": "symbol",
"source": "mapbox.mapbox-streets-v5",
"source-layer": "poi_label",
"layout": {
"icon-rotation-alignment": "viewport"
}
},
{
"id": "country_label",
"type": "symbol",
"source": "mapbox.mapbox-streets-v5",
"source-layer": "country_label",
"filter": [
"==",
"$type",
"Point"
],
"layout": {
"text-field": "{name}",
"text-font": [
"Open Sans Regular",
"Arial Unicode MS Regular"
],
"text-padding": 10
},
"paint": {
"text-halo-color": "rgba(255,255,255,0.7)",
"text-halo-width": 0.25,
"text-color": "#000000"
}
},
{
"id": "road_label",
"type": "symbol",
Expand Down Expand Up @@ -148,6 +115,39 @@
"text-halo-color": "rgba(255,255,255,0.7)",
"text-halo-width": 0.25
}
},
{
"id": "country_label",
"type": "symbol",
"source": "mapbox.mapbox-streets-v5",
"source-layer": "country_label",
"filter": [
"==",
"$type",
"Point"
],
"layout": {
"text-field": "{name}",
"text-font": [
"Open Sans Regular",
"Arial Unicode MS Regular"
],
"text-padding": 10
},
"paint": {
"text-halo-color": "rgba(255,255,255,0.7)",
"text-halo-width": 0.25,
"text-color": "#000000"
}
},
{
"id": "poi",
"type": "symbol",
"source": "mapbox.mapbox-streets-v5",
"source-layer": "poi_label",
"layout": {
"icon-rotation-alignment": "viewport"
}
}
]
}
}
18 changes: 12 additions & 6 deletions test/migrations/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ t('renames urls', function (t) {
"type": "video", "url": ["foo"],
coordinates: [[1, 0], [1, 0], [1, 0], [1, 0]]
}
}
},
"layers": []
};

var output = {
Expand All @@ -113,7 +114,8 @@ t('renames urls', function (t) {
"type": "video", "urls": ["foo"],
coordinates: [[0, 1], [0, 1], [0, 1], [0, 1]]
}
}
},
"layers": []
};

t.deepEqual(migrate(input), output, 'renames url and flips coordinates of of video');
Expand Down Expand Up @@ -486,12 +488,14 @@ t('update fontstack function constant', function (t) {
t('migrate UNversioned fontstack urls', function (t) {
var input = {
"version": 7,
"glyphs": "mapbox://fontstack/{fontstack}/{range}.pbf"
"glyphs": "mapbox://fontstack/{fontstack}/{range}.pbf",
"layers": []
};

var output = {
"version": 8,
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf"
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
"layers": []
};

t.deepEqual(migrate(input), output);
Expand All @@ -501,12 +505,14 @@ t('migrate UNversioned fontstack urls', function (t) {
t('migrate versioned fontstack urls', function (t) {
var input = {
"version": 7,
"glyphs": "mapbox://fonts/v1/boxmap/{fontstack}/{range}.pbf"
"glyphs": "mapbox://fonts/v1/boxmap/{fontstack}/{range}.pbf",
"layers": []
};

var output = {
"version": 8,
"glyphs": "mapbox://fonts/boxmap/{fontstack}/{range}.pbf"
"glyphs": "mapbox://fonts/boxmap/{fontstack}/{range}.pbf",
"layers": []
};

t.deepEqual(migrate(input), output);
Expand Down

0 comments on commit d6a0c08

Please sign in to comment.