Skip to content

cesium-mcp-bridge

浏览器 SDK — 嵌入到 CesiumJS 应用中,通过 WebSocket 接收命令。

npm

安装

bash
npm install cesium-mcp-bridge

Peer 依赖cesium@~1.139.0

初始化

js
import { CesiumBridge } from 'cesium-mcp-bridge'

const viewer = new Cesium.Viewer('cesiumContainer')
const bridge = new CesiumBridge(viewer)

命令(58 个)

视图控制

命令描述关键参数
flyTo相机飞行动画到指定位置longitude, latitude, height, heading, pitch, roll, duration
setView立即设置相机位置longitude, latitude, height, heading, pitch, roll
getView获取当前相机状态
zoomToExtent缩放到地理范围west, south, east, north
saveViewpoint保存当前视角为命名书签name
loadViewpoint恢复已保存的视点书签name, duration
listViewpoints列出所有视点书签
exportScene导出场景为结构化 JSON 快照

实体

命令描述关键参数
addMarker添加点标记longitude, latitude, label, color, size
addLabel添加文字标注data, field, style
addPolyline添加折线(路径/线段)coordinates, color, width, clampToGround
addPolygon添加多边形区域coordinates, color, outlineColor, opacity, extrudedHeight
addModel放置 3D 模型 (glTF/GLB)longitude, latitude, url, scale, heading, pitch, roll
updateEntity更新实体属性entityId, position, color, label, scale, show
removeEntity移除单个实体entityId
batchAddEntities批量添加多个实体entities(类型化定义数组)
queryEntities搜索/筛选场景中的实体name, type, bbox
getEntityProperties获取实体的所有属性entityId

图层管理

命令描述关键参数
addGeoJsonLayer加载 GeoJSON 数据urldata, name, style
listLayers列出所有已加载图层
removeLayer按 ID 移除图层layerId
clearAll移除所有图层、实体和数据源
setLayerVisibility显示/隐藏图层layerId, visible
updateLayerStyle修改图层样式layerId, style, tileStyle
getLayerSchema获取图层属性字段结构layerId
setBasemap切换底图影像provider, url

高级相机

命令描述关键参数
lookAtTransform环绕式相机注视longitude, latitude, height, heading, pitch, range
startOrbit开始相机环绕旋转speed, direction
stopOrbit停止环绕动画
setCameraOptions配置相机控制器enableRotate, enableZoom, enableTilt

扩展实体类型

命令描述关键参数
addBillboard添加图片图标longitude, latitude, image, scale
addBox添加 3D 盒体position, dimensions, material
addCorridor添加走廊positions, width, material
addCylinder添加圆柱体/圆锥体position, length, topRadius, bottomRadius
addEllipse添加椭圆position, semiMajorAxis, semiMinorAxis
addRectangle添加矩形west, south, east, north, material
addWall添加墙体positions, maximumHeights, minimumHeights

动画

命令描述关键参数
createAnimation创建路径动画entityId, waypoints, model
controlAnimation播放/暂停动画entityId, action
removeAnimation删除动画实体entityId
listAnimations列出活跃动画
updateAnimationPath更新路径可视属性entityId, show, width, color
trackEntity相机追踪实体entityId
controlClock配置时钟startTime, stopTime, multiplier
setGlobeLighting地球光照控制enableLighting, enableFog

3D 场景

命令描述关键参数
load3dTiles加载 3D TileseturlionAssetId, name, maximumScreenSpaceError
loadTerrain设置地形提供者url, provider
loadImageryService添加影像图层url/serviceTypeionAssetId, name
loadCzml加载 CZML 时间动态数据dataurl, name
loadKml加载 KML/KMZ 数据dataurl, name

交互

命令描述关键参数
screenshot截取当前视图width, height, format
highlight高亮要素layerId, featureId, color
measure测量距离或面积type, coordinates

其他

命令描述关键参数
playTrajectory沿路径播放动画positions, duration, loop
addHeatmap创建热力图可视化points, name, radius, gradient

场景

命令描述关键参数
setSceneOptions配置场景环境fogEnabled, shadowsEnabled, sunShow, backgroundColor
setPostProcess配置后处理效果bloom, ambientOcclusion, fxaa

两种调用方式

方式一:类型安全方法

typescript
const result = await bridge.flyTo({
  longitude: 116.4,
  latitude: 39.9,
  height: 5000,
  duration: 2,
})

方式二:JSON 命令分发

typescript
const result = await bridge.execute({
  action: 'flyTo',
  params: {
    longitude: 116.4,
    latitude: 39.9,
    height: 5000,
    duration: 2,
  },
})

事件

typescript
bridge.on('layerAdded', (layer) => console.log('图层已添加:', layer))
bridge.on('layerRemoved', (layerId) => console.log('已移除:', layerId))
bridge.on('error', (err) => console.error('Bridge 错误:', err))

TypeScript 类型

typescript
import type {
  BridgeCommand,
  BridgeResult,
  FlyToParams,
  SetViewParams,
  AddGeoJsonLayerParams,
  AddHeatmapParams,
  Load3dTilesParams,
  PlayTrajectoryParams,
  LayerInfo,
  HighlightParams,
  // 相机
  LookAtTransformParams,
  StartOrbitParams,
  SetCameraOptionsParams,
  // 扩展实体类型
  AddBillboardParams,
  AddBoxParams,
  AddCorridorParams,
  AddCylinderParams,
  AddEllipseParams,
  AddRectangleParams,
  AddWallParams,
  MaterialSpec,
  MaterialInput,
  OrientationInput,
  PositionDegrees,
  // 动画
  CreateAnimationParams,
  ControlAnimationParams,
  RemoveAnimationParams,
  UpdateAnimationPathParams,
  TrackEntityParams,
  ControlClockParams,
  SetGlobeLightingParams,
  AnimationWaypoint,
  AnimationInfo,
  // 图层 Schema 与样式
  GetLayerSchemaParams,
  LayerSchemaResult,
  LayerSchemaField,
  UpdateLayerStyleParams,
  // 场景
  SetSceneOptionsParams,
  SetPostProcessParams,
  // 数据格式
  LoadCzmlParams,
  LoadKmlParams,
  // 交互
  MeasureParams,
} from 'cesium-mcp-bridge'

Released under the MIT License.