antv-l7/docs/api/react/layer.zh.md

209 lines
3.5 KiB
Markdown
Raw Normal View History

2020-03-08 14:48:52 +08:00
---
title: Layer 组件
2020-03-08 17:31:56 +08:00
order: 2
2020-03-08 14:48:52 +08:00
---
2020-11-21 14:05:59 +08:00
2020-11-16 15:19:41 +08:00
`markdown:docs/common/style.md`
2020-11-17 10:59:32 +08:00
2020-03-11 21:35:11 +08:00
## Layer 类型
React 各个组件名称和 L7 名称保持一致
- PointLayer
- PolygonLayer
- LineLayer
- HeatmapLayer
- RasterLayer
- ImageLayer
- CityBuildingLayer
### 使用方式
```jsx
import { PointLayer } '@antv/l7-react';
```
2020-03-09 01:04:27 +08:00
## Layer Props
2020-11-21 14:05:59 +08:00
### options 图层 配置
<description> _layer options_ \_ **可选** </description>
2020-03-08 14:48:52 +08:00
2020-11-21 03:51:18 +08:00
`markdown:docs/common/layer/options.md`
2020-03-09 01:04:27 +08:00
2020-11-21 14:05:59 +08:00
### source 图层数据
2020-11-21 03:51:18 +08:00
<description> _sourceOption_ **必选** _default:_ `0`</description>
2020-03-08 14:48:52 +08:00
数据源配置项
2020-03-08 15:19:21 +08:00
2020-03-08 14:48:52 +08:00
- data 支持 geojson、csv、json
- parser 数据解析配置项
- transforms 数据处理配置项
2020-11-21 03:51:18 +08:00
```jsx
<PointLayer
source={{
data: [],
parser: {
2020-11-21 14:05:59 +08:00
type: 'geojson',
2020-11-21 03:51:18 +08:00
},
2020-11-21 14:05:59 +08:00
transforms: [],
}}
2020-11-21 03:51:18 +08:00
/>
```
2020-03-09 01:04:27 +08:00
2020-11-21 14:05:59 +08:00
### color 图层颜色
2020-11-21 03:51:18 +08:00
<description> _attributeOption_ **必选** _default:_ `0`</description>
### shape 图形形状
2020-11-21 14:05:59 +08:00
2020-11-21 03:51:18 +08:00
<description> _attributeOption_ **必选** _default:_ `0`</description>
### size 图形大小
<description> _attributeOption_ **必选** </description>
### select 选中高亮
2020-11-21 14:05:59 +08:00
2020-11-21 03:51:18 +08:00
<description> _interaction option_ **可选** </description>
### active 滑过高亮
2020-11-21 14:05:59 +08:00
2020-11-21 03:51:18 +08:00
<description> _interaction option_ **可选** </description>
### animate 动画
2020-11-21 14:05:59 +08:00
2020-11-21 03:51:18 +08:00
<description> _animate Option_ **可选** </description>
### style 样式
2020-11-21 14:05:59 +08:00
2020-11-21 03:51:18 +08:00
<description> _styleOption_ **可选** </description>
`markdown:docs/common/layer/layer_style.md`
2020-11-21 14:05:59 +08:00
### scale 度量
2020-11-21 03:51:18 +08:00
<description> _scale Option_ **可选** </description>
2020-03-09 01:04:27 +08:00
度量配置项
- values scaleCfg
**scaleCfg**
- key 为字段名 fieldname | attributeName
- value scale 配置项
```javascript
const scales = {
values: {
name: {
type: 'cat',
},
},
};
```
2020-11-21 03:51:18 +08:00
### onLayerLoaded 图层回调
2020-11-21 14:05:59 +08:00
2020-11-21 03:51:18 +08:00
<description> _Function_ **可选** </description>
获取图层对象方法
### attribute Option
color, size, shape 等图形映射通道,通过下面参数配置
- field 映射字段,如果是常量设置为 null
- values 映射值 支持 常量,数组,回调函数,如果 values 为数组或回调需要设置 field 字段
### scale Option
2020-03-09 01:04:27 +08:00
### interaction option
2020-03-11 21:35:11 +08:00
activeselect 配置项
2020-03-09 01:04:27 +08:00
**option**
- color 设置交互的颜色,指滑过或者选中的
2020-03-11 21:35:11 +08:00
```jsx
2020-11-21 03:51:18 +08:00
<PointLayer
active={{
2020-11-21 14:05:59 +08:00
option: {
color: 'red',
},
}}
2020-11-21 03:51:18 +08:00
/>
2020-03-11 21:35:11 +08:00
```
2020-11-21 03:51:18 +08:00
## 获取 layer 对象
2020-03-09 01:04:27 +08:00
2020-11-21 03:51:18 +08:00
### onLayerLoaded
2020-03-09 01:04:27 +08:00
回调函数获取 layer, scene 对象
2020-03-11 21:35:11 +08:00
```javascript
onLayerLoaded = (layer, scene) => {};
```
2020-03-09 01:04:27 +08:00
2020-11-21 03:51:18 +08:00
### Context API
2020-03-09 01:04:27 +08:00
```jsx
import { LayerContext } from '@antv/l7-react';
<LayerContext.Consumer>
{(layer, scene) => {
// use `scene` here
}}
</LayerContext.Consumer>;
```
2020-11-21 03:51:18 +08:00
## Layer 示例
2020-03-08 18:04:13 +08:00
2020-03-08 14:48:52 +08:00
```jsx
2020-03-08 15:19:21 +08:00
import { PolygonLayer } from '@antv/l7-react';
2020-03-08 14:48:52 +08:00
<PolygonLayer
key={'2'}
source={{
data,
}}
color={{
field: 'name',
2020-03-08 15:19:21 +08:00
values: ['#2E8AE6', '#69D1AB', '#DAF291', '#FFD591', '#FF7A45', '#CF1D49'],
2020-03-08 14:48:52 +08:00
}}
shape={{
values: 'fill',
}}
style={{
opacity: 1,
}}
2020-03-09 01:04:27 +08:00
active={{
option: {
color: 'red',
},
}}
2020-03-08 15:19:21 +08:00
/>;
2020-03-08 14:48:52 +08:00
```
2020-03-09 01:04:27 +08:00
## 子组件
### 事件组件
| prop name | Type | Default | Description |
| --------- | ---------- | ------- | ----------------------------------------- |
| type | `string` | `null` | 事件类型 [详情](../layer/layer/#鼠标事件) |
| handler | `Function` | `null` | layer 回调函数 |
### 示例
```jsx
import { LayerEvent, PolygonLayer } from 'l7-react';
<PolygonLayer>
<LayerEvent type="click" handler={() => {}} />
<LayerEvent type="mousemove" handler={() => {}} />
</PolygonLayer>;
```