Repository navigation
Expand file tree
/
Copy pathAddDataset.js
More file actions
executable file
·216 lines (196 loc) · 6.12 KB
/
Copy pathAddDataset.js
File metadata and controls
executable file
·216 lines (196 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
Copyright © SuperMap. All rights reserved.
Author: Yangshanglong
E-mail: yangshanglong@supermap.com
*/
import * as React from 'react'
import { SectionList } from 'react-native'
import { Toast } from '../../utils'
import { DatasetType } from 'imobile_for_javascript'
import { Container, ListSeparator, TextBtn, DataSetListSection, DataSetListItem } from '../../components'
import styles from './styles'
export default class AddDataset extends React.Component {
props: {
navigation: Object,
}
constructor(props) {
super(props)
const { params } = this.props.navigation.state
this.workspace = params.workspace
this.map = params.map
this.layerList = params.layerList || []
this.cb = params.cb
this.state = {
dataSourceList: [],
openList: {},
}
}
componentDidMount() {
this.getDatasets()
}
checkContainsDataset = async dsName => {
return new Promise(async (resolve, reject) => {
try {
let isExist = false
for (let i = 0; i < this.layerList.length; i++) {
let ds = await this.layerList[i].layer.getDataset()
if (!ds) continue
let name = await ds.getName()
if (name === dsName) {
isExist = true
break
}
if (await ds.getType() === DatasetType.Network) {
let dv = await ds.toDatasetVector()
let subDataset = await dv.getChildDataset()
if (subDataset && await subDataset.getName() === dsName){
isExist = true
break
}
}
}
resolve(isExist)
} catch (e) {
reject(e)
}
})
}
getDatasets = async () => {
let list = []
let dataSources = await this.workspace.getDatasources()
let count = await dataSources.getCount()
for (let i = 0; i < count; i++) {
let dataSetList = []
let dataSource = await dataSources.get(i)
let name = await dataSource.getAlias()
let dataSets = await dataSource.getDatasets()
let dataSetCount = await dataSets.getCount()
for (let j = 0; j < dataSetCount; j++) {
let dataset = await dataSets.get(j)
let dsType = await dataset.getType()
if (dsType === DatasetType.TABULAR) continue
let dsName = await dataset.getName()
// let isAdd = await this.map.containsCaption(dsName, name)
let isAdd = await this.checkContainsDataset(dsName)
// let isAdd = false
dataSetList.push({
name: dsName,
type: dsType,
isAdd: isAdd,
dataset: dataset,
section: i,
key: i + '-' + dsName,
})
if (dsType === DatasetType.Network) {
let dv = await dataset.toDatasetVector()
let subDataset = await dv.getChildDataset()
let subDatasetName = await subDataset.getName()
let subDatasetType = await subDataset.getType()
let subDatasetIsAdd = await this.checkContainsDataset(subDatasetName)
if (subDataset) {
dataSetList.push({
name: subDatasetName,
type: subDatasetType,
isAdd: subDatasetIsAdd,
dataset: subDataset,
section: i,
key: 'sub-' + i + '-' + subDatasetName,
})
}
}
}
list.push({
key: name,
isShow: true,
data: dataSetList,
index: i,
})
}
this.setState({
dataSourceList: list,
}, () => {
this.container.setLoading(false)
})
}
showSection = (section, isShow?: boolean) => {
let newData = this.state.dataSourceList
if (isShow === undefined) {
section.isShow = !section.isShow
} else {
section.isShow = isShow
}
newData[section.index] = section
this.setState({
dataSourceList: newData.concat(),
})
}
select = data => {
let newList = this.state.openList
if (newList[data.section + '-' + data.name]) {
delete(newList[data.section + '-' + data.name])
} else {
newList[data.section + '-' + data.name] = data
}
this.setState({
openList: newList,
})
}
/**
* 添加数据集
* @returns {Promise.<void>}
*/
addDatasets = async () => {
if (Object.getOwnPropertyNames(this.state.openList).length <= 0) return
let showEntireMap = false
for(let key in this.state.openList) {
let item = this.state.openList[key]
await this.map.addLayer(item.dataset, true)
if (item.type === DatasetType.IMAGE || item.type === DatasetType.Grid) {
showEntireMap = true
}
}
Toast.show('添加图层成功')
this.map && await this.map.refresh()
showEntireMap && this.map && await this.map.viewEntire()
this.props.navigation.goBack()
this.cb && this.cb()
}
_renderSetion = ({ section }) => {
return (
<DataSetListSection data={section} height={60} onPress={this.showSection} />
)
}
_renderItem = ({ item }) => {
return (
<DataSetListItem subTitle={'已添加'} radio={true} hidden={!this.state.dataSourceList[item.section].isShow} data={item} height={60} onPress={this.select} />
)
}
_renderItemSeparatorComponent = ({ section }) => {
return section.isShow ? <ListSeparator /> : null
}
// _renderSectionSeparatorComponent = ({ section }) => {
// return section.isShow ? <ListSeparator height={scaleSize(20)} /> : null
// }
_keyExtractor = item => (item.key + item.index)
render() {
return (
<Container
ref={ref => this.container = ref}
initWithLoading
headerProps={{
title: '添加图层',
navigation: this.props.navigation,
headerRight: <TextBtn btnText="添加" textStyle={styles.headerBtnTitle} btnClick={this.addDatasets} />,
}}>
<SectionList
renderSectionHeader={this._renderSetion}
renderItem={this._renderItem}
keyExtractor={this._keyExtractor}
sections={this.state.dataSourceList}
ItemSeparatorComponent={this._renderItemSeparatorComponent}
// SectionSeparatorComponent={this._renderSectionSeparatorComponent}
/>
</Container>
)
}
}