-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPFloor.ts
170 lines (157 loc) · 3.86 KB
/
MPFloor.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
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
import MPEntity from "./MPEntity";
import { MPMultiPolygon, MPMultiPolygonParams, MPBounds, MPPoint, MPBuilding } from "../../index";
import { Platform } from "react-native";
/**
* A MapsIndoors geographical entity. A floor is contained within a {@link MPBuilding}.
*
* @export
* @class MPFloor
* @typedef {MPFloor}
* @extends {MPEntity}
*/
export default class MPFloor extends MPEntity {
/**
* The default floor index is 0, as that is the index of ground floors and any point outside a building.
*
* @public
* @static
* @readonly
* @type {number}
*/
public static readonly defaultGroundFloorIndex: number = 0;
/**
* Creates an instance of MPFloor.
*
* @constructor
* @private
* @param {string} [id] The floor's ID.
* @param {string} [name] The floor's name.
* @param {?MPMultiPolygon} [geometry] The geometry of the floor.
* @param {?string[]} [aliases] An array of aliases used by the floor.
* @param {?number} [floorIndex] The floor index of the floor.
* @param {?string} [buildingId] The ID of the building this floor lies within.
*/
private constructor(
private readonly id: string,
private readonly name: string,
public readonly geometry?: MPMultiPolygon,
public readonly aliases?: string[],
public readonly floorIndex?: number,
public buildingId?: string,
) {
super("MPFloor");
}
public get isPoint(): boolean {
return false;
}
/**
* Creator for MPFloor, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPFloorParams} object
* @returns {MPFloor}
*/
public static create(object: MPFloorParams): MPFloor {
var multiPolygon;
if (Platform.OS === 'ios') {
multiPolygon = MPMultiPolygon.create({coordinates: object?.geometry, bbox: [].concat(object?.entityBounds?.northeast, object?.entityBounds?.southwest)});
}else {
multiPolygon = MPMultiPolygon.create(object?.geometry);
}
return new MPFloor(
object?.id,
object?.name,
multiPolygon,
object?.aliases,
object?.floorIndex,
object?.buildingId,
);
}
/**
* Get the floor's id.
*
* @public
* @readonly
* @type {string}
*/
public get floorId(): string {
return this.id;
}
/**
* Get the floor's displayName.
*
* @public
* @readonly
* @type {string}
*/
public get displayName(): string {
return this.name;
}
/**
* Get the floor's bounds.
*
* @public
* @readonly
* @type {MPBounds}
*/
public get bounds(): MPBounds {
return this.geometry!.bounds;
}
/**
* Get the floor's position, this is usually the center of the floors {@link geometry}.
*
* @public
* @readonly
* @type {MPPoint}
*/
public get position(): MPPoint {
return this.geometry!.bounds.center;
}
}
/**
* Parameter interface for {@link MPFloor}.
*
* @export
* @interface MPFloorParams
* @typedef {MPFloorParams}
*/
export interface MPFloorParams {
/**
* The floor's ID.
*
* @type {string}
*/
id: string,
/**
* The floor's name.
*
* @type {string}
*/
name: string,
/**
* The geometry of the floor.
*
* @type {?MPMultiPolygon}
*/
geometry: MPMultiPolygon | any,
/**
* An array of aliases used by the floor.
*
* @type {?string[]}
*/
aliases?: string[],
/**
* The floor index of the floor.
*
* @type {?number}
*/
floorIndex?: number,
/**
* The ID of the building this floor lies within.
*
* @type {?string}
*/
buildingId?: string,
entityBounds: any
}