-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPVenueCollection.ts
58 lines (54 loc) · 1.54 KB
/
MPVenueCollection.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
import MPCollection from "./MPCollection";
import MPVenue from "./MPVenue";
/**
* Description placeholder.
*
* @export
* @class MPVenueCollection
* @typedef {MPVenueCollection}
* @extends {MPCollection<MPVenue>}
*/
export default class MPVenueCollection extends MPCollection<MPVenue> {
/**
* Internal.
*
* Map between administrative ID and venues.
*
* @private
* @type {!Map<String, MPVenue>}
*/
private adminIdMap!: Map<String, MPVenue>;
/**
* Creates an instance of MPVenueCollection.
*
* @constructor
* @private
* @param {MPVenue[]} venues A collection of venues used in MapsIndoors.
*/
private constructor(venues: MPVenue[]) {
super();
this.map = new Map(venues.map((venue) => [venue.id, venue]));
this.adminIdMap = new Map(venues.map((venue) => [venue.administrativeId.toLowerCase(), venue]));
}
/**
* Fetch a venue by its administrative id.
*
* @public
* @param {string} id
* @returns {(MPVenue | undefined)}
*/
public getVenueByAdminId(id: string) : MPVenue | undefined {
return this.adminIdMap.get(id.toLowerCase());
}
/**
* Creator for MPVenueCollection, used to decode JSON from the MapsIndoors SDK.
*
* @static
* @param {?*} [object]
* @returns {MPVenueCollection}
*/
static create(object?: any) : MPVenueCollection {
let venues: MPVenue[] = object?.map((venue: any) => MPVenue.create(venue));
return new MPVenueCollection(venues);
}
}