对arcGis动态渲染标记点优化

摘要:
importReactfrom'反应';import'./索引。小于';从'contexts/map'导入{mapContext};从“td”导入{复选框};importesriConfigfrom'gisConfig/esri。配置';从“sri-loader”导入sri-loader;进口站
import React from 'react';
import './index.less';
import { mapContext } from 'contexts/map';
import { Checkbox } from 'antd';
import esriConfig from 'gisConfig/esri.config';
import esriLoader from 'esri-loader';
import stations from './station';

const stationOptions = [
    { label: '雨量站', value: '0' },
    { label: '水位站', value: '1' },
    { label: '水质站', value: '2' },
];
const { arcgisOption } = esriConfig;
const GraphicLayer = ['rainLayer', 'waterLevelLayer', 'waterQualityLayer'];
const varName = ['rainGraphicLayer', 'waterLevelGraphicLayer', 'waterQualityGraphicLayer'];
export default class CheckLayer extends React.Component {
    mapView;
    map;
    popContent;
    constructor(props) {
        super(props);
    }
    static contextType = mapContext;
    state = {
        // 当前展示的测站类别
        currentStationSttp: ['0', '1', '2'],
        isClickTools: false,
        popupVisible: false,
        stationData: [],
    };

    rainGraphicLayer;
    waterLevelGraphicLayer;
    waterQualityGraphicLayer;

    componentDidMount() {
        this.mapView = this.context.mapView;
        this.map = this.context.map;
        PubSub.subscribe('isModalOpen', (msg: any, data: any) => {
            const item = { msg, data };
            this.setState({
                isClickTools: item.data.isClickTools,
            });
        });
        esriLoader
            .loadModules(['esri/Graphic', 'esri/layers/GraphicsLayer'], arcgisOption)
            .then(([Graphic, GraphicsLayer]) => {
                //雨量图层
                // this.rainGraphicLayer = this.map.findLayerById('rainLayer');
                // if (this.rainGraphicLayer) {
                //     this.map.remove(this.rainGraphicLayer);
                // }
                // const rainGraphicLayer = new GraphicsLayer({
                //     id: 'rainLayer',
                // });
                // this.map.add(rainGraphicLayer, 150);
                // this.rainGraphicLayer.removeAll();
                GraphicLayer.map((item, index) => {
                    const graphicsLayer = new GraphicsLayer({
                        id: item,
                    });
                    this.map.add(graphicsLayer, 150 + index);
                });

                //水位图层
                // this.waterLevelGraphicLayer = this.map.findLayerById('waterLevelLayer');
                // if (this.waterLevelGraphicLayer) {
                //     this.map.remove(this.waterLevelGraphicLayer);
                // }
                // const waterLevelGraphicLayer = new GraphicsLayer({
                //     id: 'waterLevelLayer',
                // });
                // this.map.add(waterLevelGraphicLayer, 151);
                // this.waterLevelGraphicLayer.removeAll();
                //水质图层
                // this.waterQualityGraphicLayer = this.map.findLayerById('waterQualityLayer');
                // if (this.waterQualityGraphicLayer) {
                //     this.map.remove(this.waterQualityGraphicLayer);
                // }
                // const waterQualityGraphicLayer = new GraphicsLayer({
                //     id: 'waterQualityLayer',
                // });
                // this.map.add(waterQualityGraphicLayer, 152);
                //  this.waterQualityGraphicLayer.removeAll();

                stations.forEach((item) => {
                    let imgPath = '';
                    switch (item.type) {
                        case '0':
                            imgPath = require(`@assets/images/rainfall_station_default.png`);
                            break;
                        case '1': {
                            if (item.isWarn === '1') {
                                imgPath = require(`@assets/images/ground_water_station_default_warn.png`);
                            } else {
                                imgPath = require(`@assets/images/ground_water_station_default.png`);
                            }
                            break;
                        }
                        case '2':
                            imgPath = require(`@assets/images/spring_station_default.png`);
                            break;
                        default:
                            break;
                    }

                    const symbol = {
                        type: 'picture-marker',
                        url: imgPath,
                         '72px',
                        height: '88px',
                    };

                    const point = {
                        type: 'point',
                        longitude: item.x,
                        latitude: item.y,
                    };
                    const graphic = new Graphic({
                        geometry: point,
                        symbol: symbol,
                        attributes: item,
                        popupTemplate: {
                            title: '{typeName}',
                            content: this.popContent,
                        },
                    });

                    const rainGraphic = this.map.findLayerById(GraphicLayer[item.type]);
                    rainGraphic.add(graphic);
                    // switch (item.type) {
                    //     case '0':
                    //          rainGraphicLayer.add(graphic);
                    //         break;
                    //     case '1':
                    //         waterLevelGraphicLayer.add(graphic);
                    //         break;
                    //     case '2':
                    //         waterQualityGraphicLayer.add(graphic);
                    //         break;
                    //     default:
                    //         break;
                    // }
                });
                this.mapView.popup.dockOptions = {
                    buttonEnabled: false,
                };
                this.mapView.popup.collapseEnabled = false;
                this.mapView.on('click', (event) => {
                    PubSub.publish('openPopup', {
                        isOpen: false,
                    });
                    this.mapView.hitTest(event).then((response) => {
                        if (response.results.length) {
                            // 获取每个图形上的ID
                            const attributesData = response.results[0].graphic.attributes;
                            // const graphicRes = response.results.filter((result) => {
                            //     return (
                            //         result.graphic.layer === rainGraphicLayer ||
                            //         result.graphic.layer === waterLevelGraphicLayer ||
                            //         result.graphic.layer === waterQualityGraphicLayer
                            //     );
                            // });
                            // if (graphicRes.length) {
                            this.setState({
                                popupVisible: true,
                                stationData: attributesData ? [attributesData] : [],
                            });
                            PubSub.publish('openPopup', {
                                //  isOpen: this.state.isClickTools ? false : true,
                                isOpen: true,
                                title: '测站详情',
                                X: event.x,
                                Y: event.y,
                                //    type: graphicRes.attributes.type,
                                data: attributesData ? [attributesData] : [],
                            });
                            // }
                        }
                    });
                });

                // this.mapView.on('pointer-enter', (event) => {
                //     this.mapView.hitTest(event).then((response) => {
                //         if (response.results.length) {
                //             const graphic = response.results.filter((result) => {
                //                 return (
                //                     result.graphic.layer === this.rainGraphicLayer ||
                //                     result.graphic.layer === this.waterLevelGraphicLayer ||
                //                     result.graphic.layer === this.waterQualityGraphicLayer
                //                 );
                //             })[0].graphic;
                //             if (graphic) {
                //                 alert(graphic.attributes.name);
                //                 console.log(graphic);
                //             }
                //         }
                //     });
                // });
            });
    }

    componentWillUnmount() {
        this.mapView.popup.close();
        const rainGraphicLayer = this.map.findLayerById('rainLayer');
        this.map.remove(rainGraphicLayer);
        const waterLevelGraphicLayer = this.map.findLayerById('waterLevelLayer');
        this.map.remove(waterLevelGraphicLayer);
        const waterQualityGraphicLayer = this.map.findLayerById('waterQualityLayer');
        this.map.remove(waterQualityGraphicLayer);
        // this.map.remove(this.rainGraphicLayer);
    }
    handleRenderCheckout = () => {
        const children = [];
        stationOptions.map((item: any, index: number) =>
            children.push(
                <Checkbox
                    key={index}
                    value={item.value}
                    onClick={this.handleStepOnChange}
                    className={'my-station-checkbox-item'}>
                    {item.label}
                </Checkbox>
            )
        );
        return children;
    };
    /**
     * @description 处理要渲染的测站类别发生变化
     * @memberof GIS
     */
    handleStepOnChange = (sttps: any) => {
        this.setState({
            currentStationSttp: sttps,
        });

        this.map.findLayerById('rainLayer').visible = sttps.indexOf('0') >= 0 ? true : false;
        this.map.findLayerById('waterLevelLayer').visible = sttps.indexOf('1') >= 0 ? true : false;
        this.map.findLayerById('waterQualityLayer').visible = sttps.indexOf('2') >= 0 ? true : false;
    };
    // 查看更多
    seeMoreBtn = () => {
        PubSub.publish('openRightPopup', {
            isOpen: true,
        });
    };
    render() {
        const { stationData } = this.state;

        return (
            <>
                <div className="home-station-manager">
                    <Checkbox.Group
                        options={stationOptions}
                        className={'my-station-checkbox'}
                        value={this.state.currentStationSttp}
                        onChange={this.handleStepOnChange}>
                        {this.handleRenderCheckout()}
                    </Checkbox.Group>
                </div>
                <div
                    style={{ display: this.state.popupVisible ? 'block' : 'none' }}
                    ref={(node) => {
                        this.popContent = node;
                    }}
                    className="popup-container">
                    {/* <h4 className="title">{stationData.length && stationData[0].typeName}</h4> */}

                    <ul className="info-list">
                        <li>监测站:</li>
                        <li>{stationData.length && stationData[0].name}</li>
                    </ul>
                    <ul className="info-list">
                        <li>经度:</li>
                        <li>{stationData.length && stationData[0].x}</li>
                    </ul>
                    <ul className="info-list">
                        <li>纬度:</li>
                        <li>{stationData.length && stationData[0].y}</li>
                    </ul>
                    <a onClick={this.seeMoreBtn} className="seeMore">
                        查看更多
                    </a>
                </div>
            </>
        );
    }
}

免责声明:文章转载自《对arcGis动态渲染标记点优化》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇卡巴斯基简体中文版相关QA(ZT)Android JNI 学习(七):Accessing Fields Api下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

ArcGIS for Server 10.1中Web Adaptor的工作原理

  ArcGIS for Server 10.1的安装目录中,都会内置一个tomcat(Program Files\ArcGIS\Server\framework\runtime\tomcat\),无需单独的Web Server即可发布各种GIS服务(对于熟悉.NET的朋友来说,更省去单独安装和配置IIS的步骤);AGS应用程序的端口号也由之前版本的80(...

ArcGIS Server常见问题之二

同样摘自ESRI公司网站。 内容摘要 本指导描述了如何配置Windows XP SP2防火墙,使得ArcGIS Server能正常工作。为了完成下面的过程,必须安装Windows XP Service Pack 2,下面的步骤需要为ArcGIS Server配置Windows防火墙。 过程描述 当升级的Windows XP SP2,将安装Windows防火...

利用ARCGIS和LocaSpace Viewer无限制免费下载高清的谷歌卫星影像

卫星影像可以当做我们内业成图时的工作参考。目前市面上出现的几款好用的卫星图片下载工具,比如91卫图助手、bigemap等软件,都可以自定义导出坐标系及参数,但存在使用限制,比如限制了单次下载大小或者每日下载大小等。 也有无限制下载卫星地图的软件,比如LocaSpace Viewer,但是该软件最终导出只能是WGS84坐标系下的卫星影像,无法直接导出北京5...

libpcap编程实例

1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <pcap.h> 4 #include <errno.h> 5 #include <sys/socket.h> 6 #include <netinet/in...

Egg.js 实现向服务器上传图片

1.安装时间处理 及 压缩 模块 yarn add silly-datetime pump 2.文件保存路径 config/config.default.js config.uploadDir = 'app/public/avatar/upload'; 3.创建tools serviceapp/service/tools.js 'use strict';...

ModelContext模型上下文

usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Web;   namespaceTeamService.Data {     publicclassModelContextStatus     {         publicconstintDISAB...