fix(style): validate layer style configuration
This commit is contained in:
@@ -28,8 +28,11 @@ export default tool({
|
||||
.describe("Classification method."),
|
||||
segments: tool.schema
|
||||
.number()
|
||||
.int()
|
||||
.min(2)
|
||||
.max(10)
|
||||
.optional()
|
||||
.describe("Number of segments."),
|
||||
.describe("Number of rendered intervals, from 2 to 10."),
|
||||
min_size: tool.schema
|
||||
.number()
|
||||
.optional()
|
||||
@@ -54,9 +57,9 @@ export default tool({
|
||||
.enum(["single", "gradient", "rainbow", "custom"])
|
||||
.optional()
|
||||
.describe("Color strategy."),
|
||||
single_palette_index: tool.schema.number().optional(),
|
||||
gradient_palette_index: tool.schema.number().optional(),
|
||||
rainbow_palette_index: tool.schema.number().optional(),
|
||||
single_palette_index: tool.schema.number().int().min(0).max(6).optional(),
|
||||
gradient_palette_index: tool.schema.number().int().min(0).max(2).optional(),
|
||||
rainbow_palette_index: tool.schema.number().int().min(0).max(1).optional(),
|
||||
show_labels: tool.schema
|
||||
.boolean()
|
||||
.optional()
|
||||
@@ -65,7 +68,7 @@ export default tool({
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Whether to show ids."),
|
||||
opacity: tool.schema.number().optional().describe("Opacity in [0, 1]."),
|
||||
opacity: tool.schema.number().min(0).max(1).optional().describe("Opacity in [0, 1]."),
|
||||
adjust_width_by_property: tool.schema
|
||||
.boolean()
|
||||
.optional()
|
||||
@@ -73,11 +76,11 @@ export default tool({
|
||||
custom_breaks: tool.schema
|
||||
.array(tool.schema.number())
|
||||
.optional()
|
||||
.describe("Custom break values."),
|
||||
.describe("Strictly increasing boundaries. Length must equal segments + 1."),
|
||||
custom_colors: tool.schema
|
||||
.array(tool.schema.string())
|
||||
.optional()
|
||||
.describe("Custom rgba colors."),
|
||||
.describe("Custom CSS colors. Length must equal segments."),
|
||||
})
|
||||
.optional()
|
||||
.describe(
|
||||
@@ -87,8 +90,24 @@ export default tool({
|
||||
async execute(args) {
|
||||
const layerLabel = args.layer_id === "junctions" ? "节点" : "管道";
|
||||
if (args.reset_to_default) {
|
||||
return `已将${layerLabel}图层重置为默认样式。`;
|
||||
return `已提交${layerLabel}图层默认样式重置请求。`;
|
||||
}
|
||||
return `已对${layerLabel}图层应用样式。`;
|
||||
const style = args.style_config;
|
||||
if (style?.custom_breaks) {
|
||||
if (
|
||||
style.custom_breaks.some(
|
||||
(value, index, values) => index > 0 && value <= values[index - 1],
|
||||
)
|
||||
) {
|
||||
throw new Error("custom_breaks must be strictly increasing");
|
||||
}
|
||||
if (style.segments && style.custom_breaks.length !== style.segments + 1) {
|
||||
throw new Error("custom_breaks length must equal segments + 1");
|
||||
}
|
||||
}
|
||||
if (style?.segments && style.custom_colors && style.custom_colors.length !== style.segments) {
|
||||
throw new Error("custom_colors length must equal segments");
|
||||
}
|
||||
return `已提交${layerLabel}图层样式请求。`;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user