-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPVenue.ts
294 lines (278 loc) · 7.51 KB
/
MPVenue.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
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
import { Platform } from "react-native";
import { MPPoint, MPPointParams, MPBounds, MPMapStyle, MPPolygon, MPVenueInfo, MPDataField, MPBuilding, MPLocation } from '../../index';
import MPEntity from "./MPEntity";
import MPUtils from "./MPUtils";
/**
* A MapsIndoors geographical entity. A venue can exist anywhere,
* and it can contain a number of {@link MPBuilding}s and {@link MPLocation}s.
*
* @export
* @class MPVenue
* @typedef {MPVenue}
* @extends {MPEntity}
*/
export default class MPVenue extends MPEntity {
/**
* Creates an instance of MPVenue.
*
* @constructor
* @param {string} id The venue's ID.
* @param {string} administrativeId The venue's readable ID.
* @param {string} tilesUrl The URL that is used to fetch tiles for the venue.
* @param {MPMapStyle[]} mapStyles An array of mapStyles that can be used on this venue.
* @param {MPPolygon} geometry The geometry of the venue.
* @param {number} defaultFloor The venue's defalt floor index.
* @param {MPVenueInfo} venueInfo A collection of information about the venue.
* @param {MPPoint} anchor The anchor point for the location.
* @param {MPPoint[]} entryPoints Points of entry that are used to create routes between MapsIndoors and the underlying map.
* @param {string} [externalId] An optional ID used to map the venue to a customer's ID.
* @param {?string} [graphId] The ID of the graph used to route on this venue.
*/
constructor(
public readonly id: string,
public readonly administrativeId: string,
public readonly tilesUrl: string,
public readonly mapStyles: MPMapStyle[],
public readonly geometry: MPPolygon,
public readonly defaultFloor: number,
public readonly venueInfo: MPVenueInfo,
public readonly anchor: MPPoint,
public readonly entryPoints: MPPoint[],
public readonly externalId: string,
public readonly graphId?: string,
) {
super("MPVenue");
}
/**
* Creator for MPVenue, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPVenueParams} object
* @returns {MPVenue}
*/
public static create(object: MPVenueParams): MPVenue {
var polygon;
if (Platform.OS === 'ios') {
polygon = MPPolygon.create({coordinates: object?.geometry, bbox: [].concat(object?.bbox?.northeast, object?.bbox?.southwest)});
}else {
polygon = MPPolygon.create(object?.geometry);
}
return new MPVenue(
object?.id,
object?.name,
object?.tilesUrl,
object?.styles?.map((style: any) => MPMapStyle.create(style)),
polygon,
object?.defaultFloor,
MPVenueInfo.create(object?.venueInfo),
MPPoint.create(object?.anchor),
object?.entryPoints?.map((entryPoint: any) => MPPoint.create(entryPoint)),
object?.externalId,
object?.graphId,
);
}
/**
* Get the venue's name.
*
* @public
* @readonly
* @type {string}
*/
public get name(): string {
return this.venueInfo?.name;
}
/**
* Get the venue's bounds.
*
* @public
* @readonly
* @type {MPBounds}
*/
public get bounds(): MPBounds {
return this.geometry.bounds;
}
/**
* Get the position of the venue, this will correspond to the venue's anchor point.
*
* @public
* @readonly
* @type {MPPoint}
*/
public get position(): MPPoint {
return this.anchor;
}
/**
* Inherited from {@link MPEntity}, a venue's geometry is never a {@link MPPoint}.
*
* @public
* @readonly
* @type {boolean}
*/
public get isPoint(): boolean {
return false;
}
/**
* Get the venue's default mapstyle.
*
* @public
* @readonly
* @type {MPMapStyle}
*/
public get defaultMapStyle(): MPMapStyle {
return this.mapStyles[0];
}
/**
* Fetch a field from the venue's info member.
*
* @public
* @param {?string} [key]
* @returns {(MPDataField | undefined)}
*/
public getField(key?: string): MPDataField | undefined {
if (key !== undefined) {
return this.venueInfo.fields?.get(key);
}
}
/**
* Check whether a given mapstyle is valid for the venue.
*
* @public
* @param {?MPMapStyle} [style]
* @returns {boolean}
*/
public isMapStyleValid(style?: MPMapStyle) : boolean {
if (style) {
this.mapStyles.forEach((value: MPMapStyle) => {
if (style == value) {
return true;
}
});
}
return false;
}
/**
* Check whether the venue has a valid routing graph.
*
* @public
* @async
* @returns {Promise<boolean>}
*/
public async hasGraph(): Promise<boolean> {
return MPUtils.venueHasGraph(this.id);
}
/**
* Check whether the venue contains a point.
*
* @public
* @async
* @param {MPPoint} point
* @returns {Promise<boolean>}
*/
public async contains(point: MPPoint): Promise<boolean> {
return this.geometry.contains(point);
}
/**
* Parses the object to a JSON object that is compatible with the MapsIndoors SDK.
*
* @public
* @returns {MPVenueParams}
*/
public toJSON(): MPVenueParams {
return {
id: this.id,
graphId: this.graphId,
name: this.administrativeId,
tilesUrl: this.tilesUrl,
styles: this.mapStyles,
geometry: this.geometry,
defaultFloor: this.defaultFloor,
venueInfo: this.venueInfo,
anchor: this.anchor.toJSON(),
entryPoints: this.entryPoints,
externalId: this.externalId,
}
}
}
/**
* Parameter interface for {@link MPVenue}.
*
* @export
* @interface MPVenueParams
* @typedef {MPVenueParams}
*/
export interface MPVenueParams {
/**
* The venue's ID.
*
* @type {string}
*/
id: string,
/**
* The venue's readable ID.
*
* @type {string}
*/
name: string,
/**
* An ID used to map the venue to a customer's ID.
*
* @type {?string}
*/
externalId: string,
/**
* The URL that is used to fetch tiles for the venue.
*
* @type {string}
*/
tilesUrl: string,
/**
* An array of mapStyles that can be used on this venue.
*
* @type {MPMapStyle[]}
*/
styles: MPMapStyle[],
/**
* The geometry of the venue.
*
* @type {MPPolygon}
*/
geometry: MPPolygon | any,
/**
* The venue's defalt floor index.
*
* @type {number}
*/
defaultFloor: number,
/**
* A collection of information about the venue.
*
* @type {MPVenueInfo}
*/
venueInfo: MPVenueInfo,
/**
* The anchor point for the venue.
*
* @type {MPPointParams}
*/
anchor: MPPointParams,
/**
* Points of entry that are used to create routes between MapsIndoors and the underlying map.
*
* @type {MPPoint[]}
*/
entryPoints: MPPoint[],
/**
* The ID of the graph used to route on this venue.
*
* @type {?string}
*/
graphId?: string,
/**
* A object of two arrays representing coordinates
* Northeast & Southwest
*
* @type {any}
*/
bbox?: any
}