JSAPI Three API Reference
    正在准备搜索索引...

    类 RenderingLabel

    全局标签类,可通过此类的API添加和移除标签
    该类会随EngineRendering的初始化自动实例化,不需要开发者手动执行初始化调用,通过engine.rendering.label访问

    // 添加一个简单的文本标签
    engine.rendering.label.add({
    position: [116.404, 39.915, 0],
    text: '北京市',
    textSize: 14,
    textFillStyle: '#ffffff',
    });

    // 添加一个图标标签
    engine.rendering.label.add({
    position: [116.404, 39.915, 0],
    mapSrc: 'marker.png',
    width: 32,
    height: 32,
    });

    // 添加一个图文组合标签
    engine.rendering.label.add({
    position: [116.404, 39.915, 0],
    text: '北京市',
    mapSrc: 'marker.png',
    width: 32,
    height: 32,
    collision: true, // 支持碰撞检测
    textAnchor: 'left', // 图标在文字左边
    });
    索引

    方法

    • 添加单个标签

      参数

      • label: {
            collision?: boolean;
            flat?: boolean;
            height?: number;
            mapSrc?: string;
            position: number[];
            text?: string;
            textAnchor?: string;
            textFillStyle?: string;
            textSize?: number;
            textStrokeStyle?: string;
            textStrokeWidth?: number;
            width?: number;
        }

        标签配置

        • 可选collision?: boolean

          是否启用碰撞检测

        • 可选flat?: boolean

          是否贴地

        • 可选height?: number

          图标高度(像素)

        • 可选mapSrc?: string

          图标URL

        • position: number[]

          标签位置 [经度, 纬度, 高度]

        • 可选text?: string

          标签文本

        • 可选textAnchor?: string

          文字锚点位置

        • 可选textFillStyle?: string

          文字颜色

        • 可选textSize?: number

          文字大小(像素)

        • 可选textStrokeStyle?: string

          文字描边颜色

        • 可选textStrokeWidth?: number

          文字描边宽度

        • 可选width?: number

          图标宽度(像素)

      返回 DataItem

      返回添加的标签项

      const label = engine.rendering.label.add({
      position: [116.404, 39.915, 0],
      text: '北京市',
      textSize: 16,
      textFillStyle: '#ffffff',
      textStrokeStyle: '#000000',
      textStrokeWidth: 2,
      textAnchor: 'bottom',
      collision: true,
      flat: false
      });
    • 移除单个标签

      参数

      返回 void

      const label = engine.rendering.label.add({
      position: [116.404, 39.915, 0],
      text: '北京市'
      });

      // 稍后移除该标签
      engine.rendering.label.removeLabel(label);