addPolyline
Draw lines or paths on a 3D globe by specifying coordinates, color, width, and ground clamping. Returns the created entity ID for further manipulation.
Instructions
在地图上添加折线(路径、线段),返回 entityId
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coordinates | Yes | 折线坐标数组 [[lon, lat, height?], ...] | |
| color | No | 线条颜色(CSS 格式) | #3B82F6 |
| width | No | 线条宽度(像素) | |
| clampToGround | No | 是否贴地 | |
| label | No | 折线标注文本 |
Implementation Reference
- The 'addPolyline' handler implementation which processes parameters and adds a polyline entity to the Cesium viewer.
export function addPolyline(viewer: Cesium.Viewer, params: AddPolylineParams): Cesium.Entity { const { coordinates, color = '#3B82F6', width = 3, clampToGround = true, label } = params const cesiumColor = parseColor(color) const positions = coordinates.map(c => { validateCoordinate(c[0]!, c[1]!, c[2]) return Cesium.Cartesian3.fromDegrees(c[0]!, c[1]!, c[2] ?? 0) }) // 取中点作为标签位置 const midIdx = Math.floor(positions.length / 2) return viewer.entities.add({ position: label ? positions[midIdx] : undefined, polyline: { positions, width, material: cesiumColor, clampToGround, }, label: label ? { text: label, font: '13px sans-serif', fillColor: Cesium.Color.WHITE, outlineColor: Cesium.Color.BLACK, outlineWidth: 2, style: Cesium.LabelStyle.FILL_AND_OUTLINE, pixelOffset: new Cesium.Cartesian2(0, -12), verticalOrigin: Cesium.VerticalOrigin.BOTTOM, disableDepthTestDistance: Number.POSITIVE_INFINITY, } : undefined, }) }