map/src/pages/BaseMap/LayerData/index.js

371 lines
17 KiB
JavaScript
Raw Normal View History

2023-08-30 13:55:59 +08:00
import React from 'react';
2024-06-17 17:06:46 +08:00
import { Tree, Button, Modal, Form, Input, Radio, message, Menu } from 'antd';
2023-08-30 13:55:59 +08:00
import {
DownOutlined,
EyeOutlined,
EyeInvisibleOutlined,
2024-06-17 17:06:46 +08:00
UnderlineOutlined,
UnorderedListOutlined,
2023-08-30 13:55:59 +08:00
} from '@ant-design/icons';
import SetLogoImagePath from './SetLogoImagePath'
2024-06-15 11:22:30 +08:00
import { createLayer, getBasicLayerMenuApi } from '../../../api';
2023-08-30 13:55:59 +08:00
import '../../../index.less';
2024-06-17 17:06:46 +08:00
import { label } from 'three/examples/jsm/nodes/Nodes.js';
2023-08-30 13:55:59 +08:00
class LayerData extends React.Component {
constructor () {
super ();
this.state = {
treeData: [],
2024-06-17 17:06:46 +08:00
menuData:[], //菜单数据
2023-08-30 13:55:59 +08:00
layerId: '',
2023-10-25 22:47:42 +08:00
isModalOpen: false,
addLayer: {
id: 0,
2024-04-02 22:57:35 +08:00
logoImageColor: 'gray',
2023-10-25 22:47:42 +08:00
logoImagePath: '',
name: '',
note: '',
},
2024-01-08 21:25:46 +08:00
selectLayerList: [],
2023-08-30 13:55:59 +08:00
}
}
2024-06-17 17:06:46 +08:00
// 获取基础图层菜单栏,获取列表数据
2023-08-30 13:55:59 +08:00
getBasicLayerMenu = (adcode) => {
2024-06-15 11:22:30 +08:00
return getBasicLayerMenuApi({adcode: adcode}).then((e) => {
let basicLayeData = e.data;
2023-08-30 13:55:59 +08:00
let basicLayeList = [];
for (var i in basicLayeData) {
basicLayeList.push({
key: basicLayeData[i].id,
title : basicLayeData[i].name,
selectable: false,
2024-02-27 16:36:00 +08:00
children: this.getLayerList(basicLayeData[i].layerList),
2023-08-30 13:55:59 +08:00
})
}
this.setState ({
2024-06-17 17:06:46 +08:00
menuData: menuDataList,
2023-08-30 13:55:59 +08:00
})
});
}
2024-06-17 17:06:46 +08:00
// 获取图层列表
2023-08-30 13:55:59 +08:00
getLayerList = (layerList, i) => {
var cLayerList = [];
for (let i in layerList) {
cLayerList.push({
2024-06-17 17:06:46 +08:00
// key: 0顺序 1图层id 2时间 3名称 4是否为自创图层
key: i + '-' + layerList[i].id + '-' + new Date() + '-' + layerList[i].name + '(' + layerList[i].geoUnitAmount + ')' + '-' + layerList[i].isCustomize,
label: layerList[i].name + '(' + layerList[i].geoUnitAmount + ')',
// icon 分别为图标和小眼睛(是否显示该图层),后续在选择函数中修改
icon:[<SetLogoImagePath logoImagePath={layerList[i].logoImagePath} key={new Date().getTime() + 1}/>,<EyeInvisibleOutlined className='eye' key={new Date().getTime()} />],
// icon:({ selected }) => (selected ? [<EyeOutlined className='eye' key={new Date().getTime()} />,<SetLogoImagePath logoImagePath={layerList[i].logoImagePath} key={new Date().getTime() + 1}/>]
// : [<EyeInvisibleOutlined className='eye' key={new Date().getTime()} />,<SetLogoImagePath logoImagePath={layerList[i].logoImagePath} key={new Date().getTime() + 1}/>]),
typee: layerList[i].type,
isCustomize: layerList[i].isCustomize,
2023-08-30 13:55:59 +08:00
})
}
return cLayerList;
}
2024-06-17 17:06:46 +08:00
2024-01-22 23:26:36 +08:00
//新建点位后修改涂层数量
changeUnitAmount = (layerId) => {
2024-06-17 17:06:46 +08:00
let menu = this.state.menuData;
for (let i in menu) {
for (let j in menu[i].children) {
if (layerId == menu[i].children[j].key.split('-')[1]) {
menu[i].children[j].title = 'ooo' ;
2024-01-22 23:26:36 +08:00
}
}
}
this.setState ({
2024-06-17 17:06:46 +08:00
menuData: menu
2024-01-22 23:26:36 +08:00
})
}
2023-08-30 13:55:59 +08:00
// 选中图层
onLayerSelect = (selectedKeys, info) => {
2024-01-08 21:25:46 +08:00
let selectLayerList = [];
2023-08-30 13:55:59 +08:00
let layerId = info.node.key.split('-')[1];
2024-01-08 21:25:46 +08:00
for (let i in info.selectedNodes) {
selectLayerList.push({
'value': info.selectedNodes[i].key.split('-')[1],
'label': info.selectedNodes[i].title,
2024-01-22 23:26:36 +08:00
'isCustomize': info.selectedNodes[i].isCustomize,
2024-01-08 21:25:46 +08:00
})
}
2023-08-30 13:55:59 +08:00
this.setState({
2024-01-08 21:25:46 +08:00
layerId: layerId,
selectLayerList: selectLayerList,
2023-08-30 13:55:59 +08:00
})
if (info.node.type === 1 || info.node.type === 4) {
this.props.getLayerPoints(layerId, info.selected, info.node.type);
} else if (info.node.type === 2) {
this.props.getLayerShapes(layerId, info.selected);
}
}
2024-06-17 17:06:46 +08:00
// 选中图层
selectLayer = (e) => {
// 修改选中状态
let menuData = this.state.menuData;
this.setState({menuData:[]}) // 将图层列表的数据清空(不清空组件不更新数据)
for (let i in menuData) { // 将选中图层的小眼睛改为打开状态(重新写入数据)
for (let j in menuData[i].children) {
if (e.key === menuData[i].children[j].key) {
let iconList = menuData[i].children[j].icon[0];
menuData[i].children[j].icon = [];
menuData[i].children[j].icon.push(iconList);
menuData[i].children[j].icon.push(<EyeOutlined className='eye' key={new Date().getTime()} />);
}
}
}
// 改变选择状态并改变地图上的图层
let layerId = e.key.split('-')[1];
if (e.item.props.typee === 1 || e.item.props.typee === 4) {
this.props.getLayerPoints(layerId, true, e.item.props.typee);
} else if (e.item.props.typee === 2) {
this.props.getLayerShapes(layerId, true);
}
// 将选中图层写入选中图层列表
let selectLayerList = [];
for (let m in e.selectedKeys) {
selectLayerList.push({
// key: 0顺序 1图层id 2时间 3名称 4是否为自创图层
'value' : e.selectedKeys[m].split('-')[1],
'label' : e.selectedKeys[m].split('-')[3],
'isCustomize' : e.selectedKeys[m].split('-')[4],
})
}
this.setState({
layerId: layerId,
selectLayerList: selectLayerList,
menuData: [...menuData]
})
}
// 取消选中图层
deselectlayer = (e) =>{
// 修改选中状态
let menuData = this.state.menuData;
this.setState({menuData:[]})
for (let i in menuData) {
for (let j in menuData[i].children) {
if (e.key === menuData[i].children[j].key) {
let iconList = menuData[i].children[j].icon[0];
menuData[i].children[j].icon = [];
menuData[i].children[j].icon.push(iconList);
menuData[i].children[j].icon.push(<EyeInvisibleOutlined className='eye' key={new Date().getTime()} />);
}
}
}
// 改变选择状态并改变地图上的图层
let layerId = e.key.split('-')[1];
if (e.item.props.typee === 1 || e.item.props.typee === 4) {
this.props.getLayerPoints(layerId, false, e.item.props.typee);
} else if (e.item.props.typee === 2) {
this.props.getLayerShapes(layerId, false);
}
// 将选中图层写入选中图层列表
let selectLayerList = [];
for (let m in e.selectedKeys) {
selectLayerList.push({
// key: 0顺序 1图层id 2时间 3名称 4是否为自创图层
'value' : e.selectedKeys[m].split('-')[1],
'label' : e.selectedKeys[m].split('-')[3],
'isCustomize' : e.selectedKeys[m].split('-')[4],
})
}
this.setState({
layerId: layerId,
selectLayerList: selectLayerList,
menuData: [...menuData],
})
}
2023-10-25 22:47:42 +08:00
//弹出框事件
showModal = () => {
this.setState({
isModalOpen: true
});
};
handleOk = (values) => {
2024-02-27 16:36:00 +08:00
let self = this;
2023-10-25 22:47:42 +08:00
if (this.state.addLayer.id != 0) { //编辑图层
updateLayer({
id: this.state.addLayer.id,
logoImagePath: this.state.addLayer.logoImagePath,
name: this.state.addLayer.name,
note: this.state.addLayer.note,
}).then((e) => {
this.setState({
isModalOpen: false
});
})
} else {
createLayer({ //创建图层
2024-01-29 22:49:41 +08:00
// id: this.state.addLayer.id,
cityAdcode: this.props.adcode.cityAdcode,
districtAdcode: this.props.adcode.districtAdcode,
2023-10-25 22:47:42 +08:00
logoImagePath: this.state.addLayer.logoImagePath,
name: this.state.addLayer.name,
note: this.state.addLayer.note,
}).then((e) => {
2024-01-29 23:07:42 +08:00
if (e.success) {
2024-02-27 16:36:00 +08:00
message.success(e.message || '图层创建成功!');
2024-01-29 23:07:42 +08:00
this.setState({
isModalOpen: false
});
} else {
2024-02-27 16:36:00 +08:00
message.error(e.message || '图层创建失败!');
2024-01-29 23:07:42 +08:00
}
2024-02-27 16:36:00 +08:00
}).then(() => {
let filter = self.props.adcode.districtAdcode || self.props.adcode.cityAdcode;
self.getBasicLayerMenu(filter)
2023-10-25 22:47:42 +08:00
})
}
};
handleCancel = () => {
this.setState({
isModalOpen: false
});
};
onLayerNameChange = (e) => {
this.setState({
addLayer: {
id: this.state.addLayer.id,
logoImagePath: this.state.addLayer.logoImagePath,
note: this.state.addLayer.note,
name: e.target.value,
2024-04-02 22:57:35 +08:00
logoImageColor: this.state.addLayer.logoImageColor
2023-10-25 22:47:42 +08:00
}
})
};
onLayerNoteChange = (e) => {
this.setState({
addLayer: {
id: this.state.addLayer.id,
logoImagePath: this.state.addLayer.logoImagePath,
name: this.state.addLayer.name,
note: e.target.value,
2024-04-02 22:57:35 +08:00
logoImageColor: this.state.addLayer.logoImageColor
2023-10-25 22:47:42 +08:00
}
})
};
2024-04-02 22:57:35 +08:00
onLayerIconColorChange = (e) => {
2023-10-25 22:47:42 +08:00
this.setState({
2024-04-02 22:57:35 +08:00
addLayer: {
id: this.state.addLayer.id,
note: this.state.addLayer.note,
name: this.state.addLayer.name,
logoImagePath: this.state.addLayer.logoImagePath,
logoImageColor: e.target.value
}
})
};
onLayerIogoImagePathChange = (e) => {
this.setState({
2023-10-25 22:47:42 +08:00
addLayer: {
id: this.state.addLayer.id,
note: this.state.addLayer.note,
name: this.state.addLayer.name,
logoImagePath: e.target.value,
2024-04-02 22:57:35 +08:00
logoImageColor: this.state.addLayer.logoImageColor
2023-10-25 22:47:42 +08:00
}
})
};
2024-06-17 17:06:46 +08:00
// 根据已选列表变化
changeSelectStatus = () => {
for (let n in this.state.selectLayerList) {
// 修改选中状态
let menuData = this.state.menuData;
this.setState({menuData:[]})
for (let i in menuData) {
for (let j in menuData[i].children) {
if (this.state.selectLayerList[n].value === menuData[i].children[j].key.split('-')[1]) {
let iconList = menuData[i].children[j].icon[0];
menuData[i].children[j].icon = [];
menuData[i].children[j].icon.push(iconList);
menuData[i].children[j].icon.push(<EyeOutlined className='eye' key={new Date().getTime()} />);
}
}
}
this.setState({
menuData: [...menuData]
})
}
}
2023-08-30 13:55:59 +08:00
render() {
return (
<div className='layer-data-wrap'>
2024-06-17 17:06:46 +08:00
<div className='menu-list'>
<div className={this.state.menuData.length > 0 ? 'showItem layer-data-title' : 'hideItem layer-data-title'}>
<span>图层数据</span>
</div>
<Menu
2023-08-30 13:55:59 +08:00
multiple
2024-06-17 17:06:46 +08:00
id='layer-data-menu'
onDeselect={this.deselectlayer}
onSelect={this.selectLayer}
items={this.state.menuData}
mode='inline'
2023-08-30 13:55:59 +08:00
/>
2024-06-17 17:06:46 +08:00
<div id='add-layer'>
<Button type='primary' id='add-layer-button' className={this.state.menuData.length > 0 ? 'showItem' : 'hideItem'}
onClick={this.showModal}>新建图层</Button>
</div>
</div>
2023-10-25 22:47:42 +08:00
<Modal title="新建图层" open={this.state.isModalOpen} onOk={this.handleOk} onCancel={this.handleCancel} className='edit-layer-modal'>
2023-10-27 22:03:45 +08:00
<Form name='base' id='edit-layer-form' onFinish={this.handleOk}>
2023-10-25 22:47:42 +08:00
<Form.Item label="图层名称"
rules={[
{
required: true,
message: '请输入图层名称!',
}
]}>
<Input name='id' type='hidden' value={this.state.addLayer.id}/>
<Input name='name' value={this.state.addLayer.name} onChange={this.onLayerNameChange}/>
</Form.Item>
<Form.Item label="图层图标" rules={[
{
required: true,
message: '请选择图层图标!',
}
]}>
2024-04-02 22:57:35 +08:00
<Radio.Group id='redio-btn-color-group' onChange={this.onLayerIconColorChange}>
<Radio.Button name='logoColor' value='red' className='radio-btn-color color-01'></Radio.Button>
<Radio.Button name='logoColor' value='yellow' className='radio-btn-color color-02'></Radio.Button>
<Radio.Button name='logoColor' value='green' className='radio-btn-color color-03'></Radio.Button>
<Radio.Button name='logoColor' value='blue' className='radio-btn-color color-04'></Radio.Button>
<Radio.Button name='logoColor' value='cyan' className='radio-btn-color color-05'></Radio.Button>
<Radio.Button name='logoColor' value='pink' className='radio-btn-color color-06'></Radio.Button>
<Radio.Button name='logoColor' value='white' className='radio-btn-color color-07'></Radio.Button>
<Radio.Button name='logoColor' value='gray' className='radio-btn-color color-08'></Radio.Button>
<Radio.Button name='logoColor' value='black' className='radio-btn-color color-09'></Radio.Button>
</Radio.Group>
2023-10-25 22:47:42 +08:00
<Radio.Group id='redio-btn-group' onChange={this.onLayerIogoImagePathChange}>
2024-04-08 21:56:05 +08:00
<Radio.Button name='logoImagePath' value={`iconPoint01_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint01_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint02_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint02_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint03_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint03_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint04_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint04_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint05_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint05_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint06_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint06_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint07_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint07_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint08_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint08_${this.state.addLayer.logoImageColor}`}></Radio.Button>
<Radio.Button name='logoImagePath' value={`iconPoint09_${this.state.addLayer.logoImageColor}`} className={`radio-btn iconPoint09_${this.state.addLayer.logoImageColor}`}></Radio.Button>
2023-10-25 22:47:42 +08:00
</Radio.Group>
</Form.Item>
<Form.Item label="图层备注">
2023-10-27 22:03:45 +08:00
<Input.TextArea name='note' value={this.state.addLayer.note} onChange={this.onLayerNoteChange}
style={{height: '120px'}}/>
2023-10-25 22:47:42 +08:00
</Form.Item>
</Form>
</Modal>
2023-08-30 13:55:59 +08:00
</div >
);
}
}
export default LayerData