addGeoJsonLayer
Add GeoJSON data layers to 3D maps with configurable styling options including colors, classifications, and choropleth rendering for points, lines, and polygons.
Instructions
添加 GeoJSON 图层到地图(支持 Point/Line/Polygon,可配置颜色/分级/分类渲染)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | 图层ID(不传则自动生成) | |
| name | No | 图层显示名称 | |
| data | Yes | GeoJSON FeatureCollection 对象 | |
| style | No | 样式配置(color, opacity, pointSize, choropleth, category) |
Implementation Reference
- The handler implementation for the addGeoJsonLayer tool, responsible for parsing parameters and interacting with the Cesium layer manager.
async addGeoJsonLayer(params: AddGeoJsonLayerParams): Promise<LayerInfo> { const { id, name, data, style, dataRefId } = params const layerId = id ?? `layer_${Date.now()}` const layerName = name ?? layerId const color = style?.color ?? '#3B82F6' const opacity = style?.opacity ?? 0.6 const pointSize = style?.pointSize ?? 10 this.removeLayer(layerId) const cesiumColor = parseColor(color).withAlpha(opacity) const ds = await Cesium.GeoJsonDataSource.load(data, { stroke: cesiumColor, fill: cesiumColor.withAlpha(opacity * 0.4), strokeWidth: 3, markerSize: 1, markerColor: cesiumColor, clampToGround: true, }) - Type definition for the parameters required by addGeoJsonLayer.
export interface AddGeoJsonLayerParams { id?: string name?: string data: Record<string, unknown> style?: LayerStyle dataRefId?: string labelField?: string labelStyle?: { font?: string fillColor?: string outlineColor?: string outlineWidth?: number pixelOffset?: [number, number] scale?: number } } - packages/cesium-mcp-runtime/src/index.ts:306-324 (registration)Registration and delegation of the addGeoJsonLayer command within the MCP runtime.
// — addGeoJsonLayer _registerTool( 'addGeoJsonLayer', '添加 GeoJSON 图层到地图(支持 Point/Line/Polygon,可配置颜色/分级/分类渲染)', { id: z.string().optional().describe('图层ID(不传则自动生成)'), name: z.string().optional().describe('图层显示名称'), data: z.record(z.unknown()).describe('GeoJSON FeatureCollection 对象'), style: z.record(z.unknown()).optional().describe('样式配置(color, opacity, pointSize, choropleth, category)'), }, async (params) => { const result = await sendToBrowser('addGeoJsonLayer', params) return { content: [{ type: 'text' as const, text: JSON.stringify(result ?? { success: true }) }] } }, ) // — addLabel _registerTool( 'addLabel',