feat(map): add coordinate zoom action
This commit is contained in:
@@ -118,6 +118,12 @@ const TOOL_META: Record<string, ToolMeta> = {
|
||||
actionLabel: "定位到地图",
|
||||
color: "#3ba272",
|
||||
},
|
||||
zoom_to_map: {
|
||||
label: "缩放到坐标",
|
||||
icon: <LocationOnRounded sx={{ fontSize: 18 }} />,
|
||||
actionLabel: "缩放到地图",
|
||||
color: "#0ea5e9",
|
||||
},
|
||||
view_history: {
|
||||
label: "查看计算结果",
|
||||
icon: <TimelineRounded sx={{ fontSize: 18 }} />,
|
||||
@@ -176,6 +182,46 @@ function normalizeLocateIds(params: Record<string, unknown>): string[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
function readFiniteNumber(value: unknown): number | null {
|
||||
if (typeof value === "number" && Number.isFinite(value)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildZoomTo3857Action(
|
||||
params: Record<string, unknown>,
|
||||
): Extract<ChatToolAction, { type: "zoom_to_map" }> | null {
|
||||
const rawCoordinate = params.coordinate ?? params.coordinates ?? params.center;
|
||||
const tuple = Array.isArray(rawCoordinate)
|
||||
? rawCoordinate
|
||||
: [params.x ?? params.lon ?? params.longitude, params.y ?? params.lat ?? params.latitude];
|
||||
const x = readFiniteNumber(tuple[0]);
|
||||
const y = readFiniteNumber(tuple[1]);
|
||||
if (x === null || y === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const zoom = readFiniteNumber(params.zoom);
|
||||
const durationMs = readFiniteNumber(params.duration_ms ?? params.durationMs);
|
||||
const rawSourceCrs = params.source_crs ?? params.sourceCrs ?? params.crs;
|
||||
const normalizedSourceCrs =
|
||||
typeof rawSourceCrs === "string" ? rawSourceCrs.trim().toUpperCase() : "";
|
||||
const sourceCrs =
|
||||
normalizedSourceCrs === "EPSG:4326" ? "EPSG:4326" : "EPSG:3857";
|
||||
return {
|
||||
type: "zoom_to_map",
|
||||
coordinate: [x, y],
|
||||
sourceCrs,
|
||||
zoom: zoom ?? undefined,
|
||||
durationMs: durationMs ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function getToolDescription(toolCall: ToolCall): string {
|
||||
const { params } = toolCall;
|
||||
const resolveScadaFeatureInfos = (): [string, string][] => {
|
||||
@@ -281,6 +327,14 @@ function getToolDescription(toolCall: ToolCall): string {
|
||||
case "render_junctions": {
|
||||
return (params.render_ref as string | undefined) ?? "渲染引用";
|
||||
}
|
||||
case "zoom_to_map": {
|
||||
const action = buildZoomTo3857Action(params);
|
||||
if (!action) {
|
||||
return "地图坐标";
|
||||
}
|
||||
const zoom = action.zoom === undefined ? "" : ` · zoom ${action.zoom}`;
|
||||
return `${action.coordinate[0]}, ${action.coordinate[1]} · ${action.sourceCrs}${zoom}`;
|
||||
}
|
||||
case APPLY_LAYER_STYLE_TOOL: {
|
||||
const payload = parseApplyLayerStylePayload(params);
|
||||
return payload ? describeApplyLayerStyle(payload) : "图层样式";
|
||||
@@ -341,6 +395,8 @@ function buildAction(toolCall: ToolCall): ChatToolAction | null {
|
||||
(params.end as string | undefined),
|
||||
});
|
||||
switch (toolCall.tool) {
|
||||
case "zoom_to_map":
|
||||
return buildZoomTo3857Action(params);
|
||||
case "locate_features": {
|
||||
const featureTypeRaw = params.feature_type;
|
||||
const featureType =
|
||||
|
||||
Reference in New Issue
Block a user