This repository has been archived by the owner on Apr 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
v8.js
58 lines (50 loc) · 1.45 KB
/
v8.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
function eachSource(style, callback) {
for (var k in style.sources) {
callback(style.sources[k]);
}
}
function eachLayer(style, callback) {
for (var k in style.layers) {
callback(style.layers[k]);
eachLayer(style.layers[k], callback);
}
}
function eachLayout(layer, callback) {
for (var k in layer) {
if (k.indexOf('layout') === 0) {
callback(layer[k], k);
}
}
}
function renameProperty(obj, from, to) {
obj[to] = obj[from]; delete obj[from];
}
module.exports = function(style) {
style.version = 8;
eachSource(style, function(source) {
if (source.type === 'video' &&
source.url !== undefined) {
renameProperty(source, 'url', 'urls');
}
if (source.type === 'video') {
source.coordinates.forEach(function(coord) {
return coord.reverse();
});
}
});
eachLayer(style, function(layer) {
eachLayout(layer, function(layout) {
if (typeof layout['text-font'] === 'string') {
layout['text-font'] = layout['text-font'].split(',')
.map(function(s) {
return s.trim();
});
}
if (layout['symbol-min-distance'] !== undefined) {
renameProperty(layout, 'symbol-min-distance', 'symbol-spacing');
}
});
});
return style;
};