Repository navigation
Expand file tree
/
Copy pathLayer.js
More file actions
executable file
·352 lines (326 loc) · 9.9 KB
/
Copy pathLayer.js
File metadata and controls
executable file
·352 lines (326 loc) · 9.9 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*********************************************************************************
Copyright © SuperMap. All rights reserved.
Author: will
E-mail: pridehao@gmail.com
**********************************************************************************/
import { NativeModules } from 'react-native'
let L = NativeModules.JSLayer
let ThemeType = NativeModules.JSThemeType;
import Dataset from './Dataset.js'
import Recordset from './Recordset.js'
import Selection from './Selection.js'
import LayerSetting from './LayerSetting.js'
import LayerSettingVector from './LayerSettingVector.js'
import LayerSettingGrid from './LayerSettingGrid'
import LayerSettingImage from './LayerSettingImage'
import Theme from './Theme'
import ThemeLabel from './ThemeLabel'
import ThemeRange from './ThemeRange'
import ThemeUnique from './ThemeUnique'
/**
* @class Layer
* @description (该类的实例不可被创建,只可以通过在 Map 类中的 addLayer 方法来创建)该类提供了图层显示和控制等的便于地图管理的一系列方法。当数据集被加载到地图窗口中显示的时,就形成了一个图层,因此图层是数据集的可视化显示。一个图层是对一个数据集的引用或参考。通过对可视化的图层的编辑,可以对 相应的数据集的要素进行编辑。一个图层或多个图层叠加显示则形成了地图。图层分为普通图层和专题图层,矢量的普通图层中所有要素采用相同的渲染风格,栅格图层采用颜色表来显示其像元;而专题图层则采用指定类型的专题图风格来渲染其中的 要素或像元。
*/
export default class Layer {
constructor() {
}
/**
* 设置图层是否处于可编辑状态。该方法控制是否对图层所引用的数据进行修改。
* @memberOf Layer
* @param {boolean} editable
* @returns {Promise.<void>}
*/
async setEditable(editable) {
try {
await L.setEditable(this._SMLayerId, editable)
} catch (e) {
console.error(e)
}
}
/**
* 判断图层是否处于可编辑状态。
* @memberOf Layer
* @returns {Promise.<boolean>}
*/
async getEditable() {
try {
var { isEditable } = await L.getEditable(this._SMLayerId)
return isEditable
} catch (e) {
console.error(e)
}
}
/**
* 返回图层的名称。图层的名称在图层所在的地图中唯一标识此图层。该标识不区分大小写。
* @memberOf Layer
* @returns {Promise.<void>}
*/
async getName() {
try {
var { layerName } = await L.getName(this._SMLayerId)
return layerName
} catch (e) {
console.error(e)
}
}
/**
* 返回此图层对应的数据集对象。图层是对数据集的引用,因而,一个图层与一个数据集相对应。
* @memberOf Layer
* @returns {Promise.<Dataset>}
*/
async getDataset() {
try {
var { datasetId } = await L.getDataset(this._SMLayerId)
if (datasetId) {
var dataset = new Dataset()
dataset._SMDatasetId = datasetId
return dataset
} else {
return null
}
} catch (e) {
console.error(e)
}
}
/**
* 设置图层关联的数据集。 设置的数据集必须与当前地图属于同一工作空间,且数据集类型与原有数据集类型一致,否则会抛出异常(该方法暂不支持iOS设备)。
* @memberOf Layer
* @param {object} dataset - 图层关联的数据集
* @returns {Promise.<void>}
*/
async setDataset(dataset) {
try {
await L.setDataset(this._SMLayerId, dataset._SMDatasetId)
} catch (e) {
console.error(e)
}
}
/**
* 返回此图层中的选择集对象。选择集是个集合,其中包含选择的图层中的一个或多个要素。在选择集中的要素才可以被编辑。注意选择集只适用于矢量数据集,栅格数据集和影像数据集没有选择集。
* @memberOf Layer
* @returns {Promise.<Selection>}
*/
async getSelection() {
try {
var { selectionId, recordsetId } = await L.getSelection(this._SMLayerId)
var selection = new Selection()
var recordset = new Recordset()
selection._SMSelectionId = selectionId
recordset._SMRecordsetId = recordsetId
selection.recordset = recordset
return selection
} catch (e) {
console.error(e)
}
}
/**
* 设置图层中对象是否可以选择。
* @memberOf Layer
* @param {boolean} b
* @returns {Promise.<void>}
*/
async setSelectable(b) {
try {
await L.setSelectable(this._SMLayerId, b)
} catch (e) {
console.error(e)
}
}
/**
* 返回图层中对象是否可以选择
* @memberOf Layer
* @param {void}
* @returns {Promise.<boolean>}
*/
async isSelectable() {
try {
var { selectable } = await L.isSelectable(this._SMLayerId)
return selectable
} catch (e) {
console.error(e)
}
}
/**
* 获取此图层是否可见。true 表示此图层可见,false 表示图层不可见。当图层不可见时,其他所有的属性的设置将无效。
* @memberOf Layer
* @returns {Promise.<boolean>}
*/
async getVisible() {
try {
var isVisible = await L.getVisible(this._SMLayerId)
return isVisible
} catch (e) {
console.error(e)
}
}
/**
* 设置此图层是否可见。true 表示此图层可见,false 表示图层不可见。当图层不可见时,其他所有的属性的设置将无效。
* @memberOf Layer
* @param {boolean} b
* @returns {Promise.<void>}
*/
async setVisible(b) {
try {
await L.setVisible(this._SMLayerId, b)
} catch (e) {
console.error(e)
}
}
/**
* 获取此图层是否可捕捉
* @returns {Promise}
*/
async isSnapable() {
try {
var isSnapable = await L.isSnapable(this._SMLayerId)
return isSnapable
} catch (e) {
console.error(e)
}
}
/**
* 设置此图层是否可捕捉,false不可捕捉, true可捕捉
* @param isSnapable
* @returns {Promise.<void>}
*/
async setSnapable(isSnapable) {
try {
await L.setSnapable(this._SMLayerId, isSnapable)
} catch (e) {
console.error(e)
}
}
/**
* 返回普通图层的风格设置。LayerSettingVector 类用来对矢量数据图层风格进行设置和修改。
* @memberOf Layer
* @returns {Promise.<LayerSetting>}
*/
async getAdditionalSetting() {
try {
let layerSetting
let { _layerSettingId_, type } = await L.getAdditionalSetting(this._SMLayerId)
if (type === 0) {
layerSetting = new LayerSettingVector()
layerSetting._SMLayerSettingId = _layerSettingId_
} else if (type === 1) {
//image
layerSetting = new LayerSettingImage()
layerSetting._SMLayerSettingId = _layerSettingId_
} else {
//grid
layerSetting = new LayerSettingGrid()
layerSetting._SMLayerSettingId = _layerSettingId_
}
return layerSetting
} catch (e) {
console.error(e)
}
}
/**
* 设置普通图层的风格。普通图层风格的设置对矢量数据图层、栅格数据图层以及影像数据图层是不相同的。LayerSettingVector类用来对矢量数据图层的风格进行设置和修改。
* @memberOf Layer
* @param {LayerSetting} layerSetting - 普通图层的风格设置.{@link LayerSetting}
* @returns {Promise.<void>}
*/
async setAdditionalSetting(layerSetting) {
try {
await L.setAdditionalSetting(this._SMLayerId, layerSetting._SMLayerSettingId)
} catch (e) {
console.error(e)
}
}
/**
* 返回选中的对象的集合
* @param point2D
* @param tolerance
* @returns {Promise.<Selection>}
*/
async hitTest(point2D, tolerance) {
try {
let { selectionId, recordsetId } = await L.hitTest(this._SMLayerId, point2D._SMPoint2DId, tolerance)
let selection = await new Selection()
selection._SMSelectionId = selectionId
let recordset = await new Recordset()
recordset._SMRecordsetId = recordsetId
selection.recordset = recordset
return selection
} catch (e) {
console.error(e)
}
}
/**
* 返回选中的对象的集合
* @param point
* @param tolerance
* @returns {Promise.<Selection>}
*/
async hitTestEx(point, tolerance) {
try {
let { selectionId, recordsetId } = await L.hitTestEx(this._SMLayerId, point._SMPointId, tolerance)
let selection = await new Selection()
selection._SMSelectionId = selectionId
let recordset = await new Recordset()
recordset._SMRecordsetId = recordsetId
selection.recordset = recordset
return selection
} catch (e) {
console.error(e)
}
}
/**
* 返回图层标题
* @returns {Promise}
*/
async getCaption() {
try {
return await L.getCaption(this._SMLayerId)
} catch (e) {
console.error(e)
}
}
/**
* 设置图层标题
* @param value
* @returns {Promise.<void>}
*/
async setCaption(value) {
try {
await L.setCaption(this._SMLayerId, value)
} catch (e) {
console.error(e)
}
}
/**
* 获取专题图层的专题图对象
* @returns {Promise.<void>}
*/
async getTheme() {
try {
let mTheme = await L.getTheme(this._SMLayerId) // {themeId, type}
if (mTheme && mTheme.themeId) {
let theme;
switch (mTheme.type) {
case ThemeType.UNIQUE:
theme = new ThemeUnique()
break
case ThemeType.RANGE:
theme = new ThemeRange()
break
case ThemeType.LABEL:
theme = new ThemeLabel()
break
default:
theme = new Theme()
break
}
theme._SMThemeId = mTheme.themeId
theme.type = mTheme.type
return theme
} else {
return null
}
} catch (e) {
console.error(e)
}
}
}