优化queryFeaturesByIds ID 处理逻辑,确保查询功能正常
This commit is contained in:
@@ -789,12 +789,27 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Other frontend tools → dispatch to chatToolStore immediately
|
// Other frontend tools → dispatch to chatToolStore immediately
|
||||||
|
const normalizeIds = (): string[] => {
|
||||||
|
const rawIds = params.ids;
|
||||||
|
if (Array.isArray(rawIds)) {
|
||||||
|
return rawIds
|
||||||
|
.map((id) => String(id).trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
if (typeof rawIds === "string") {
|
||||||
|
return rawIds
|
||||||
|
.split(",")
|
||||||
|
.map((id) => id.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
const buildLocateFeaturesAction = (
|
const buildLocateFeaturesAction = (
|
||||||
layer: string,
|
layer: string,
|
||||||
geometryKind: "point" | "line",
|
geometryKind: "point" | "line",
|
||||||
): ChatToolAction => ({
|
): ChatToolAction => ({
|
||||||
type: "locate_features" as const,
|
type: "locate_features" as const,
|
||||||
ids: (params.ids as string[]) ?? [],
|
ids: normalizeIds(),
|
||||||
layer,
|
layer,
|
||||||
geometryKind,
|
geometryKind,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -224,11 +224,16 @@ const queryFeaturesByIds = async (
|
|||||||
ids: string[],
|
ids: string[],
|
||||||
layer?: string
|
layer?: string
|
||||||
): Promise<Feature[]> => {
|
): Promise<Feature[]> => {
|
||||||
if (!ids.length) {
|
const normalizedIds = ids
|
||||||
|
.map((id) => String(id).trim())
|
||||||
|
.filter((id) => id.length > 0);
|
||||||
|
|
||||||
|
if (!normalizedIds.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const orFilter = ids.map((id) => `id='${id}'`).join(" OR ");
|
const escapedIds = normalizedIds.map((id) => id.replace(/'/g, "''"));
|
||||||
|
const orFilter = escapedIds.map((id) => `id='${id}'`).join(" OR ");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!layer) {
|
if (!layer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user