-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V4 migration #16
Merged
V4 migration #16
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2a8f08b
migration to 3.1
ansis 7375c3e
Fix layer.filter for conversion
2ae7568
notworking: working on converting size fns to halo-width fns where si…
a8652d2
Converts text-halo-width to pixels
8088f97
travis-ify JS
3d58837
Captures exponential and linear functions in text-halo migrations, co…
58a288e
travis-ify fn migration
a9d6758
rename v3.1 to v4
mourner afd9bf5
Migrate glyphs to top level
jfirebaugh a869368
Validate v4
jfirebaugh 73ca80f
Git URL for spec
jfirebaugh 8b85a6c
Promote render `type` property to parent layer
jfirebaugh 97e1f65
Merge branch 'master' of github.com:mapbox/mapbox-gl-style-lint into …
edb12c5
Merge pull request #17 from mapbox/layer-type
mourner 6c96d26
delete render property if empty after type promotion
mourner dd7a037
Really delete render property if empty after type promotion
jfirebaugh 4d1ac03
these are not separate properties
ansis 3167c53
v4 migration icon type issues
dea5ce6
Fix validation for arrays of functions
c94fcdf
text-path: curve > symbol-placement: line, rm symbol-rotation-alignment
eddfcc9
icon-size, text-align, , symbol-rotation fixes
36a92da
Merge branch 'master' into v3.1
yhahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
'use strict'; | ||
|
||
//var ref = require('../lib/reference')('v4'); | ||
|
||
var vc; | ||
|
||
module.exports = function(v3) { | ||
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; | ||
}; | ||
|
||
var newTypes = { | ||
point: 'Point', | ||
line: 'LineString', | ||
polygon: 'Polygon' | ||
}; | ||
|
||
function convertLayer(layer) { | ||
var render = layer.render; | ||
|
||
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 (layer.type === 'text' || layer.type === 'icon') { | ||
layer.type = 'symbol'; | ||
|
||
var convertHalo = function(haloWidth, textSize) { | ||
return Number(((6 - haloWidth * 8) * textSize / 24).toFixed(2)); | ||
}; | ||
|
||
// convert text-halo-width to pixels | ||
for (var classname in layer) { | ||
if (classname.indexOf('style') === 0) { | ||
var style = layer[classname]; | ||
if (style['text-halo-width']) { | ||
if (typeof(style['text-halo-width']) == 'string' && style['text-halo-width'].indexOf('@') != -1) { | ||
style['text-halo-width'] = vc[style['text-halo-width']]; | ||
} | ||
// handle 3 cases: text-size as constant, text-size as #, no text-size but max-text-size | ||
var textSize = (typeof(style['text-size']) == 'string' && | ||
style['text-size'].indexOf('@') != -1) ? | ||
vc[style['text-size']] : | ||
(style['text-size'] ? | ||
style['text-size'] : | ||
layer.render['text-max-size']); | ||
|
||
// handle text-size numbers and functions | ||
if (typeof(textSize) == 'number') { | ||
style['text-halo-width'] = convertHalo(style['text-halo-width'], textSize); | ||
} else if (textSize && textSize.fn && textSize.fn == 'stops') { | ||
var stops = []; | ||
for (var stop in textSize.stops) { | ||
stops.push( | ||
[textSize.stops[stop][0], | ||
convertHalo(style['text-halo-width'], textSize.stops[stop][1])] | ||
); | ||
} | ||
style['text-halo-width'] = { | ||
"fn": "stops", | ||
"stops": stops | ||
}; | ||
} else if (textSize && textSize.fn && textSize.fn == ('exponential' || 'linear')) { | ||
var val; var max; var min; | ||
if (textSize.val) val = convertHalo(style['text-halo-width'], textSize.val); | ||
if (textSize.max) max = convertHalo(style['text-halo-width'], textSize.max); | ||
if (textSize.min) min = convertHalo(style['text-halo-width'], textSize.min); | ||
style['text-halo-width'] = textSize; | ||
style['text-halo-width'].val = val; | ||
style['text-halo-width'].max = max; | ||
style['text-halo-width'].min = min; | ||
} | ||
} | ||
} | ||
} | ||
|
||
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); | ||
} | ||
|
||
function rename(render, from, to) { | ||
if (render[from]) { | ||
render[to] = render[from]; | ||
delete render[from]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the culprit I suppose