Skip to content

Commit f9cad00

Browse files
ochafikclaude
andcommitted
fix: position camera during streaming partial input
The camera only moved after the full tool input was received. Now ontoolinputpartial positions the camera as soon as bbox/center fields are available (once), so markers appear in the right location during progressive streaming. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 68cf651 commit f9cad00

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

examples/map-server/src/mcp-app.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,15 +1498,55 @@ function updateCopyButton(): void {
14981498
// Tool Input Handlers
14991499
// =============================================================================
15001500

1501+
// Track whether we've already positioned the camera from streaming
1502+
let hasPositionedFromPartial = false;
1503+
15011504
// Handle streaming tool input (progressive annotation rendering)
15021505
app.ontoolinputpartial = (params) => {
15031506
if (!viewer) return;
15041507
const args = params.arguments as
1505-
| { annotations?: AnnotationDef[] }
1508+
| {
1509+
west?: number;
1510+
south?: number;
1511+
east?: number;
1512+
north?: number;
1513+
latitude?: number;
1514+
longitude?: number;
1515+
radiusKm?: number;
1516+
annotations?: AnnotationDef[];
1517+
}
15061518
| undefined;
1507-
if (!args?.annotations || args.annotations.length === 0) return;
1519+
if (!args) return;
1520+
1521+
// Position camera as soon as bbox/center fields are available (once)
1522+
if (!hasPositionedFromPartial) {
1523+
let bbox: BoundingBox | null = null;
1524+
if (
1525+
args.west != null &&
1526+
args.south != null &&
1527+
args.east != null &&
1528+
args.north != null
1529+
) {
1530+
bbox = {
1531+
west: args.west,
1532+
south: args.south,
1533+
east: args.east,
1534+
north: args.north,
1535+
};
1536+
} else if (args.latitude != null && args.longitude != null) {
1537+
bbox = bboxFromCenter(args.latitude, args.longitude, args.radiusKm ?? 50);
1538+
}
1539+
if (bbox) {
1540+
hasPositionedFromPartial = true;
1541+
hasReceivedToolInput = true;
1542+
setViewToBoundingBox(viewer, bbox);
1543+
hideLoading();
1544+
log.info("Positioned camera from streaming partial");
1545+
}
1546+
}
15081547

1509-
// Process all but the last item (which may be truncated from streaming)
1548+
// Process annotations (all but last which may be truncated)
1549+
if (!args.annotations || args.annotations.length === 0) return;
15101550
const safe = args.annotations.slice(0, -1);
15111551
for (const ann of safe) {
15121552
if (!ann.id || !ann.type) continue;

0 commit comments

Comments
 (0)