Skip to main content
Glama

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
NameRequiredDescriptionDefault
coordinatesYes折线坐标数组 [[lon, lat, height?], ...]
colorNo线条颜色(CSS 格式)#3B82F6
widthNo线条宽度(像素)
clampToGroundNo是否贴地
labelNo折线标注文本

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,
      })
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gaopengbin/cesium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server