/
Feature.ts
107 lines (92 loc) 路 2.93 KB
/
Feature.ts
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
import { inherit } from '@vue-cesium/utils/util'
let inherited = false
// const customProperties = ['entityCollection', 'properties', 'data']
class Feature {
currentProperties: any
currentDescription: any
updateCounters: any
cesiumEntity: Cesium.Entity
name: any
description: any
properties: any
data: any
imageryLayer: any
position: any
coords: any
constructor(options) {
const { Entity, knockout } = Cesium
Entity.call(this, options)
// addCustomFeatureProperties(this)
this.currentProperties = undefined
/**
* Gets or sets the current description. This property is observable.
* @type {String}
*/
this.currentDescription = undefined
/**
* Gets or sets counter objects used to trigger an update of the Feature Info Section,
* to allow custom components to self-update. The object keys are timeoutIds, and values are
* {reactComponent: ReactComponent, counter: Integer}.
* This property is observable.
* @type {Object}
*/
this.updateCounters = undefined
knockout.track(this, [
'currentProperties',
'currentDescription',
'updateCounters'
])
}
static init () {
if (inherited) {
return
}
inherit(Cesium.Entity, Feature)
inherited = true
}
static fromEntity (entity: Cesium.Entity) {
const feature = new Feature({ id: entity.id })
;(feature as any).merge(entity)
// for (let i = 0; i < customProperties.length; i++) {
// if (entity.propertyNames.indexOf(customProperties[i]) === -1) {
// feature[customProperties[i]] = entity[customProperties[i]] // Assume no merging or cloning needed.
// }
// }
feature.cesiumEntity = entity
return feature
}
static fromEntityCollectionOrEntity (entity) {
// If this entity is part of a collection, get the feature with this id from that collection.
let feature
if (entity.entityCollection) {
feature = entity.entityCollection.getById(entity.id)
}
if (!feature || !(feature instanceof Feature)) {
feature = Feature.fromEntity(entity)
}
return feature
}
static fromImageryLayerFeature (imageryFeature, viewer: Cesium.Viewer) {
const feature = new Feature({
id: imageryFeature.name
})
feature.name = imageryFeature.name
feature.description = imageryFeature.description // already defined by the new Entity
feature.properties = imageryFeature.properties
feature.data = imageryFeature.data
feature.imageryLayer = imageryFeature.imageryLayer
feature.position = viewer.scene.globe.ellipsoid.cartographicToCartesian(
imageryFeature.position
)
feature.coords = imageryFeature.coords
return feature
}
}
// function addCustomFeatureProperties (entity) {
// for (let i = 0; i < customProperties.length; i++) {
// if (entity.propertyNames.indexOf(customProperties[i]) === -1) {
// entity.addProperty(customProperties[i])
// }
// }
// }
export default Feature