Skip to content

Commit

Permalink
v4 migration icon type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Jul 8, 2014
2 parents 97e1f65 + 4d1ac03 commit 3167c53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
6 changes: 3 additions & 3 deletions bin/gl-style-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ var migrated = false;
if (data.version === 2) {
// Migrate to v3
data = require('../migrations/v3')(data);
data = require('../migrations/v3.1')(data);
data = require('../migrations/v4')(data);
migrated = true;
}

if (data.version === 3) {
// Migrate to v3.1
data = require('../migrations/v3.1')(data);
// Migrate to v4
data = require('../migrations/v4')(data);
migrated = true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var parseCSSColor = require('csscolorparser').parseCSSColor;
module.exports = {};
module.exports.value = value;

['v2','v3'].forEach(function(version) {
['v2','v3','v4'].forEach(function(version) {
var ref = reference(version);
// Create validator for version
module.exports[version] = validator(ref);
Expand Down
55 changes: 34 additions & 21 deletions migrations/v3.1.js → migrations/v4.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
'use strict';

//var ref = require('../lib/reference')('v3');
//var ref = require('../lib/reference')('v4');

var vc;

module.exports = function(v3) {
//v3.version = 3.1;
v3.version = 4;
vc = v3.constants;
for (var id in v3.sources) {
var source = v3.sources[id];
if (source.glyphs) {
v3.glyphs = source.glyphs;
delete source.glyphs;
}
}
v3.layers.forEach(convertLayer);
return v3;
};
Expand All @@ -22,29 +29,20 @@ function convertLayer(layer) {

if (!render) return;

layer.type = render.type;
delete render.type;


if (Object.keys(render).length === 0) { // was just type
delete layer.render;
}

if (layer.filter && layer.filter.$type) {
layer.filter.$type = newTypes[layer.filter.$type];
}

if (render.type === 'text' || render.type === 'icon') {
render.type = 'symbol';

rename(render, 'icon-spacing', 'symbol-min-distance');
rename(render, 'text-min-distance', 'symbol-min-distance');
rename(render, 'icon-allow-overlap', 'symbol-allow-overlap');
rename(render, 'text-allow-overlap', 'symbol-allow-overlap');
rename(render, 'icon-ignore-placement', 'symbol-ignore-placement');
rename(render, 'text-ignore-placement', 'symbol-ignore-placement');

if (layer.style && layer.style['icon-rotate-anchor']) {
render['symbol-rotation-alignment'] = layer.style['icon-rotate-anchor'];
delete layer.style['icon-rotate-anchor'];
}

if (render['text-path' === 'curve']) {
render['symbol-rotation-alignment'] = 'map';
render.placement = 'line';
}
if (layer.type === 'text' || layer.type === 'icon') {
layer.type = 'symbol';

var convertHalo = function(haloWidth, textSize) {
return Number(((6 - haloWidth * 8) * textSize / 24).toFixed(2));
Expand Down Expand Up @@ -95,6 +93,21 @@ function convertLayer(layer) {
}
}

if (!layer.render) return;

rename(render, 'icon-spacing', 'symbol-min-distance');
rename(render, 'text-min-distance', 'symbol-min-distance');

if (layer.style && layer.style['icon-rotate-anchor']) {
render['symbol-rotation-alignment'] = layer.style['icon-rotate-anchor'];
delete layer.style['icon-rotate-anchor'];
}

if (render['text-path' === 'curve']) {
render['symbol-rotation-alignment'] = 'map';
render.placement = 'line';
}

delete render['text-path'];
}
if (layer.layers) layer.layers.forEach(convertLayer);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"coveralls": "~2.10.0"
},
"dependencies": {
"mapbox-gl-style-spec": "0.0.2",
"mapbox-gl-style-spec": "git://github.com/mapbox/mapbox-gl-style-spec.git",
"js-beautify": "^1.4.2",
"minimist": "0.0.8",
"jsonlint-lines": "~1.6.0",
Expand Down

1 comment on commit 3167c53

@lbud
Copy link
Contributor

@lbud lbud commented on 3167c53 Jul 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I should justify how major this looks, I had a bunch of previously uncommitted changes and git'ed things funny, I think, and now everything looks weird 😕. The only real change here is grouping all the layer.render properties together and moving the return down after deleting empty layer.render so it doesn't affect other layer changes.

Please sign in to comment.