From 34bb49f4877a4423443fd63f93c1650020615fec Mon Sep 17 00:00:00 2001 From: Lei OT Date: Fri, 27 Oct 2023 13:47:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5:=20=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E6=98=BE=E7=A4=BA=E5=9B=BD=E7=B1=8D=E4=B8=9A=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MapCountry.jsx | 109 ++++++++++++++++++++++++++++++++++ src/views/Home.jsx | 22 ++++++- 2 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 src/components/MapCountry.jsx diff --git a/src/components/MapCountry.jsx b/src/components/MapCountry.jsx new file mode 100644 index 0000000..e7fdce9 --- /dev/null +++ b/src/components/MapCountry.jsx @@ -0,0 +1,109 @@ +import { useContext, useState, useEffect, useMemo } from 'react'; +import { observer } from 'mobx-react'; +import { ChoroplethMap } from '@ant-design/maps'; +import { dataFieldAlias } from '../libs/ht'; +import { cloneDeep } from '../utils/commons'; + +export default observer((props) => { + const { dataSource, sourceField, valueField, ...extConfig } = props; + + const [mdataSource, setMdataSource] = useState([]); + useEffect(() => { + const dataMapped = (cloneDeep(dataSource) || []).reduce((r, v) => ({...r, + [(v.groupsLabel || '_').replace('(待删除)', '')]: v + }), {}); + if (dataMapped?.['中国']) { + dataMapped['中国'].groupsLabel = '中华人民共和国'; + } + setMdataSource(Object.values(dataMapped)); + return () => {}; + }, [dataSource, valueField]); + + const config = { + container: '#topC', + map: { + // type: 'amap', + type: 'mapbox', + // style: 'blank', + center: [120.19382669582967, 30.258134], + zoom: 3, + pitch: 0, + // scrollZoom: false, + // dragPan: false, + // zoomEnable: false, + // token: 'd78b5ba25a4699a1cb567b7a933e630b', // amap + }, + // geoArea: { + // url: 'https://gw.alipayobjects.com/os/alisis/geo-data-v0.1.2/choropleth-data', + // type: 'topojson', + // }, + source: { + data: mdataSource.filter((ele) => ele[sourceField]), + joinBy: { + geoField: 'name', + sourceField: sourceField || 'name', + }, + }, + autoFit: true, + color: { + field: valueField || 'value', + value: [ + '#001D70', + '#0047A5', + '#1A4397', + '#2555B7', + '#3165D1', + '#3D76DD', + '#467BE8', + '#6296FE', + '#7EA6F9', + '#98B7F7', + '#BDD0F8', + '#DDE6F7', + '#F2F5FC'].reverse(), + scale: { type: 'quantile' }, + }, + viewLevel: { + // level: 'country', + // adcode: '100000', + // granularity: 'province', + level: 'world', + adcode: 'all', + granularity: 'country', + }, + chinaBorder: false, + style: { + opacity: 1, + stroke: '#fff', + lineWidth: 0.6, + lineOpacity: 1, + }, + state: { + active: { + stroke: 'yellow', + lineWidth: 0.6, + // lineOpacity: 0.8, + }, + }, + label: { + visible: true, + field: 'name', + style: { + fill: '#000', + opacity: 0.8, + fontSize: 10, + stroke: '#fff', + strokeWidth: 1.5, + textAllowOverlap: false, + padding: [8, 8], + }, + }, + tooltip: { + items: ['name', { field: valueField, alias: dataFieldAlias[valueField].alias, customValue: (v) => dataFieldAlias[valueField].formatter(v) }], + }, + zoom: false, + legend: false, + }; + + return ; +}); diff --git a/src/views/Home.jsx b/src/views/Home.jsx index c0ab571..1cce101 100644 --- a/src/views/Home.jsx +++ b/src/views/Home.jsx @@ -8,6 +8,7 @@ import Bullet from '../components/BulletWithSort'; import Waterfall from '../components/Waterfall'; import MixTBWithKPI from './../components/MixTBWithKPI'; import Donut from './../components/Donut'; +import MapCountry from './../components/MapCountry'; import DataFieldRadio from '../components/DataFieldRadio'; import { datePartOptions } from './../components/DateGroupRadio/date'; import SearchForm from './../components/search/SearchForm'; @@ -18,7 +19,7 @@ import './home.css'; const topSeries = [ { key: 'dept', label: '小组', graphVisible: true }, { key: 'operator', label: '顾问', graphVisible: true }, - { key: 'country', label: '国籍', graphVisible: true }, + { key: 'country', label: '国籍', graphVisible: false }, { key: 'GuestGroupType', label: '客群类别', graphVisible: false }, { key: 'destination', label: '目的地', graphVisible: true }, ]; @@ -252,10 +253,10 @@ export default observer(() => { - + {topSeriesSet.map((item) => item.graphVisible ? ( - +

{item.label}

@@ -265,6 +266,21 @@ export default observer(() => { )}
+
+ + + +

国籍

+ + + +
+ +
+ +
+
+
); });