-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: wb-yzg904416@antgroup.com <wb-yzg904416@antgroup.com> Co-authored-by: yunji <yunji.me@outlook.com>
- Loading branch information
1 parent
f22e77a
commit d482ef0
Showing
8 changed files
with
385 additions
and
14 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/composite-layers/src/composite-layers/choropleth-layer/helper.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,68 @@ | ||
import { IParserCfg } from '@antv/l7'; | ||
import { ChoroplethLayerOptions, LabelPosition } from './types'; | ||
import { SourceOptions } from '../../types/attr'; | ||
import { ISource } from '../../types/common'; | ||
import { isBoolean, isUndefined } from '@antv/util'; | ||
import { getLabelLayerOptions as getLabelOptions } from '../common/label-layer'; | ||
|
||
/** | ||
* 是否开启自定义标注图层坐标字段 | ||
*/ | ||
export const isLabelPosition = ( | ||
position?: LabelPosition | ||
): position is Pick<IParserCfg, 'x' | 'y' | 'coordinates' | 'geometry'> => { | ||
if (isUndefined(position) || isBoolean(position)) return false; | ||
|
||
if ( | ||
isUndefined(position['coordinates']) && | ||
(isUndefined(position['x']) || isUndefined(position['y'])) && | ||
isUndefined(position['geometry']) | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
/** | ||
* 开启自定义标注图层坐标字段,解析标注图层 source | ||
*/ | ||
export const parserLabeSourceData = ( | ||
source: ISource, | ||
labelOptions: ChoroplethLayerOptions['label'] | ||
): ISource | SourceOptions => { | ||
const position = labelOptions?.position; | ||
if (!isLabelPosition(position)) { | ||
return source; | ||
} | ||
|
||
// TODO: type 为 json 有效,为 geojson 会自动计算中心点,指定坐标字段无效 | ||
const type = source.parser.type; | ||
const transforms = source.transforms; | ||
const originData = source['originData']; | ||
const sourceOptions = { data: originData, transforms }; | ||
|
||
if (position['coordinates']) { | ||
const coordinates = position['coordinates']; | ||
sourceOptions['parser'] = { type, coordinates }; | ||
} else if (position['x'] && position['y']) { | ||
const x = position['x']; | ||
const y = position['y']; | ||
sourceOptions['parser'] = { type, x, y }; | ||
} else if (position['geometry']) { | ||
const geometry = position['geometry']; | ||
sourceOptions['parser'] = { type, geometry }; | ||
} | ||
|
||
return sourceOptions; | ||
}; | ||
|
||
/** | ||
* 获取标注图层配置项 | ||
*/ | ||
export const getLabelLayerOptions = (options: ChoroplethLayerOptions, source: ISource) => { | ||
return { | ||
...getLabelOptions<ChoroplethLayerOptions>(options), | ||
source: parserLabeSourceData(source, options.label), | ||
}; | ||
}; |
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
Oops, something went wrong.