-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddressBalloonFeatureInfoView.js
137 lines (129 loc) · 4.12 KB
/
addressBalloonFeatureInfoView.js
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
import BalloonFeatureInfoView, {
extractNestedKey,
} from './balloonFeatureInfoView.js';
import AddressBalloonComponent from './AddressBalloonComponent.vue';
/**
* @typedef {import("./balloonFeatureInfoView.js").BalloonFeatureInfoViewOptions & {
* addressName?: string|null,
* street?: string|null,
* number?: string|null,
* city?: string|null,
* zip?: string|null,
* country?: string|null,
* }} AddressBalloonFeatureInfoViewOptions
* @property {string|null} [addressName='gml:name'] key to evaluate for name. Use null to suppress
* @property {string|null} [street='Address.Street'] key to evaluate for street. Use null to suppress
* @property {string|null} [number='Address.HouseNumber'] key to evaluate for house number. Use null to suppress
* @property {string|null} [city='Address.City'] key to evaluate for city. Use null to suppress
* @property {string|null} [zip='Address.ZipCode'] key to evaluate for zip code. Use null to suppress
* @property {string|null} [country='Address.Country'] key to evaluate for country. Use null to suppress
*/
/**
* @class
* @description An balloon view.
* @extends {BalloonFeatureInfoView}
*/
class AddressBalloonFeatureInfoView extends BalloonFeatureInfoView {
/**
* @type {string}
*/
static get className() {
return 'AddressBalloonFeatureInfoView';
}
/** @returns {AddressBalloonFeatureInfoViewOptions} */
static getDefaultOptions() {
return {
addressName: 'gml:name',
street: 'Address.Street',
number: 'Address.HouseNumber',
city: 'Address.City',
zip: 'Address.ZipCode',
country: 'Address.Country',
};
}
/**
* @param {AddressBalloonFeatureInfoViewOptions} options
*/
constructor(options) {
super(options, AddressBalloonComponent);
const defaultOptions = AddressBalloonFeatureInfoView.getDefaultOptions();
/**
* @type {string|null}
*/
this.addressName =
options.addressName !== undefined
? options.addressName
: defaultOptions.addressName;
/**
* @type {string|null}
*/
this.street =
options.street !== undefined ? options.street : defaultOptions.street;
/**
* @type {string|null}
*/
this.number =
options.number !== undefined ? options.number : defaultOptions.number;
/**
* @type {string|null}
*/
this.city = options.city !== undefined ? options.city : defaultOptions.city;
/**
* @type {string|null}
*/
this.zip = options.zip !== undefined ? options.zip : defaultOptions.zip;
/**
* @type {string|null}
*/
this.country =
options.country !== undefined ? options.country : defaultOptions.country;
}
/**
* derives address attributes from addressKeys
* @param {undefined|import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature} feature
* @returns {Object}
*/
getAttributes(feature) {
const attributes = super.getAttributes(feature);
const obj = {};
const applyAddressKeys = (key) => {
if (this[key]) {
const derivedValue = extractNestedKey(this[key], attributes);
if (derivedValue) {
obj[key] = derivedValue;
}
}
};
Object.keys(AddressBalloonFeatureInfoView.getDefaultOptions()).forEach(
(key) => applyAddressKeys(key),
);
return obj;
}
/**
* @returns {AddressBalloonFeatureInfoViewOptions}
*/
toJSON() {
const config = super.toJSON();
const defaultOptions = AddressBalloonFeatureInfoView.getDefaultOptions();
if (this.addressName !== defaultOptions.addressName) {
config.addressName = this.addressName;
}
if (this.street !== defaultOptions.street) {
config.street = this.street;
}
if (this.number !== defaultOptions.number) {
config.number = this.number;
}
if (this.city !== defaultOptions.city) {
config.city = this.city;
}
if (this.zip !== defaultOptions.zip) {
config.zip = this.zip;
}
if (this.country !== defaultOptions.country) {
config.country = this.country;
}
return config;
}
}
export default AddressBalloonFeatureInfoView;