-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaplibre.js
125 lines (119 loc) · 2.83 KB
/
maplibre.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { v8 } from "maplibre-gl/dist/style-spec";
let specFns = Object.entries(v8.expression_name.values).map(([key, value]) => {
return {
name: key,
doc: value.doc,
};
});
/**
* Add in some missing functions and docs
*/
specFns = specFns.concat([
{
name: "linear",
doc: "Interpolates linearly between the pair of stops just less than and just greater than the input.",
},
{
name: "exponential",
doc: "Interpolates exponentially between the stops just less than and just greater than the input.",
},
{
name: "cubic-bezier",
doc: "Interpolates using the cubic bezier curve defined by the given control points.",
},
]);
const expressionFns = specFns.map(({ name, doc }) => {
const renameFn = (name) => {
if (name === "-") {
return name;
}
return name.replace(/-/g, "_");
};
return {
type: "class",
label: renameFn(name),
detail: `— ${doc}`,
};
});
const definition = {
features: {
lookup: false,
array: true,
dictionary: true,
},
functions: {
argAutocomplete: () => {
return [];
},
functionAutocomplete: () => {
return expressionFns;
},
renames: [
["%", "mod"],
["^", "pow"],
["!", "not"],
["!=", "ne"],
["==", "eq"],
["<", "lt"],
["<=", "le"],
[">", "gt"],
[">=", "ge"],
["interpolate-hcl", "interpolate_hcl"],
["number-format", "number_format"],
["to-boolean", "to_boolean"],
["to-color", "to_color"],
["to-number", "to_number"],
["to-string", "to_string"],
["feature-state", "feature_state"],
["geometry-type", "geometry_type"],
["line-progress", "line_progress"],
["index-of", "index_of"],
["interpolate-hcl", "interpolate_hcl"],
["interpolate-lab", "interpolate_lab"],
["is-supported-script", "is_supported_script"],
["resolved-locale", "resolved_locale"],
["to-rgba", "to_tgba"],
["heatmap-density", "heatmap_density"],
],
types: {
format: (index) => {
if (index % 2 === 1) {
return ["object"];
}
},
"number-format": (index) => {
if (index % 2 === 1) {
return ["object"];
}
},
collator: (index) => {
if (index % 2 === 1) {
return ["object"];
}
},
literal: (index) => {
return ["object", "array", "any"];
},
},
format: [
{
name: "all",
breakAfter: true,
},
{
name: "format",
breakAfter: (length, index) => {
if (index === 0) {
return true;
} else if (length - 1 === index) {
return true;
} else if ((index - 1) % 2 === 1) {
return true;
}
return false;
},
},
],
},
};
export default definition;