Repository navigation
Expand file tree
/
Copy pathMapChange.js
More file actions
executable file
·90 lines (80 loc) · 2.18 KB
/
Copy pathMapChange.js
File metadata and controls
executable file
·90 lines (80 loc) · 2.18 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
import * as React from 'react'
import { FlatList } from 'react-native'
import { Container, ListSeparator } from '../../components'
import { Toast } from '../../utils'
import NavigationService from '../NavigationService'
import { MapListItem } from './components'
export default class MapChange extends React.Component {
props: {
navigation: Object,
nav: Object,
}
constructor(props) {
super(props)
const { state } = this.props.navigation
this.workspace = state.params.workspace
this.map = state.params.map
this.cb = state.params.cb
;(async function () {
let maps = await this.workspace.getMaps()
let count = await maps.getCount()
let mapNameArr = []
for (let i = 0; i < count; i++) {
let name = await maps.get(i)
let map = this.map
mapNameArr.push({ key: name, num: i, map: map })
}
this.setState({
dataList: mapNameArr,
}, () => {
this.container.setLoading(false)
})
}).bind(this)()
}
state = {
dataList: '',
}
_map_change = ({key, map}) => {
(async function () {
await map.close()
await map.open(key)
await map.refresh()
// NavigationService.goBack()
this.cb && this.cb()
let routes = this.props.nav.routes
let routeKey = ''
for (let i = 0; i < routes.length - 1; i++) {
if (routes[i].routeName === 'MapView') {
routeKey = routes[i + 1].key
}
}
NavigationService.goBack(routeKey)
Toast.show('地图切换成功')
}).bind(this)()
}
_renderItem = ({ item }) => {
return (
<MapListItem data={item} onPress={() => {this._map_change(item)}} />
)
}
_renderItemSeparatorComponent = () => {
return <ListSeparator />
}
render() {
return (
<Container
ref={ref => this.container = ref}
initWithLoading
headerProps={{
title: '地图切换',
navigation: this.props.navigation,
}}>
<FlatList
data={this.state.dataList}
renderItem={this._renderItem}
ItemSeparatorComponent={this._renderItemSeparatorComponent}
/>
</Container>
)
}
}