-
Notifications
You must be signed in to change notification settings - Fork 1
/
MapsIndoors.ts
530 lines (494 loc) · 16.9 KB
/
MapsIndoors.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
import { NativeModules, Platform } from 'react-native';
import {
MPMapStyle,
MPLocation, MPSolution, MPVenue, MPQuery, MPFilter,
MPDisplayRule, MPSolutionDisplayRule, MPPositionProviderInterface,
MPPositionResultInterface, MPUserRole, MPError, MPCategoryCollection, MPUserRoleCollection
} from "../../index";
import MPBuildingCollection from './MPBuildingCollection';
import MPVenueCollection from './MPVenueCollection';
const { MapsIndoorsModule } = NativeModules;
/**
* Main class for accessing data in the MapsIndoors SDK.
*
* @export
* @class MapsIndoors
* @typedef {MapsIndoors}
*/
export default class MapsIndoors {
/**
* Creates an instance of MapsIndoors.
*
* @constructor
* @private
*/
private constructor() { };
/**
* Loads content from the MapsIndoors solution matching the given API {@link apiKey}.
*
* @public
* @static
* @async
* @param {String} apiKey The key to the MapsIndoors solution.
* @returns {Promise<void>} If the load fails for any reason, it will reject with a {@link MPError}.
*/
public static async load(apiKey: String): Promise<void> {
return MapsIndoorsModule.loadMapsIndoors(apiKey).catch((err: Error) =>
Promise.reject(MPError.parse(err))
);
}
/**
* Gets the default venue for this solution.
*
* @public
* @static
* @async
* @returns {Promise<MPVenue | undefined>}
*/
public static async getDefaultVenue(): Promise<MPVenue | undefined> {
return MapsIndoorsModule.getDefaultVenue().then((venueString: string) => {
let venue = MPVenue.create(JSON.parse(venueString));
return Promise.resolve(venue);
}).catch((err: Error) => Promise.reject(MPError.parse(err)));
}
/**
* Gets a collection of all venues for the current solution.
*
* @public
* @static
* @async
* @returns {Promise<MPVenueCollection>}
*/
public static async getVenues(): Promise<MPVenueCollection> {
return MapsIndoorsModule.getVenues()
.catch((err: Error) => {return Promise.reject(MPError.create(MPError.parse(err)))})
.then((venueString: string) => {
const venues: MPVenueCollection = MPVenueCollection.create(JSON.parse(venueString));
return Promise.resolve(venues);
});
}
/**
* Gets a collection of all building for the current solution.
*
* @public
* @static
* @async
* @returns {Promise<MPBuildingCollection>}
*/
public static async getBuildings(): Promise<MPBuildingCollection> {
return MapsIndoorsModule.getBuildings()
.catch((err: Error) => Promise.reject(MPError.parse(err)))
.then((buildingString: string) => {
const buildings: MPBuildingCollection = MPBuildingCollection.create(JSON.parse(buildingString));
return Promise.resolve(buildings);
});
}
/**
* Gets a collection of all categories for the current solution.
*
* @public
* @static
* @async
* @returns {Promise<MPCategoryCollection>}
*/
public static async getCategories(): Promise<MPCategoryCollection> {
return MapsIndoorsModule.getCategories()
.catch((err: Error) => Promise.reject(MPError.parse(err)))
.then((categoryString: string) => {
const categories: MPCategoryCollection = MPCategoryCollection.create(JSON.parse(categoryString));
return Promise.resolve(categories);
});
}
/**
* Gets all locations (a list of {@link MPLocation} objects) for the current solution.
*
* @public
* @static
* @async
* @returns {Promise<MPLocation[]>}
*/
public static async getLocations(): Promise<MPLocation[]> {
return MapsIndoorsModule.getLocations()
.catch((err: Error) => {Promise.reject(MPError.parse(err))})
.then((locationsString: string) => {
const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
return Promise.resolve(locations);
})
}
/**
* {@link disable} SDK event logging through MapsIndoors. No logs will be created or send with this disabled.
*
* By default it is enabled. But disabled in the CMS meaning logs will be created but never uploaded.
*
* @public
* @static
* @async
* @param {boolean} disable
* @returns {Promise<void>}
*/
public static async disableEventLogging(disable: boolean): Promise<void> {
return MapsIndoorsModule.disableEventLogging(disable).then(() => Promise.resolve());
}
/**
* Retrieves the API key that was set when calling {@link load}.
*
* Will return empty string if no key has been set.
*
* @public
* @static
* @async
* @returns {Promise<string>}
*/
public static async getApiKey(): Promise<string> {
return MapsIndoorsModule.getApiKey();
}
/**
* Returns a list of the current solution's available languages.
*
* @public
* @static
* @async
* @returns {Promise<string[]>}
*/
public static async getAvailableLanguages(): Promise<string[]> {
return MapsIndoorsModule.getAvailableLanguages()
.catch((err: Error) => Promise.reject(MPError.parse(err)));
}
/**
* Returns the default language for the current solution.
*
* @public
* @static
* @async
* @returns {Promise<string>}
*/
public static async getDefaultLanguage(): Promise<string> {
return MapsIndoorsModule.getDefaultLanguage();
}
/**
* Gets the language currently used in the SDK.
*
* @public
* @static
* @async
* @returns {Promise<string>}
*/
public static async getLanguage(): Promise<string> {
return MapsIndoorsModule.getLanguage();
}
/**
* Retrieves a {@link MPLocation} by its {@link id}.
*
* @public
* @static
* @async
* @param {string} id
* @returns {Promise<MPLocation | undefined>}
*/
public static async getLocationById(id: string): Promise<MPLocation | undefined> {
return MapsIndoorsModule.getLocationById(id).then((locationString: string | undefined | null) => {
if (locationString) {
const location: MPLocation = MPLocation.create(JSON.parse(locationString));
return Promise.resolve(location);
} else {
return Promise.resolve(undefined);
}
});
}
/**
* Retrieves a list of {@link MPLocation}s by {@link externalIds}.
*
* @public
* @static
* @async
* @param {string[]} externalIds
* @returns {Promise<MPLocation[]>}
*/
public static async getLocationsByExternalIds(externalIds: string[]): Promise<MPLocation[]> {
return MapsIndoorsModule.getLocationsByExternalIds(externalIds).then((locationsString: string) => {
const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
return Promise.resolve(locations);
});
}
/**
* Gets a collection of available map styles.
*
* @public
* @static
* @async
* @returns {Promise<MPMapStyle[]>}
*/
public static async getMapStyles(): Promise<MPMapStyle[]> {
return MapsIndoorsModule.getMapStyles().then((mapStylesString: string) => {
const mapStyles: MPMapStyle[] = JSON.parse(mapStylesString).map((mapStyle: any) => MPMapStyle.create(mapStyle));
return Promise.resolve(mapStyles);
});
}
/**
* Gets the {@link MPSolution} for the current loaded api key.
*
* @public
* @static
* @async
* @returns {Promise<MPSolution>}
*/
public static async getSolution(): Promise<MPSolution> {
return MapsIndoorsModule.getSolution().then((solutionString: string) => {
const solution: MPSolution = MPSolution.create(JSON.parse(solutionString));
return Promise.resolve(solution);
});
}
/**
* Run a query on all available locations with a query and filter.
*
* @public
* @static
* @async
* @param {MPQuery} query
* @param {MPFilter} filter
* @returns {Promise<MPLocation[]>}
*/
public static async getLocationsAsync(query: MPQuery, filter: MPFilter): Promise<MPLocation[]> {
return MapsIndoorsModule.getLocationsAsync(JSON.stringify(query), JSON.stringify(filter))
.then((locationsString: string) => {
const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) =>
MPLocation.create(location));
return Promise.resolve(locations);
}).catch((err: Error) => Promise.reject(MPError.parse(err)));
}
/**
* Retrieve the display rule for the given {@link location}.
*
* Requires that {@link load} has successfully executed.
*
* @public
* @static
* @async
* @param {MPLocation} location
* @returns {Promise<MPDisplayRule | undefined>}
*/
public static async getDisplayRuleByLocation(location: MPLocation): Promise<MPDisplayRule | undefined> {
return MapsIndoorsModule.locationDisplayRuleExists(location.id).then((exists: boolean) => {
return Promise.resolve(exists ? MPDisplayRule.create({ "id": location.id }) : undefined);
});
}
/**
* Retrieve the display rule with a given [@link name}.
*
* Requires that {@link load} has successfully executed.
*
* @public
* @static
* @async
* @param {string} name The ID of the DisplayRule
* @returns {Promise<MPDisplayRule>}
*/
public static async getDisplayRuleByName(name: string): Promise<MPDisplayRule> {
return MapsIndoorsModule.displayRuleNameExists(name).then((exists: boolean) => {
return Promise.resolve(exists ? MPDisplayRule.create({ "id": name }) : undefined);
});
}
/**
* Retrieve the main display rule (can be configured in the CMS).
*
* Requires that {@link load} has successfully executed.
*
* @public
* @static
* @async
* @returns {Promise<MPDisplayRule>}
*/
public static async getMainDisplayRule(): Promise<MPDisplayRule> {
return Promise.resolve(MPDisplayRule.create({"id": "main"}));
}
/**
* Retrieve the corresponding display rule for the given {@link MPSolutionDisplayRule}.
*
* Requires that {@link load} has successfully executed.
*
* @public
* @static
* @async
* @param {MPSolutionDisplayRule} solutionDisplayRule
* @returns {Promise<MPDisplayRule>}
*/
public static async getSolutionDisplayRule(solutionDisplayRule: MPSolutionDisplayRule): Promise<MPDisplayRule> {
return Promise.resolve(MPDisplayRule.create({"id": solutionDisplayRule}));
}
/**
* Retrieve the default display rule (fallback rule in case the main rule has not loaded/ has errors).
*
* @public
* @static
* @async
* @returns {Promise<MPDisplayRule>}
*/
public static async getDefaultDisplayRule(): Promise<MPDisplayRule> {
return Promise.resolve(MPDisplayRule.create({"id": "default"}));
}
/**
* Set a new position provider, or pass undefined to remove the current one.
*
* @public
* @static
* @async
* @param {MPPositionProviderInterface} positonProvider
* @returns {Promise<void>}
*/
public static async setPositionProvider(positonProvider?: MPPositionProviderInterface): Promise<void> {
if (positonProvider) {
const positionUpdateListener = (position: MPPositionResultInterface) => {
if (Platform.OS === 'ios') {
let obj = {
coordinate: [position.point.longitude, position.point.latitude, position.floorIndex],
floorIndex: position.floorIndex,
bearing: position.bearing,
accuracy: position.accuracy,
providerName: position.positionProvider
}
MapsIndoorsModule.onPositionUpdate(JSON.stringify(obj));
}else {
MapsIndoorsModule.onPositionUpdate(JSON.stringify(position));
}
};
positonProvider.addOnPositionUpdateListener(positionUpdateListener);
return MapsIndoorsModule.setPositionProvider(positonProvider.name).then(() => { });
} else {
return MapsIndoorsModule.removePositionProvider().then(() => { });
}
}
/**
* Gets the User Roles for the current solution.
*
* Note that role names are localized.
*
* @public
* @static
* @async
* @returns {Promise<MPUserRoleCollection>}
*/
public static async getUserRoles(): Promise<MPUserRoleCollection> {
return MapsIndoorsModule.getUserRoles().then((userRolesString: string) => {
const userRoles: MPUserRoleCollection = MPUserRoleCollection.create(JSON.parse(userRolesString));
return Promise.resolve(userRoles);
}).catch((err: string) => Promise.reject(MPError.create(JSON.parse(err))));
}
/**
* Checks if there is on device data (embedded/locally stored) available. For this to return true,
* data has to be available for all solution data types ({@link MPLocation}, {@link MPBuilding}...).
*
* Returns true if data is available, otherwise returns false.
*
* @public
* @static
* @async
* @returns {Promise<boolean>}
*/
public static async checkOfflineDataAvailability(): Promise<boolean> {
return MapsIndoorsModule.checkOfflineDataAvailability();
}
/**
* Clears the internal state of MapsIndoors SDK. Any loaded content is purged from memory.
*
* Invoke {@link load} to start the SDK anew.
*
* @public
* @static
* @async
* @returns {Promise<void>}
*/
public static async destroy(): Promise<void> {
return MapsIndoorsModule.destroy().then(() => { });
}
/**
* Check if the current API key is valid.
*
* @public
* @static
* @async
* @returns {Promise<boolean>}
*/
public static async isApiKeyValid(): Promise<boolean> {
return MapsIndoorsModule.isApiKeyValid();
}
/**
* Check if {@link load} has been called.
*
* @public
* @static
* @async
* @returns {Promise<boolean>}
*/
public static async isInitialized(): Promise<boolean> {
return MapsIndoorsModule.isInitialized();
}
/**
* Check if the SDK is initialized and ready for use.
*
* @public
* @static
* @async
* @returns {Promise<boolean>}
*/
public static async isReady(): Promise<boolean> {
return MapsIndoorsModule.isReady();
}
/**
* Sets the SDK's internal language.
*
* By default, the SDK language can be:
*
* * the solution's default language ({@link MPSolutionInfo#getDefaultLanguage()}).
* * the current device language, if the MapsIndoors data isn't available (ie: first app run without network access).
*
* @public
* @static
* @async
* @param {string} language
* @returns {Promise<boolean>}
*/
public static async setLanguage(language: string): Promise<boolean> {
return MapsIndoorsModule.setLanguage(language);
}
/**
* Main data synchronization method.
*
* If not manually invoked, [MapControl.create(config, listener)] will invoke it.
*
* @public
* @static
* @async
* @returns {Promise<void>}
*/
public static async synchronizeContent(): Promise<void> {
return MapsIndoorsModule.synchronizeContent().catch((err: Error) => {
return Promise.reject(MPError.parse(err));
});
}
/**
* Applies a list of {@link MPUserRole}s to the SDK which will get the UserRole specific locations..
*
* @public
* @static
* @async
* @param {MPUserRole[]} userRoles
* @returns {Promise<void>}
*/
public static async applyUserRoles(userRoles: MPUserRole[]): Promise<void> {
return MapsIndoorsModule.applyUserRoles(JSON.stringify(userRoles));
}
/**
* Returns the list of {@link MPUserRole}s that is currently applied.
*
* @public
* @static
* @async
* @returns {Promise<MPUserRole[]>}
*/
public static async getAppliedUserRoles(): Promise<MPUserRole[]> {
return MapsIndoorsModule.getAppliedUserRoles().then((userRolesString: string) => {
const userRoles: MPUserRole[] = JSON.parse(userRolesString).map((userRole: any) => MPUserRole.create(userRole));
return Promise.resolve(userRoles);
});
}
}