Repository navigation
Expand file tree
/
Copy pathGeoText.js
More file actions
executable file
·183 lines (170 loc) · 4.43 KB
/
Copy pathGeoText.js
File metadata and controls
executable file
·183 lines (170 loc) · 4.43 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
/*********************************************************************************
Copyright © SuperMap. All rights reserved.
Author: Yang Shanglong
E-mail: yangshanglong@supermap.com
**********************************************************************************/
import { NativeModules } from 'react-native';
let GT = NativeModules.JSGeoText;
import TextPart from './TextPart'
import TextStyle from './TextStyle'
/**
* 文本类,派生于 Geometry 类。
* 该类主要用于对地物要素进行标识和必要的注记说明。
* 文本对象由一个或多个部分组成,每个部分称为文本对象的一个子对象,每个子对象都是一个 TextPart 的实例。
* 同一个文本对象的所有子对象都使用相同的文本风格,即使用该文本对象的文本风格进行显示。
*/
export default class GeoText {
async createObj() {
try {
let geoTextId = await GT.createObj();
let geoText = new GeoText();
geoText._SMGeoTextId = geoTextId;
return geoText;
} catch (e) {
console.error(e);
}
}
async createObjWithTextPart(textPart) {
try {
let geoTextId = await GT.createObjWithTextPart(textPart._SMTextPartId);
let geoText = new GeoText();
geoText._SMGeoTextId = geoTextId;
return geoText;
} catch (e) {
console.error(e);
}
}
async dispose () {
try {
await GT.dispose(this._SMGeoTextId);
} catch (e) {
console.error(e);
}
}
/**
* 在文本对象中添加文本子对象
* @param textPartId
* @returns {Promise.<void>}
*/
async addPart(textPartId) {
try {
await GT.addPart(this._SMGeoTextId, textPartId);
} catch (e) {
console.error(e);
}
}
/**
* 返回此文本对象的指定序号的子对象
* @returns {Promise}
*/
async getPart(index) {
try {
let textPartId = await GT.getRotation(this._SMGeoTextId, index);
let textPart = new TextPart();
textPart._SMTextPartId = textPartId
return textPart;
} catch (e) {
console.error(e);
}
}
/**
* 返回文本对象的子对象个数
* @returns {Promise.<Promise|string>}
*/
async getPartCount() {
try {
let count = await GT.getPartCount(this._SMGeoTextId);
return count
} catch (e) {
console.error(e);
}
}
/**
* 返回文本对象的内容
* @returns {Promise.<Promise|Promise.<Promise|string>|string>}
*/
async getText() {
try {
let text = await GT.getText(this._SMGeoTextId);
return text;
} catch (e) {
console.error(e);
}
}
/**
* 返回文本对象的文本风格
* @returns {Promise.<TextStyle>}
*/
async getTextStyle() {
try {
let textStyleId = await GT.getTextStyle(this._SMGeoTextId);
let textStyle = new TextStyle();
textStyle._SMTextStyleId = textStyleId;
return textStyle;
} catch (e) {
console.error(e);
}
}
/**
* 在此文本对象的指定位置插入一个文本子对象
* @param index
* @param textPartId
* @returns {Promise.<void>}
*/
async insertPart(index, textPart) {
try {
await GT.insertPart(this._SMGeoTextId, index, textPart._SMPoint2DId);
} catch (e) {
console.error(e);
}
}
/**
* 判定该文本对象是否为空,即其子对象的个数是否为0
* @returns {Promise.<Promise|*|boolean>}
*/
async isEmpty() {
try {
let isEmpty = await GT.isEmpty(this._SMGeoTextId);
return isEmpty;
} catch (e) {
console.error(e);
}
}
/**
* 删除此文本对象的指定序号的文本子对象
* @param index
* @returns {Promise.<void>}
*/
async removePart(index) {
try {
await GT.removePart(this._SMGeoTextId, index);
} catch (e) {
console.error(e);
}
}
/**
* 修改此文本对象的指定序号的子对象,即用新的文本子对象来替换原来的文本子对象
* @param index
* @param textPart
* @returns {Promise.<void>}
*/
async setPart(index, textPart) {
try {
await GT.setPart(this._SMGeoTextId, index, textPart._SMPoint2DId);
} catch (e) {
console.error(e);
}
}
/**
* 设置文本对象的文本风格
* @param textStyle
* @returns {Promise.<void>}
*/
async setTextStyle(textStyle) {
try {
await GT.setTextStyle(this._SMGeoTextId, textStyle._SMPoint2DId);
} catch (e) {
console.error(e);
}
}
}