addMarker
Add a labeled point marker to a 3D globe at specific coordinates. Specify longitude, latitude, label text, color, and size to create visual markers for spatial data visualization.
Instructions
在指定经纬度添加标注点,返回 layerId 供后续操作
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| longitude | Yes | 经度(-180 ~ 180) | |
| latitude | Yes | 纬度(-90 ~ 90) | |
| label | No | 标注文本 | |
| color | No | 标注颜色(CSS 格式) | #3B82F6 |
| size | No | 点大小(像素) | |
| id | No | 自定义图层ID(不传则自动生成) |
Implementation Reference
- The core implementation of the addMarker function which creates a Cesium entity with a point and optional label.
export function addMarker(viewer: Cesium.Viewer, params: AddMarkerParams): Cesium.Entity { const { longitude, latitude, label, color = '#3B82F6', size = 12 } = params validateCoordinate(longitude, latitude) const cesiumColor = parseColor(color) return viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(longitude, latitude), point: { pixelSize: size, color: cesiumColor, outlineColor: Cesium.Color.WHITE, outlineWidth: 1, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, disableDepthTestDistance: Number.POSITIVE_INFINITY, }, 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, -18), verticalOrigin: Cesium.VerticalOrigin.BOTTOM, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, disableDepthTestDistance: Number.POSITIVE_INFINITY, } : undefined, }) } - The TypeScript interface defining the parameters required for the addMarker tool.
export interface AddMarkerParams { longitude: number latitude: number label?: string color?: ColorInput size?: number }