2020-08-10 10:44:28 +08:00
|
|
|
---
|
|
|
|
title: 文本标注
|
|
|
|
order: 4
|
|
|
|
---
|
2021-12-29 17:08:46 +08:00
|
|
|
|
2020-11-21 03:51:18 +08:00
|
|
|
`markdown:docs/common/style.md`
|
2020-08-20 17:09:45 +08:00
|
|
|
|
2020-08-10 10:44:28 +08:00
|
|
|
为图层添加文本标注
|
|
|
|
|
|
|
|
## 使用
|
|
|
|
|
|
|
|
地图标注需要添加一个新的图层的实现
|
|
|
|
|
2022-01-05 12:15:27 +08:00
|
|
|
```javascript
|
|
|
|
import { PointLayer } from '@antv/l7';
|
|
|
|
```
|
|
|
|
|
2022-01-06 14:30:29 +08:00
|
|
|
<img width="60%" style="display: block;margin: 0 auto;" alt="案例" src='https://gw.alipayobjects.com/mdn/antv_site/afts/img/A*7blvQ4v7Q1UAAAAAAAAAAABkARQnAQ'>
|
2022-01-05 12:15:27 +08:00
|
|
|
|
2020-08-10 10:44:28 +08:00
|
|
|
### shape
|
|
|
|
|
|
|
|
- field 标注的字段名称
|
|
|
|
- shapeType 'text'
|
|
|
|
|
|
|
|
```javascript
|
2020-08-20 17:09:45 +08:00
|
|
|
layer.shape('name', 'text');
|
2020-08-10 10:44:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### style
|
|
|
|
|
2020-08-20 17:09:45 +08:00
|
|
|
- opacity `number`
|
|
|
|
- textAnchor `string` 文本相对锚点的位置
|
|
|
|
`'right' | 'top-right' | 'left' | 'bottom-right' | 'left' | 'top-left' | 'bottom-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'top' | 'top-right' | 'top-left' | 'center';`
|
2020-11-19 10:03:54 +08:00
|
|
|
- padding: `number` 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
|
|
|
|
- spacing: number 文本间隔
|
2020-08-10 10:44:28 +08:00
|
|
|
- stroke: `string`; 描边颜色
|
|
|
|
- strokeWidth `number` 描边宽度
|
|
|
|
- strokeOpacity `number` 描边透明度
|
|
|
|
- fontWeight `string` 字体粗细
|
|
|
|
- fontFamily `string` 字号
|
2020-08-20 17:09:45 +08:00
|
|
|
- textOffset `[number, number]` 文本偏移量
|
2020-08-10 10:44:28 +08:00
|
|
|
- textAllowOverlap: `boolean` 是否允许文字遮盖
|
|
|
|
|
2022-01-05 12:15:27 +08:00
|
|
|
[在线案例](../../../examples/point/text#point_text)
|
2020-11-16 15:19:41 +08:00
|
|
|
|
|
|
|
`markdown:docs/common/layer/base.md`
|