Repository navigation
Expand file tree
/
Copy pathjsonUtil.js
More file actions
72 lines (63 loc) · 1.62 KB
/
Copy pathjsonUtil.js
File metadata and controls
72 lines (63 loc) · 1.62 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
/* eslint-disable arrow-parens */
/*
Copyright © SuperMap. All rights reserved.
Author: Wang Li
*/
import { Utility } from 'imobile_for_reactnative'
import ConstPath from '../constants/ConstPath'
async function readConfig() {
let filePath =
(await Utility.appendingHomeDirectory(ConstPath.CustomerPath)) +
'mapinfo.txt'
let strJson = await Utility.readFile(filePath)
return JSON.parse(strJson)
}
async function getMapDatasource() {
let filePath =
(await Utility.appendingHomeDirectory(ConstPath.CustomerPath)) +
'mapinfo.txt'
let strJson = await Utility.readFile(filePath)
let jsonInfo = JSON.parse(strJson)
return jsonInfo.data[0].maps
}
async function saveMapInfo(configInfo, mapname, dataSources) {
let filePath =
(await Utility.appendingHomeDirectory(ConstPath.CustomerPath)) +
'mapinfo.txt'
let mapList = {
mapName: mapname + '.xml',
UDBName: dataSources,
plot: ['TY.plot'],
}
configInfo.data[0].maps.push(mapList)
let strJson = JSON.stringify(configInfo)
Utility.writeFile(filePath, strJson)
}
async function updateMapInfo(configInfo) {
let filePath =
(await Utility.appendingHomeDirectory(ConstPath.CustomerPath)) +
'mapinfo.txt'
let strJson = JSON.stringify(configInfo)
Utility.writeFile(filePath, strJson)
}
function isJSON(str) {
if (typeof str == 'string') {
try {
var obj = JSON.parse(str)
if (typeof obj == 'object' && obj) {
return true
} else {
return false
}
} catch (e) {
return false
}
}
}
export default {
readConfig,
getMapDatasource,
updateMapInfo,
saveMapInfo,
isJSON,
}