From 47079b9b0bda42d97a844ac47ee24bcc928a16ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=81=86=E4=B8=80?= Date: Tue, 18 Feb 2020 23:09:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96react=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=96=B0=E5=A2=9EFilter=E7=AD=89=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react/src/component/Layer.ts | 8 ++++++-- .../src/component/LayerAttribute/Active.tsx | 17 ++++++++++++++++ .../src/component/LayerAttribute/Color.tsx | 2 +- .../src/component/LayerAttribute/Filter.tsx | 18 +++++++++++++++++ .../src/component/LayerAttribute/Layer.tsx | 16 ++++++++++----- .../src/component/LayerAttribute/Shape.tsx | 2 +- .../src/component/LayerAttribute/Size.tsx | 2 +- .../src/component/LayerAttribute/Source.tsx | 13 +++++++++--- .../src/component/LayerAttribute/index.ts | 20 +++++++++++++++---- packages/react/src/component/LayerContext.tsx | 7 +++++++ packages/react/src/component/LayerEvent.tsx | 18 +++++++++++++++++ packages/react/src/component/Scene.tsx | 19 +++++++++++++++--- packages/react/src/component/SceneContext.tsx | 4 ++-- packages/react/src/index.ts | 8 +++++--- 14 files changed, 129 insertions(+), 25 deletions(-) create mode 100644 packages/react/src/component/LayerAttribute/Active.tsx create mode 100644 packages/react/src/component/LayerAttribute/Filter.tsx create mode 100644 packages/react/src/component/LayerContext.tsx create mode 100644 packages/react/src/component/LayerEvent.tsx diff --git a/packages/react/src/component/Layer.ts b/packages/react/src/component/Layer.ts index 4deebbc545..fced1febd4 100644 --- a/packages/react/src/component/Layer.ts +++ b/packages/react/src/component/Layer.ts @@ -2,7 +2,9 @@ import * as React from 'react'; import { ILayerProps } from './LayerAttribute'; import BaseLayer from './LayerAttribute/Layer'; -const PolygonLayer = React.memo(function Layer(props: ILayerProps) { +const PolygonLayer = React.memo(function Layer( + props: ILayerProps & { children?: any }, +) { return BaseLayer('polygonLayer', props); }); @@ -10,7 +12,9 @@ const LineLayer = React.memo(function Layer(props: ILayerProps) { return BaseLayer('polygonLayer', props); }); -const PointLayer = React.memo(function Layer(props: ILayerProps) { +const PointLayer = React.memo(function Layer( + props: ILayerProps & { children?: any }, +) { return BaseLayer('pointLayer', props); }); diff --git a/packages/react/src/component/LayerAttribute/Active.tsx b/packages/react/src/component/LayerAttribute/Active.tsx new file mode 100644 index 0000000000..92aafb75e8 --- /dev/null +++ b/packages/react/src/component/LayerAttribute/Active.tsx @@ -0,0 +1,17 @@ +import { IActiveOption, ILayer } from '@antv/l7'; +import * as React from 'react'; + +const { useEffect } = React; +interface ILayerProps { + layer: ILayer; + active: { + option: IActiveOption | boolean; + }; +} +export default React.memo(function Chart(props: ILayerProps) { + const { layer, active } = props; + useEffect(() => { + layer.active(active.option); + }, [active, layer]); + return null; +}); diff --git a/packages/react/src/component/LayerAttribute/Color.tsx b/packages/react/src/component/LayerAttribute/Color.tsx index f61cb9d161..98a78dfccc 100644 --- a/packages/react/src/component/LayerAttribute/Color.tsx +++ b/packages/react/src/component/LayerAttribute/Color.tsx @@ -13,6 +13,6 @@ export default React.memo(function Chart(props: ILayerProps) { color.field ? layer.color(color.field as StyleAttrField, color.values) : layer.color(color.value as StyleAttrField); - }, [color.value, color.field, JSON.stringify(color.values)]); + }, [color.value, color.field, JSON.stringify(color.values), color.values]); return null; }); diff --git a/packages/react/src/component/LayerAttribute/Filter.tsx b/packages/react/src/component/LayerAttribute/Filter.tsx new file mode 100644 index 0000000000..fe1854aded --- /dev/null +++ b/packages/react/src/component/LayerAttribute/Filter.tsx @@ -0,0 +1,18 @@ +import { ILayer, StyleAttrField } from '@antv/l7'; +import * as React from 'react'; +import { IAttributeOptions } from '.'; + +const { useEffect } = React; +interface ILayerProps { + layer: ILayer; + filter: Partial; +} +export default React.memo(function Chart(props: ILayerProps) { + const { layer, filter } = props; + useEffect(() => { + if (filter.field) { + layer.filter(filter.field as string, filter.values as StyleAttrField); + } + }, [filter.field, JSON.stringify(filter.values), filter.values]); + return null; +}); diff --git a/packages/react/src/component/LayerAttribute/Layer.tsx b/packages/react/src/component/LayerAttribute/Layer.tsx index 983a69596d..bc6e89c925 100644 --- a/packages/react/src/component/LayerAttribute/Layer.tsx +++ b/packages/react/src/component/LayerAttribute/Layer.tsx @@ -1,12 +1,14 @@ import { ILayer, LineLayer, PointLayer, PolygonLayer, Scene } from '@antv/l7'; import * as React from 'react'; +import { LayerContext } from '../LayerContext'; import { useSceneValue } from '../SceneContext'; -import { Color, ILayerProps, Scales, Shape, Size, Source, Style } from './'; + +import { Active, Color, Filter, ILayerProps, Scales, Shape, Size, Source, Style } from '.'; const { useEffect, useState } = React; -export default function BaseLayer(type: string, props: ILayerProps) { - const { source, color, shape, style, size, scales, options } = props; +export default function BaseLayer(type: string, props: ILayerProps & { children?: any }) { + const { source, color, shape, style, size, scales, active, filter, options } = props; const mapScene = (useSceneValue() as unknown) as Scene; const [layer, setLayer] = useState(); if (!layer) { @@ -39,13 +41,17 @@ export default function BaseLayer(type: string, props: ILayerProps) { } }); return ( - <> + {scales && } {size && } {style &&