Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
194 additions
and
18 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/l7plot/__tests__/unit/layers/icon-layer/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getLayerStyleAttribute } from '../../../helper/layer'; | ||
import { IconLayer } from '../../../../src/layers/icon-layer'; | ||
import { Source } from '../../../../src/types'; | ||
import { registerImages } from '../../../../src'; | ||
|
||
describe('icon layer', () => { | ||
const images = [ | ||
{ id: '02', image: 'https://gw.alipayobjects.com/zos/basement_prod/604b5e7f-309e-40db-b95b-4fac746c5153.svg' }, | ||
]; | ||
registerImages(images); | ||
|
||
const layer = new IconLayer({ | ||
source: new Source([], { parser: { type: 'json', x: 'x', y: 'y' } }), | ||
size: 12, | ||
shape: '02', | ||
color: '#fff', | ||
style: { opacity: 1, strokeWidth: 1, stroke: 'red' }, | ||
state: { active: true, select: true }, | ||
}); | ||
|
||
it('type', () => { | ||
expect(layer.type).toBe('iconLayer'); | ||
expect(layer.layer.type).toBe('PointLayer'); | ||
}); | ||
|
||
it('size', () => { | ||
expect(getLayerStyleAttribute(layer.layer['pendingStyleAttributes'], 'size')).toEqual({ | ||
attributeName: 'size', | ||
attributeField: 12, | ||
}); | ||
}); | ||
|
||
it('color', () => { | ||
expect(getLayerStyleAttribute(layer.layer['pendingStyleAttributes'], 'color')).toEqual({ | ||
attributeName: 'color', | ||
attributeField: '#fff', | ||
}); | ||
}); | ||
|
||
it('shape', () => { | ||
expect(getLayerStyleAttribute(layer.layer['pendingStyleAttributes'], 'shape')).toEqual({ | ||
attributeName: 'shape', | ||
attributeField: '02', | ||
}); | ||
}); | ||
|
||
it('style', () => { | ||
expect(layer.layer['rawConfig']).toMatchObject({ opacity: 1, strokeWidth: 1, stroke: 'red' }); | ||
}); | ||
|
||
it('state', () => { | ||
expect(layer.layer['needUpdateConfig'].enableHighlight).toBeTruthy(); | ||
expect(layer.layer['needUpdateConfig'].enableSelect).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { deepAssign } from '../../utils'; | ||
import { DotLayer } from '../dot-layer'; | ||
import { IconLayerOptions } from './types'; | ||
|
||
export type { IconLayerOptions }; | ||
|
||
export class IconLayer extends DotLayer<IconLayerOptions> { | ||
/** | ||
* 图层类型 | ||
*/ | ||
public type = DotLayer.LayerType.IconLayer; | ||
|
||
/** | ||
* 获取默认配置 | ||
*/ | ||
public getDefaultOptions(): Partial<IconLayerOptions> { | ||
return deepAssign({}, DotLayer.DefaultOptions, { | ||
color: undefined, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ShapeAttr, Source, SourceOptions } from '../../types'; | ||
import { DotLayerOptions } from '../dot-layer/types'; | ||
|
||
export interface IconLayerOptions extends DotLayerOptions { | ||
/** | ||
* 具体的数据 | ||
*/ | ||
source: SourceOptions | Source; | ||
/** | ||
* 图标形状 | ||
*/ | ||
shape: ShapeAttr<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: IconLayer | ||
order: 2 | ||
--- | ||
|
||
`markdown:docs/api/layers/icon-layer.zh.md` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
title: 图标图层 - IconLayer | ||
order: 2 | ||
--- | ||
|
||
`IconLayer` 继承基类 [PlotLayer](/zh/docs/api/layers/plot-layer)。 | ||
|
||
## 一、配置 | ||
|
||
`markdown:docs/common/layers/dot-layer/source.zh.md` | ||
|
||
### `options.`shape | ||
|
||
`string` required | ||
|
||
图标形状,使用方法如下: | ||
|
||
1. 注册图标 | ||
|
||
```js | ||
const images = [ | ||
{ id: '01', image: 'https://gw.alipayobjects.com/zos/basement_prod/604b5e7f-309e-40db-b95b-4fac746c5153.svg' }, | ||
{ id: '02', image: 'https://gw.alipayobjects.com/zos/basement_prod/30580bc9-506f-4438-8c1a-744e082054ec.svg' }, | ||
{ id: '03', image: 'https://gw.alipayobjects.com/zos/basement_prod/7aa1f460-9f9f-499f-afdf-13424aa26bbf.svg' }, | ||
]; | ||
registerImages(images); | ||
``` | ||
|
||
2. 使用注册图标 | ||
|
||
```js | ||
{ | ||
source: { | ||
data: [{ lng: 104.101, lat: 30.649, s: '01', t: 21, n: 'chengdu' }], | ||
parser: { type: 'json', x: 'lng', y: 'lat' } | ||
}, | ||
shape: 's', | ||
} | ||
``` | ||
|
||
自定义映射图标 | ||
|
||
```js | ||
{ | ||
shape: { | ||
field: 't', | ||
value: ({ t }) => { | ||
return t > 20 ? '01': '02' | ||
} | ||
} | ||
} | ||
``` | ||
|
||
`markdown:docs/common/layers/dot-layer/shape.zh.md` | ||
|
||
`markdown:docs/common/attribute/color.zh.md` | ||
|
||
`markdown:docs/common/layers/dot-layer/size.zh.md` | ||
|
||
`markdown:docs/common/layers/dot-layer/style.zh.md` | ||
|
||
`markdown:docs/common/attribute/state.zh.md` | ||
|
||
## 二、属性 | ||
|
||
继承 [PlotLayer 属性](/zh/docs/api/layers/plot-layer#二、属性)。 | ||
|
||
## 三、方法 | ||
|
||
继承 [PlotLayer 方法](/zh/docs/api/layers/plot-layer#三、方法)。 | ||
|
||
## 四、事件 | ||
|
||
继承 [PlotLayer 方法](/zh/docs/api/layers/plot-layer#四、事件)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters