Skip to content

text

Point layers support drawing text labels.

案例

accomplish

Let’s introduce how to draw a common text annotation map.

import { Scene, PointLayer } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';

const scene = new Scene({
  id: 'map',
  map: new GaodeMap({
    center: [110, 36],
    style: 'light',
    zoom: 3,
  }),
});
scene.on('loaded', () => {
  fetch('https://gw.alipayobjects.com/os/rmsportal/oVTMqfzuuRFKiDwhPSFL.json')
    .then((res) => res.json())
    .then((data) => {
      const pointLayer = new PointLayer({})
        .source(data.list, {
          parser: {
            type: 'json',
            x: 'j',
            y: 'w',
          },
        })
        .shape('m', 'text')
        .size(12)
        .color('w', ['#0e0030', '#0e0030', '#0e0030'])
        .style({
          textAnchor: 'center', // The position of the text relative to the anchor point center|left|right|top|bottom|top-left
          textOffset: [0, 0], // Offset of text relative to anchor point [horizontal, vertical]
          spacing: 2, // character spacing
          padding: [1, 1], // Text bounding box padding [horizontal, vertical], affects the collision detection results and prevents adjacent texts from being too close
          stroke: '#ffffff', // stroke color
          strokeWidth: 0.3, // Stroke width
        });
      scene.addLayer(pointLayer);
    });
});

shape(field: name: shapeType: ‘text’): ILayer

  • fieldLabeled field name.
  • shapeTypeThe default value istext。
layer.shape('name', 'text');

style

  • textAnchor stringThe position of the text relative to the anchor point'right' | 'top-right' | 'left' | 'bottom-right' | 'left' | 'top-left' | 'bottom-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'top' | 'top-right' | 'top-left' | 'center';
  • padding:numberText bounding box padding [horizontal, vertical], affects the collision detection results and prevents adjacent text from being too close
  • spacing: number text spacing
  • stroke:string; stroke color
  • strokeWidth numberstroke width
  • strokeOpacity numberstroke transparency
  • fontWeight stringFont weight
  • fontFamily stringFont size
  • textOffset [number, number]text offset
  • textAllowOverlap:booleanWhether to allow text masking
  • raisingHeight sets the raising height of the text label
© Copyright 2026 Ant Group Co., Ltd..备案号:京ICP备15032932号-38
Site search
Documentation and examplesType to start searching

Search documentation, APIs, and examples

↑↓Select↵OpenEscClose