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

216 lines
8.2 KiB
JavaScript
Raw Normal View History

2023-08-30 13:55:59 +08:00
import React from 'react';
2023-10-25 22:47:42 +08:00
import { Tree, Button, Modal, Form, Input, Radio } from 'antd';
2023-08-30 13:55:59 +08:00
import axios from 'axios';
import {
DownOutlined,
EyeOutlined,
EyeInvisibleOutlined,
} from '@ant-design/icons';
import SetLogoImagePath from './SetLogoImagePath'
2023-10-25 22:47:42 +08:00
import { createLayer } from '../../../api';
2023-08-30 13:55:59 +08:00
import '../../../index.less';
class LayerData extends React.Component {
constructor () {
super ();
this.state = {
treeData: [],
layerId: '',
2023-10-25 22:47:42 +08:00
isModalOpen: false,
addLayer: {
id: 0,
logoImagePath: '',
name: '',
note: '',
},
2024-01-08 21:25:46 +08:00
selectLayerList: [],
2023-08-30 13:55:59 +08:00
}
}
// 获取基础图层菜单栏
getBasicLayerMenu = (adcode) => {
return axios.get('/api/basicMap/getBasicLayerMenu', {
params: {
adcode: adcode
}
}).then((e) => {
let basicLayeData = e.data.data;
let basicLayeList = [];
for (var i in basicLayeData) {
basicLayeList.push({
key: basicLayeData[i].id,
title : basicLayeData[i].name,
selectable: false,
children: this.getLayerList(basicLayeData[i].layerList, i),
})
}
this.setState ({
treeData: basicLayeList
})
});
}
getLayerList = (layerList, i) => {
var cLayerList = [];
for (let i in layerList) {
cLayerList.push({
'key': i + '-' + layerList[i].id + '-' + new Date(),
'title': layerList[i].name + '(' + layerList[i].geoUnitAmount + ')',
'icon': ({ selected }) => (selected ? [<EyeOutlined key={new Date().getTime()} />,<SetLogoImagePath logoImagePath={layerList[i].logoImagePath} key={new Date().getTime() + 1}/>]
: [<EyeInvisibleOutlined key={new Date().getTime()} />,<SetLogoImagePath logoImagePath={layerList[i].logoImagePath} key={new Date().getTime() + 1}/>]),
'type': layerList[i].type,
2024-01-22 23:26:36 +08:00
'isCustomize': layerList[i].isCustomize,
2023-08-30 13:55:59 +08:00
})
}
return cLayerList;
}
2024-01-22 23:26:36 +08:00
//新建点位后修改涂层数量
changeUnitAmount = (layerId) => {
let treeData = this.state.treeData;
for (let i in treeData) {
for (let j in treeData[i].children) {
if (layerId == treeData[i].children[j].key.split('-')[1]) {
treeData[i].children[j].title = 'ooo' ;
}
}
}
this.setState ({
treeData: treeData
})
}
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);
}
}
2023-10-25 22:47:42 +08:00
//弹出框事件
showModal = () => {
this.setState({
isModalOpen: true
});
};
handleOk = (values) => {
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({ //创建图层
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
});
})
}
};
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,
}
})
};
onLayerNoteChange = (e) => {
this.setState({
addLayer: {
id: this.state.addLayer.id,
logoImagePath: this.state.addLayer.logoImagePath,
name: this.state.addLayer.name,
note: e.target.value,
}
})
};
onLayerIogoImagePathChange = (e) => {
this.setState({
addLayer: {
id: this.state.addLayer.id,
note: this.state.addLayer.note,
name: this.state.addLayer.name,
logoImagePath: e.target.value,
}
})
};
//弹出框事件
2023-08-30 13:55:59 +08:00
render() {
return (
<div className='layer-data-wrap'>
<Tree
multiple
showIcon
defaultSelectedKeys={[]}
switcherIcon={<DownOutlined />}
treeData={this.state.treeData}
onSelect={this.onLayerSelect}
/>
2023-10-25 22:47:42 +08:00
<Button type='primary' id='add-layer' className={this.state.treeData.length > 0 ? 'showItem' : 'hideItem'}
onClick={this.showModal}>新建图层</Button>
<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: '请选择图层图标!',
}
]}>
<Radio.Group id='redio-btn-group' onChange={this.onLayerIogoImagePathChange}>
<Radio.Button name='logoImagePath' value="icon01" className='radio-btn icon-01'></Radio.Button>
<Radio.Button name='logoImagePath' value="icon02" className='radio-btn icon-02'></Radio.Button>
<Radio.Button name='logoImagePath' value="icon03" className='radio-btn icon-03'></Radio.Button>
</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