antv中国地图展示

initMap() {

            chinaScene = new Scene({
                id: "mapChina",
                map: new Map({
                    style: "dark",
                    center: [102.99130938786305, 33.982243853450086],
                    zoom: 3.4,
                    pitch: 30,
                }),
                logoVisible: false,
            });
            chinaScene.on("loaded", () => {
                let lineDown, lineUp, textLayer;
                fetch(
                    // window.location.origin + window.location.pathname + "/json/china.json"
                    // this.chinaJson
                    'https://gw.alipayobjects.com/os/bmw-prod/ecd1aaac-44c0-4232-b66c-c0ced76d5c7d.json'
                    // "https://gw.alipayobjects.com/os/bmw-prod/d6da7ac1-8b4f-4a55-93ea-e81aa08f0cf3.json"
                )
                    .then((res) => res.json())
                    .then((data) => {
                        const texts = [];
                        // data.features.map((option) => {
                        this.chinaJson.features.map((option) => {

                            const { name, center } = option.properties;
                            const [lng, lat] = center;
                            texts.push({ name, lng, lat });
                            return "";
                        });
                        textLayer = new PointLayer({ zIndex: 9999 })
                            .source(texts, {
                                parser: {
                                    type: "json",
                                    x: "lng",
                                    y: "lat",
                                },
                            })
                            .shape("name", "text")
                            .size(16)
                            .color("#fff")
                            .style({
                                textAnchor: "center", // 文本相对锚点的位置 center|left|right|top|bottom|top-left
                                spacing: 2, // 字符间距
                                padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
                                stroke: "#0ff", // 描边颜色
                                strokeWidth: 0.2, // 描边宽度
                                raisingHeight: 100000,
                                textAllowOverlap: true,
                            });
                        chinaScene.addLayer(textLayer);
                        lineUp = new LineLayer({ zIndex: 1 })
                            .source(this.chinaJson)
                            .shape("line")
                            .color("#0DCCFF")
                            .size(1.2)
                            .style({
                                raisingHeight: 1010000,
                            });
                        chinaScene.addLayer(lineUp);
                        return "";
                    });
            });
            const layer = new PolygonLayer({
                // zIndex: -10
            })
                .source(this.chinaJson)
                .size(1000000)
                .shape('extrude')
                .color('#fff')
                .select({
                    color: "#ff0"
                })
                .style({
                    mapTexture: this.provinceImg, //如果想使用纹理贴图,shap必须为extrude
                    heightfixed: true,
                    pickLight: true,
                    sourceColor: "#333", //抬高高度的颜色
                    targetColor: "#fff",
                    opacity: 0.5,
                    // zIndex: -10
                });
            layer.on("click", e => {
                console.log(e, '---e1');
                this.openPopup()
                this.getProviceData(e.feature.properties.adcode)
            })

            // const layer = new PolygonLayer({
            //     // zIndex: 1,
            // })
            //     .source(this.chinaJson)
            //     .size(0)
            //     .shape('fill')
            //     .color('#c0c0c0')
            //     .select({
            //         color: "#ff0"
            //     })
            //     .style({
            //         mapTexture: this.provinceImg, //如果想使用纹理贴图,shap必须为extrude
            //         heightfixed: true,
            //         pickLight: true,
            //         sourceColor: "#333", //抬高高度的颜色
            //         targetColor: "#fff",
            //         opacity: 0.8,
            //         zIndex: -10
            //     });
            // layer.on("click", v => {
            //     console.log(v, '---e');
            // })


            const layerColor = new PolygonLayer({
                // zIndex: 9,
            })
                .source(this.chinaJson)
                .scale('density', {
                    type: 'quantile',
                })
                .size(100000)

                .color('density', this.mapcolor)
                .shape('extrude')
                .active(true)
                .select({
                    color: "#ff0"
                })
                .style({
                    opacity: 1,
                    // zIndex: 999999999999999,
                    // raisingHeight: 300000,
                    textAllowOverlap: true,
                    // mapTexture: this.provinceImg, //如果想使用纹理贴图,shap必须为extrude
                })

            // const layerColor = new PolygonLayer({
            //     // zIndex: 9,
            // })
            //     .source(this.chinaJson)
            //     .size(1000000)
            //     .shape('fill')
            //     .color('#fff')
            //     .select({
            //         color: "#ff0"
            //     })
            //     .scale('density', {
            //         type: 'quantile',
            //     })
            //     .style({
            //         // mapTexture: this.provinceImg, //如果想使用纹理贴图,shap必须为extrude
            //         heightfixed: true,
            //         pickLight: true,
            //         sourceColor: "#333", //抬高高度的颜色
            //         targetColor: "#fff",
            //         opacity: 0.5,
            //         // zIndex: -10
            //     });

            chinaScene.addLayer(layerColor);
            chinaScene.addLayer(layer);

            // layerColor.on("click", v => {
            //     console.log(v, '---e');

            // })
        },

 

### 实现雷达图 要在 React 应用中使用 AntV G2 绘制雷达图,需先安装 `@antv/g2` 和 `@antv/g2plot` 包。通过 npm 或 yarn 安装这些依赖项可以方便地集成到现有的 React 项目中[^1]。 ```bash npm install @antv/g2 @antv/g2plot ``` 创建一个新的组件来封装雷达图逻辑。此组件将在挂载时初始化图表并根据状态更新数据: ```jsx import { useEffect, useRef } from 'react'; import { Radar } from '@antv/g2plot'; const RadarChart = ({ data }) => { const chartRef = useRef(null); useEffect(() => { if (chartRef.current) { const radarPlot = new Radar(chartRef.current, { title: { visible: true, text: 'Radar Chart Example', }, forceFit: true, data, xField: 'item', // 数据中的字段名对应于类别轴上的标签 yField: 'score', // 数值轴对应的字段名称 seriesField: 'type' // 不同系列区分的颜色维度 }); radarPlot.render(); return () => { radarPlot.destroy(); }; } }, [data]); return <div ref={chartRef} style={{ width: '100%', height: '400px' }} />; }; ``` 上述代码定义了一个名为 `RadarChart` 的函数式组件,它接收一个 prop 属性 `data` 来传递给图表实例化配置对象。当组件首次渲染或接收到新的 props 更新时会触发副作用钩子重新绘制图表。 为了使该组件正常工作,在父级容器中调用时应提供适当的数据结构作为参数传入。例如: ```json [ {"item": "销售", "A": 87, "B": 56}, {"item": "管理", "A": 34, "B": 90}, ... ] ``` 这种格式允许每个条目代表一类指标,并且可以通过不同键(如 A、B)表示多个样本之间的对比关系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值