@mapsindoors/react-native-maps-indoors-mapbox 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/LICENSE +10 -10
  2. package/README.md +187 -183
  3. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  4. package/android/.gradle/7.4/checksums/md5-checksums.bin +0 -0
  5. package/android/.gradle/7.4/checksums/sha1-checksums.bin +0 -0
  6. package/android/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock +0 -0
  7. package/android/.gradle/7.4/executionHistory/executionHistory.lock +0 -0
  8. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  9. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  10. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  11. package/android/README.md +14 -14
  12. package/android/build.gradle +166 -166
  13. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  14. package/android/gradle.properties +16 -16
  15. package/android/gradlew +234 -234
  16. package/android/src/main/AndroidManifest.xml +6 -6
  17. package/android/src/main/java/com/reactlibrary/MapboxMapView.java +116 -116
  18. package/android/src/main/java/com/reactlibrary/MapsIndoorsPackage.java +53 -53
  19. package/android/src/main/java/com/reactlibrary/MapsIndoorsViewManager.java +119 -119
  20. package/android/src/main/java/com/reactlibrary/core/DirectionsRendererModule.java +218 -208
  21. package/android/src/main/java/com/reactlibrary/core/DirectionsServiceModule.java +130 -130
  22. package/android/src/main/java/com/reactlibrary/core/MPDisplayRuleModule.java +816 -816
  23. package/android/src/main/java/com/reactlibrary/core/MapControlModule.java +636 -628
  24. package/android/src/main/java/com/reactlibrary/core/MapsIndoorsModule.java +327 -327
  25. package/android/src/main/java/com/reactlibrary/core/RCMapView.java +16 -16
  26. package/android/src/main/java/com/reactlibrary/core/README.md +92 -92
  27. package/android/src/main/java/com/reactlibrary/core/UtilsModule.java +166 -166
  28. package/android/src/main/java/com/reactlibrary/core/models/Bounds.java +19 -19
  29. package/android/src/main/java/com/reactlibrary/core/models/Filter.java +77 -77
  30. package/android/src/main/java/com/reactlibrary/core/models/Location.java +17 -17
  31. package/android/src/main/java/com/reactlibrary/core/models/MPCameraPosition.java +34 -34
  32. package/android/src/main/java/com/reactlibrary/core/models/MPCameraUpdate.java +68 -68
  33. package/android/src/main/java/com/reactlibrary/core/models/MPError.java +38 -38
  34. package/android/src/main/java/com/reactlibrary/core/models/PositionProvider.java +46 -46
  35. package/android/src/main/java/com/reactlibrary/core/models/PositionResult.java +117 -117
  36. package/android/src/main/java/com/reactlibrary/core/models/Query.java +30 -30
  37. package/android/src/main/res/values/google_maps_api_key.xml +3 -3
  38. package/android/src/main/res/values/mapbox_api_key.xml +5 -5
  39. package/index.ts +183 -183
  40. package/ios/MapsIndoors.xcodeproj/project.pbxproj +318 -318
  41. package/ios/MapsIndoors.xcworkspace/contents.xcworkspacedata +7 -7
  42. package/ios/MapsIndoors.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  43. package/ios/MapsIndoorsViewManager.swift +111 -111
  44. package/ios/MapsIndoorsViewManagerBridge.m +9 -9
  45. package/ios/core/CameraPosition.swift +15 -15
  46. package/ios/core/CameraUpdate.swift +19 -19
  47. package/ios/core/CameraUpdateError.swift +11 -11
  48. package/ios/core/DirectionsRendererBridge.m +61 -57
  49. package/ios/core/DirectionsRendererModule.swift +256 -237
  50. package/ios/core/DirectionsServiceBridge.m +46 -46
  51. package/ios/core/DirectionsServiceModule.swift +149 -149
  52. package/ios/core/MPDisplayRuleBridge.m +410 -410
  53. package/ios/core/MPDisplayRuleModule.swift +845 -845
  54. package/ios/core/MapControlBridge.m +184 -178
  55. package/ios/core/MapControlModule.swift +554 -515
  56. package/ios/core/MapsIndoorsBridge.m +116 -116
  57. package/ios/core/MapsIndoorsData.swift +218 -218
  58. package/ios/core/MapsIndoorsModule.swift +296 -296
  59. package/ios/core/RCMapView.swift +14 -14
  60. package/ios/core/README.md +92 -92
  61. package/ios/core/ReactPositionProvider.swift +25 -25
  62. package/ios/core/UtilsBridge.m +63 -63
  63. package/ios/core/UtilsModule.swift +146 -146
  64. package/ios/core/helpers.swift +57 -57
  65. package/ios/react-native-maps-indoors-Bridging-Header.h +6 -6
  66. package/package.json +53 -53
  67. package/react-native-maps-indoors-mapbox.podspec +30 -30
  68. package/src/core/EventNames.ts +20 -20
  69. package/src/core/MPBounds.ts +154 -154
  70. package/src/core/MPBuilding.ts +333 -333
  71. package/src/core/MPBuildingCollection.ts +56 -56
  72. package/src/core/MPBuildingInfo.ts +62 -62
  73. package/src/core/MPCameraEvent.ts +16 -16
  74. package/src/core/MPCameraEventListener.ts +16 -16
  75. package/src/core/MPCameraPosition.ts +82 -82
  76. package/src/core/MPCameraUpdate.ts +174 -174
  77. package/src/core/MPCameraViewFitMode.ts +20 -20
  78. package/src/core/MPCategory.ts +75 -75
  79. package/src/core/MPCategoryCollection.ts +61 -61
  80. package/src/core/MPCollection.ts +58 -58
  81. package/src/core/MPCollisionHandling.ts +11 -11
  82. package/src/core/MPDataField.ts +68 -68
  83. package/src/core/MPDirectionsRenderer.ts +205 -193
  84. package/src/core/MPDirectionsService.ts +118 -118
  85. package/src/core/MPDisplayRule.ts +1027 -1027
  86. package/src/core/MPEntity.ts +59 -59
  87. package/src/core/MPEntityInfo.ts +27 -27
  88. package/src/core/MPError.ts +122 -122
  89. package/src/core/MPFilter.ts +167 -167
  90. package/src/core/MPFilterBehavior.ts +94 -94
  91. package/src/core/MPFloor.ts +169 -169
  92. package/src/core/MPFloorSelectorInterface.ts +62 -62
  93. package/src/core/MPGeometry.ts +90 -90
  94. package/src/core/MPHighway.ts +14 -14
  95. package/src/core/MPIconSize.ts +38 -38
  96. package/src/core/MPLocation.ts +385 -385
  97. package/src/core/MPLocationPropertyNames.ts +29 -29
  98. package/src/core/MPLocationType.ts +15 -15
  99. package/src/core/MPMapConfig.ts +210 -210
  100. package/src/core/MPMapStyle.ts +56 -56
  101. package/src/core/MPMultiPolygon.ts +217 -217
  102. package/src/core/MPPoint.ts +169 -169
  103. package/src/core/MPPolygon.ts +218 -218
  104. package/src/core/MPPositionProviderInterface.ts +44 -44
  105. package/src/core/MPPositionResultInterface.ts +41 -41
  106. package/src/core/MPPropertyData.ts +214 -214
  107. package/src/core/MPQuery.ts +68 -68
  108. package/src/core/MPRoute.ts +94 -94
  109. package/src/core/MPRouteCoordinate.ts +94 -94
  110. package/src/core/MPRouteLeg.ts +127 -127
  111. package/src/core/MPRouteProperty.ts +82 -82
  112. package/src/core/MPRouteStep.ts +176 -175
  113. package/src/core/MPSelectionBehavior.ts +92 -92
  114. package/src/core/MPSettings3D.ts +106 -106
  115. package/src/core/MPSize.ts +20 -20
  116. package/src/core/MPSolution.ts +179 -179
  117. package/src/core/MPSolutionConfig.ts +126 -126
  118. package/src/core/MPSolutionDisplayRule.ts +13 -13
  119. package/src/core/MPUserRole.ts +59 -59
  120. package/src/core/MPUserRoleCollection.ts +36 -36
  121. package/src/core/MPUtils.ts +156 -156
  122. package/src/core/MPVenue.ts +293 -293
  123. package/src/core/MPVenueCollection.ts +57 -57
  124. package/src/core/MPVenueInfo.ts +61 -61
  125. package/src/core/MapControl.ts +876 -864
  126. package/src/core/MapView.tsx +33 -33
  127. package/src/core/MapsIndoors.ts +530 -530
  128. package/src/core/OnBuildingFoundAtCameraTargetListener.ts +16 -16
  129. package/src/core/OnFloorSelectionChangedListener.ts +16 -16
  130. package/src/core/OnFloorUpdateListener.ts +15 -15
  131. package/src/core/OnLegSelectedListener.ts +16 -16
  132. package/src/core/OnLiveLocationUpdateListener.ts +16 -16
  133. package/src/core/OnLocationSelectedListener.ts +16 -16
  134. package/src/core/OnMapClickListener.ts +19 -19
  135. package/src/core/OnMarkerClickListener.ts +16 -16
  136. package/src/core/OnMarkerInfoWindowClickListener.ts +16 -16
  137. package/src/core/OnPositionUpdateListener.ts +16 -16
  138. package/src/core/OnVenueFoundAtCameraTargetListener.ts +16 -16
  139. package/src/core/README.md +92 -92
  140. package/android/.gradle/7.4/executionHistory/executionHistory.bin +0 -0
  141. package/android/.gradle/7.4/fileHashes/fileHashes.bin +0 -0
  142. package/android/.gradle/7.4/fileHashes/resourceHashesCache.bin +0 -0
  143. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  144. package/android/.gradle/file-system.probe +0 -0
  145. package/android/.idea/compiler.xml +0 -6
  146. package/android/.idea/gradle.xml +0 -19
  147. package/android/.idea/jarRepositories.xml +0 -60
  148. package/android/.idea/misc.xml +0 -10
  149. package/android/.idea/vcs.xml +0 -7
  150. package/android/local.properties +0 -8
@@ -1,530 +1,530 @@
1
- import { NativeModules, Platform } from 'react-native';
2
- import {
3
- MPMapStyle,
4
- MPLocation, MPSolution, MPVenue, MPQuery, MPFilter,
5
- MPDisplayRule, MPSolutionDisplayRule, MPPositionProviderInterface,
6
- MPPositionResultInterface, MPUserRole, MPError, MPCategoryCollection, MPUserRoleCollection
7
- } from "../../index";
8
- import MPBuildingCollection from './MPBuildingCollection';
9
- import MPVenueCollection from './MPVenueCollection';
10
-
11
- const { MapsIndoorsModule } = NativeModules;
12
- /**
13
- * Main class for accessing data in the MapsIndoors SDK.
14
- *
15
- * @export
16
- * @class MapsIndoors
17
- * @typedef {MapsIndoors}
18
- */
19
- export default class MapsIndoors {
20
- /**
21
- * Creates an instance of MapsIndoors.
22
- *
23
- * @constructor
24
- * @private
25
- */
26
- private constructor() { };
27
-
28
- /**
29
- * Loads content from the MapsIndoors solution matching the given API {@link apiKey}.
30
- *
31
- * @public
32
- * @static
33
- * @async
34
- * @param {String} apiKey The key to the MapsIndoors solution.
35
- * @returns {Promise<void>} If the load fails for any reason, it will reject with a {@link MPError}.
36
- */
37
- public static async load(apiKey: String): Promise<void> {
38
- return MapsIndoorsModule.loadMapsIndoors(apiKey).catch((err: Error) =>
39
- Promise.reject(MPError.parse(err))
40
- );
41
- }
42
-
43
- /**
44
- * Gets the default venue for this solution.
45
- *
46
- * @public
47
- * @static
48
- * @async
49
- * @returns {Promise<MPVenue | undefined>}
50
- */
51
- public static async getDefaultVenue(): Promise<MPVenue | undefined> {
52
- return MapsIndoorsModule.getDefaultVenue().then((venueString: string) => {
53
- let venue = MPVenue.create(JSON.parse(venueString));
54
- return Promise.resolve(venue);
55
- }).catch((err: Error) => Promise.reject(MPError.parse(err)));
56
- }
57
-
58
- /**
59
- * Gets a collection of all venues for the current solution.
60
- *
61
- * @public
62
- * @static
63
- * @async
64
- * @returns {Promise<MPVenueCollection>}
65
- */
66
- public static async getVenues(): Promise<MPVenueCollection> {
67
- return MapsIndoorsModule.getVenues()
68
- .catch((err: Error) => {return Promise.reject(MPError.create(MPError.parse(err)))})
69
- .then((venueString: string) => {
70
- const venues: MPVenueCollection = MPVenueCollection.create(JSON.parse(venueString));
71
- return Promise.resolve(venues);
72
- });
73
- }
74
-
75
- /**
76
- * Gets a collection of all building for the current solution.
77
- *
78
- * @public
79
- * @static
80
- * @async
81
- * @returns {Promise<MPBuildingCollection>}
82
- */
83
- public static async getBuildings(): Promise<MPBuildingCollection> {
84
- return MapsIndoorsModule.getBuildings()
85
- .catch((err: Error) => Promise.reject(MPError.parse(err)))
86
- .then((buildingString: string) => {
87
- const buildings: MPBuildingCollection = MPBuildingCollection.create(JSON.parse(buildingString));
88
- return Promise.resolve(buildings);
89
- });
90
- }
91
-
92
- /**
93
- * Gets a collection of all categories for the current solution.
94
- *
95
- * @public
96
- * @static
97
- * @async
98
- * @returns {Promise<MPCategoryCollection>}
99
- */
100
- public static async getCategories(): Promise<MPCategoryCollection> {
101
- return MapsIndoorsModule.getCategories()
102
- .catch((err: Error) => Promise.reject(MPError.parse(err)))
103
- .then((categoryString: string) => {
104
- const categories: MPCategoryCollection = MPCategoryCollection.create(JSON.parse(categoryString));
105
- return Promise.resolve(categories);
106
- });
107
- }
108
-
109
- /**
110
- * Gets all locations (a list of {@link MPLocation} objects) for the current solution.
111
- *
112
- * @public
113
- * @static
114
- * @async
115
- * @returns {Promise<MPLocation[]>}
116
- */
117
- public static async getLocations(): Promise<MPLocation[]> {
118
- return MapsIndoorsModule.getLocations()
119
- .catch((err: Error) => {Promise.reject(MPError.parse(err))})
120
- .then((locationsString: string) => {
121
- const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
122
- return Promise.resolve(locations);
123
- })
124
- }
125
-
126
- /**
127
- * {@link disable} SDK event logging through MapsIndoors. No logs will be created or send with this disabled.
128
- *
129
- * By default it is enabled. But disabled in the CMS meaning logs will be created but never uploaded.
130
- *
131
- * @public
132
- * @static
133
- * @async
134
- * @param {boolean} disable
135
- * @returns {Promise<void>}
136
- */
137
- public static async disableEventLogging(disable: boolean): Promise<void> {
138
- return MapsIndoorsModule.disableEventLogging(disable).then(() => Promise.resolve());
139
- }
140
-
141
- /**
142
- * Retrieves the API key that was set when calling {@link load}.
143
- *
144
- * Will return empty string if no key has been set.
145
- *
146
- * @public
147
- * @static
148
- * @async
149
- * @returns {Promise<string>}
150
- */
151
- public static async getApiKey(): Promise<string> {
152
- return MapsIndoorsModule.getApiKey();
153
- }
154
-
155
- /**
156
- * Returns a list of the current solution's available languages.
157
- *
158
- * @public
159
- * @static
160
- * @async
161
- * @returns {Promise<string[]>}
162
- */
163
- public static async getAvailableLanguages(): Promise<string[]> {
164
- return MapsIndoorsModule.getAvailableLanguages()
165
- .catch((err: Error) => Promise.reject(MPError.parse(err)));
166
- }
167
-
168
- /**
169
- * Returns the default language for the current solution.
170
- *
171
- * @public
172
- * @static
173
- * @async
174
- * @returns {Promise<string>}
175
- */
176
- public static async getDefaultLanguage(): Promise<string> {
177
- return MapsIndoorsModule.getDefaultLanguage();
178
- }
179
-
180
- /**
181
- * Gets the language currently used in the SDK.
182
- *
183
- * @public
184
- * @static
185
- * @async
186
- * @returns {Promise<string>}
187
- */
188
- public static async getLanguage(): Promise<string> {
189
- return MapsIndoorsModule.getLanguage();
190
- }
191
-
192
- /**
193
- * Retrieves a {@link MPLocation} by its {@link id}.
194
- *
195
- * @public
196
- * @static
197
- * @async
198
- * @param {string} id
199
- * @returns {Promise<MPLocation | undefined>}
200
- */
201
- public static async getLocationById(id: string): Promise<MPLocation | undefined> {
202
- return MapsIndoorsModule.getLocationById(id).then((locationString: string | undefined | null) => {
203
- if (locationString) {
204
- const location: MPLocation = MPLocation.create(JSON.parse(locationString));
205
- return Promise.resolve(location);
206
- } else {
207
- return Promise.resolve(undefined);
208
- }
209
- });
210
- }
211
-
212
- /**
213
- * Retrieves a list of {@link MPLocation}s by {@link externalIds}.
214
- *
215
- * @public
216
- * @static
217
- * @async
218
- * @param {string[]} externalIds
219
- * @returns {Promise<MPLocation[]>}
220
- */
221
- public static async getLocationsByExternalIds(externalIds: string[]): Promise<MPLocation[]> {
222
- return MapsIndoorsModule.getLocationsByExternalIds(externalIds).then((locationsString: string) => {
223
- const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
224
- return Promise.resolve(locations);
225
- });
226
- }
227
-
228
- /**
229
- * Gets a collection of available map styles.
230
- *
231
- * @public
232
- * @static
233
- * @async
234
- * @returns {Promise<MPMapStyle[]>}
235
- */
236
- public static async getMapStyles(): Promise<MPMapStyle[]> {
237
- return MapsIndoorsModule.getMapStyles().then((mapStylesString: string) => {
238
- const mapStyles: MPMapStyle[] = JSON.parse(mapStylesString).map((mapStyle: any) => MPMapStyle.create(mapStyle));
239
- return Promise.resolve(mapStyles);
240
- });
241
- }
242
-
243
- /**
244
- * Gets the {@link MPSolution} for the current loaded api key.
245
- *
246
- * @public
247
- * @static
248
- * @async
249
- * @returns {Promise<MPSolution>}
250
- */
251
- public static async getSolution(): Promise<MPSolution> {
252
- return MapsIndoorsModule.getSolution().then((solutionString: string) => {
253
- const solution: MPSolution = MPSolution.create(JSON.parse(solutionString));
254
- return Promise.resolve(solution);
255
- });
256
- }
257
-
258
- /**
259
- * Run a query on all available locations with a query and filter.
260
- *
261
- * @public
262
- * @static
263
- * @async
264
- * @param {MPQuery} query
265
- * @param {MPFilter} filter
266
- * @returns {Promise<MPLocation[]>}
267
- */
268
- public static async getLocationsAsync(query: MPQuery, filter: MPFilter): Promise<MPLocation[]> {
269
- return MapsIndoorsModule.getLocationsAsync(JSON.stringify(query), JSON.stringify(filter))
270
- .then((locationsString: string) => {
271
- const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) =>
272
- MPLocation.create(location));
273
- return Promise.resolve(locations);
274
- }).catch((err: Error) => Promise.reject(MPError.parse(err)));
275
- }
276
-
277
- /**
278
- * Retrieve the display rule for the given {@link location}.
279
- *
280
- * Requires that {@link load} has successfully executed.
281
- *
282
- * @public
283
- * @static
284
- * @async
285
- * @param {MPLocation} location
286
- * @returns {Promise<MPDisplayRule | undefined>}
287
- */
288
- public static async getDisplayRuleByLocation(location: MPLocation): Promise<MPDisplayRule | undefined> {
289
- return MapsIndoorsModule.locationDisplayRuleExists(location.id).then((exists: boolean) => {
290
- return Promise.resolve(exists ? MPDisplayRule.create({ "id": location.id }) : undefined);
291
- });
292
- }
293
-
294
- /**
295
- * Retrieve the display rule with a given [@link name}.
296
- *
297
- * Requires that {@link load} has successfully executed.
298
- *
299
- * @public
300
- * @static
301
- * @async
302
- * @param {string} name The ID of the DisplayRule
303
- * @returns {Promise<MPDisplayRule>}
304
- */
305
- public static async getDisplayRuleByName(name: string): Promise<MPDisplayRule> {
306
- return MapsIndoorsModule.displayRuleNameExists(name).then((exists: boolean) => {
307
- return Promise.resolve(exists ? MPDisplayRule.create({ "id": name }) : undefined);
308
- });
309
- }
310
-
311
- /**
312
- * Retrieve the main display rule (can be configured in the CMS).
313
- *
314
- * Requires that {@link load} has successfully executed.
315
- *
316
- * @public
317
- * @static
318
- * @async
319
- * @returns {Promise<MPDisplayRule>}
320
- */
321
- public static async getMainDisplayRule(): Promise<MPDisplayRule> {
322
- return Promise.resolve(MPDisplayRule.create({"id": "main"}));
323
- }
324
-
325
- /**
326
- * Retrieve the corresponding display rule for the given {@link MPSolutionDisplayRule}.
327
- *
328
- * Requires that {@link load} has successfully executed.
329
- *
330
- * @public
331
- * @static
332
- * @async
333
- * @param {MPSolutionDisplayRule} solutionDisplayRule
334
- * @returns {Promise<MPDisplayRule>}
335
- */
336
- public static async getSolutionDisplayRule(solutionDisplayRule: MPSolutionDisplayRule): Promise<MPDisplayRule> {
337
- return Promise.resolve(MPDisplayRule.create({"id": solutionDisplayRule}));
338
- }
339
-
340
- /**
341
- * Retrieve the default display rule (fallback rule in case the main rule has not loaded/ has errors).
342
- *
343
- * @public
344
- * @static
345
- * @async
346
- * @returns {Promise<MPDisplayRule>}
347
- */
348
- public static async getDefaultDisplayRule(): Promise<MPDisplayRule> {
349
- return Promise.resolve(MPDisplayRule.create({"id": "default"}));
350
- }
351
-
352
-
353
- /**
354
- * Set a new position provider, or pass undefined to remove the current one.
355
- *
356
- * @public
357
- * @static
358
- * @async
359
- * @param {MPPositionProviderInterface} positonProvider
360
- * @returns {Promise<void>}
361
- */
362
- public static async setPositionProvider(positonProvider?: MPPositionProviderInterface): Promise<void> {
363
- if (positonProvider) {
364
- const positionUpdateListener = (position: MPPositionResultInterface) => {
365
- if (Platform.OS === 'ios') {
366
- let obj = {
367
- coordinate: [position.point.longitude, position.point.latitude, position.floorIndex],
368
- floorIndex: position.floorIndex,
369
- bearing: position.bearing,
370
- accuracy: position.accuracy,
371
- providerName: position.positionProvider
372
- }
373
- MapsIndoorsModule.onPositionUpdate(JSON.stringify(obj));
374
- }else {
375
- MapsIndoorsModule.onPositionUpdate(JSON.stringify(position));
376
- }
377
- };
378
-
379
- positonProvider.addOnPositionUpdateListener(positionUpdateListener);
380
- return MapsIndoorsModule.setPositionProvider(positonProvider.name).then(() => { });
381
- } else {
382
- return MapsIndoorsModule.removePositionProvider().then(() => { });
383
- }
384
- }
385
-
386
- /**
387
- * Gets the User Roles for the current solution.
388
- *
389
- * Note that role names are localized.
390
- *
391
- * @public
392
- * @static
393
- * @async
394
- * @returns {Promise<MPUserRoleCollection>}
395
- */
396
- public static async getUserRoles(): Promise<MPUserRoleCollection> {
397
- return MapsIndoorsModule.getUserRoles().then((userRolesString: string) => {
398
- const userRoles: MPUserRoleCollection = MPUserRoleCollection.create(JSON.parse(userRolesString));
399
- return Promise.resolve(userRoles);
400
- }).catch((err: string) => Promise.reject(MPError.create(JSON.parse(err))));
401
- }
402
-
403
- /**
404
- * Checks if there is on device data (embedded/locally stored) available. For this to return true,
405
- * data has to be available for all solution data types ({@link MPLocation}, {@link MPBuilding}...).
406
- *
407
- * Returns true if data is available, otherwise returns false.
408
- *
409
- * @public
410
- * @static
411
- * @async
412
- * @returns {Promise<boolean>}
413
- */
414
- public static async checkOfflineDataAvailability(): Promise<boolean> {
415
- return MapsIndoorsModule.checkOfflineDataAvailability();
416
- }
417
-
418
- /**
419
- * Clears the internal state of MapsIndoors SDK. Any loaded content is purged from memory.
420
- *
421
- * Invoke {@link load} to start the SDK anew.
422
- *
423
- * @public
424
- * @static
425
- * @async
426
- * @returns {Promise<void>}
427
- */
428
- public static async destroy(): Promise<void> {
429
- return MapsIndoorsModule.destroy().then(() => { });
430
- }
431
-
432
- /**
433
- * Check if the current API key is valid.
434
- *
435
- * @public
436
- * @static
437
- * @async
438
- * @returns {Promise<boolean>}
439
- */
440
- public static async isApiKeyValid(): Promise<boolean> {
441
- return MapsIndoorsModule.isApiKeyValid();
442
- }
443
-
444
- /**
445
- * Check if {@link load} has been called.
446
- *
447
- * @public
448
- * @static
449
- * @async
450
- * @returns {Promise<boolean>}
451
- */
452
- public static async isInitialized(): Promise<boolean> {
453
- return MapsIndoorsModule.isInitialized();
454
- }
455
-
456
- /**
457
- * Check if the SDK is initialized and ready for use.
458
- *
459
- * @public
460
- * @static
461
- * @async
462
- * @returns {Promise<boolean>}
463
- */
464
- public static async isReady(): Promise<boolean> {
465
- return MapsIndoorsModule.isReady();
466
- }
467
-
468
- /**
469
- * Sets the SDK's internal language.
470
- *
471
- * By default, the SDK language can be:
472
- *
473
- * * the solution's default language ({@link MPSolutionInfo#getDefaultLanguage()}).
474
- * * the current device language, if the MapsIndoors data isn't available (ie: first app run without network access).
475
- *
476
- * @public
477
- * @static
478
- * @async
479
- * @param {string} language
480
- * @returns {Promise<boolean>}
481
- */
482
- public static async setLanguage(language: string): Promise<boolean> {
483
- return MapsIndoorsModule.setLanguage(language);
484
- }
485
-
486
- /**
487
- * Main data synchronization method.
488
- *
489
- * If not manually invoked, [MapControl.create(config, listener)] will invoke it.
490
- *
491
- * @public
492
- * @static
493
- * @async
494
- * @returns {Promise<void>}
495
- */
496
- public static async synchronizeContent(): Promise<void> {
497
- return MapsIndoorsModule.synchronizeContent().catch((err: Error) => {
498
- return Promise.reject(MPError.parse(err));
499
- });
500
- }
501
-
502
- /**
503
- * Applies a list of {@link MPUserRole}s to the SDK which will get the UserRole specific locations..
504
- *
505
- * @public
506
- * @static
507
- * @async
508
- * @param {MPUserRole[]} userRoles
509
- * @returns {Promise<void>}
510
- */
511
- public static async applyUserRoles(userRoles: MPUserRole[]): Promise<void> {
512
- return MapsIndoorsModule.applyUserRoles(JSON.stringify(userRoles));
513
- }
514
-
515
- /**
516
- * Returns the list of {@link MPUserRole}s that is currently applied.
517
- *
518
- * @public
519
- * @static
520
- * @async
521
- * @returns {Promise<MPUserRole[]>}
522
- */
523
- public static async getAppliedUserRoles(): Promise<MPUserRole[]> {
524
- return MapsIndoorsModule.getAppliedUserRoles().then((userRolesString: string) => {
525
- const userRoles: MPUserRole[] = JSON.parse(userRolesString).map((userRole: any) => MPUserRole.create(userRole));
526
- return Promise.resolve(userRoles);
527
- });
528
- }
529
-
530
- }
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import {
3
+ MPMapStyle,
4
+ MPLocation, MPSolution, MPVenue, MPQuery, MPFilter,
5
+ MPDisplayRule, MPSolutionDisplayRule, MPPositionProviderInterface,
6
+ MPPositionResultInterface, MPUserRole, MPError, MPCategoryCollection, MPUserRoleCollection
7
+ } from "../../index";
8
+ import MPBuildingCollection from './MPBuildingCollection';
9
+ import MPVenueCollection from './MPVenueCollection';
10
+
11
+ const { MapsIndoorsModule } = NativeModules;
12
+ /**
13
+ * Main class for accessing data in the MapsIndoors SDK.
14
+ *
15
+ * @export
16
+ * @class MapsIndoors
17
+ * @typedef {MapsIndoors}
18
+ */
19
+ export default class MapsIndoors {
20
+ /**
21
+ * Creates an instance of MapsIndoors.
22
+ *
23
+ * @constructor
24
+ * @private
25
+ */
26
+ private constructor() { };
27
+
28
+ /**
29
+ * Loads content from the MapsIndoors solution matching the given API {@link apiKey}.
30
+ *
31
+ * @public
32
+ * @static
33
+ * @async
34
+ * @param {String} apiKey The key to the MapsIndoors solution.
35
+ * @returns {Promise<void>} If the load fails for any reason, it will reject with a {@link MPError}.
36
+ */
37
+ public static async load(apiKey: String): Promise<void> {
38
+ return MapsIndoorsModule.loadMapsIndoors(apiKey).catch((err: Error) =>
39
+ Promise.reject(MPError.parse(err))
40
+ );
41
+ }
42
+
43
+ /**
44
+ * Gets the default venue for this solution.
45
+ *
46
+ * @public
47
+ * @static
48
+ * @async
49
+ * @returns {Promise<MPVenue | undefined>}
50
+ */
51
+ public static async getDefaultVenue(): Promise<MPVenue | undefined> {
52
+ return MapsIndoorsModule.getDefaultVenue().then((venueString: string) => {
53
+ let venue = MPVenue.create(JSON.parse(venueString));
54
+ return Promise.resolve(venue);
55
+ }).catch((err: Error) => Promise.reject(MPError.parse(err)));
56
+ }
57
+
58
+ /**
59
+ * Gets a collection of all venues for the current solution.
60
+ *
61
+ * @public
62
+ * @static
63
+ * @async
64
+ * @returns {Promise<MPVenueCollection>}
65
+ */
66
+ public static async getVenues(): Promise<MPVenueCollection> {
67
+ return MapsIndoorsModule.getVenues()
68
+ .catch((err: Error) => {return Promise.reject(MPError.create(MPError.parse(err)))})
69
+ .then((venueString: string) => {
70
+ const venues: MPVenueCollection = MPVenueCollection.create(JSON.parse(venueString));
71
+ return Promise.resolve(venues);
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Gets a collection of all building for the current solution.
77
+ *
78
+ * @public
79
+ * @static
80
+ * @async
81
+ * @returns {Promise<MPBuildingCollection>}
82
+ */
83
+ public static async getBuildings(): Promise<MPBuildingCollection> {
84
+ return MapsIndoorsModule.getBuildings()
85
+ .catch((err: Error) => Promise.reject(MPError.parse(err)))
86
+ .then((buildingString: string) => {
87
+ const buildings: MPBuildingCollection = MPBuildingCollection.create(JSON.parse(buildingString));
88
+ return Promise.resolve(buildings);
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Gets a collection of all categories for the current solution.
94
+ *
95
+ * @public
96
+ * @static
97
+ * @async
98
+ * @returns {Promise<MPCategoryCollection>}
99
+ */
100
+ public static async getCategories(): Promise<MPCategoryCollection> {
101
+ return MapsIndoorsModule.getCategories()
102
+ .catch((err: Error) => Promise.reject(MPError.parse(err)))
103
+ .then((categoryString: string) => {
104
+ const categories: MPCategoryCollection = MPCategoryCollection.create(JSON.parse(categoryString));
105
+ return Promise.resolve(categories);
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Gets all locations (a list of {@link MPLocation} objects) for the current solution.
111
+ *
112
+ * @public
113
+ * @static
114
+ * @async
115
+ * @returns {Promise<MPLocation[]>}
116
+ */
117
+ public static async getLocations(): Promise<MPLocation[]> {
118
+ return MapsIndoorsModule.getLocations()
119
+ .catch((err: Error) => {Promise.reject(MPError.parse(err))})
120
+ .then((locationsString: string) => {
121
+ const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
122
+ return Promise.resolve(locations);
123
+ })
124
+ }
125
+
126
+ /**
127
+ * {@link disable} SDK event logging through MapsIndoors. No logs will be created or send with this disabled.
128
+ *
129
+ * By default it is enabled. But disabled in the CMS meaning logs will be created but never uploaded.
130
+ *
131
+ * @public
132
+ * @static
133
+ * @async
134
+ * @param {boolean} disable
135
+ * @returns {Promise<void>}
136
+ */
137
+ public static async disableEventLogging(disable: boolean): Promise<void> {
138
+ return MapsIndoorsModule.disableEventLogging(disable).then(() => Promise.resolve());
139
+ }
140
+
141
+ /**
142
+ * Retrieves the API key that was set when calling {@link load}.
143
+ *
144
+ * Will return empty string if no key has been set.
145
+ *
146
+ * @public
147
+ * @static
148
+ * @async
149
+ * @returns {Promise<string>}
150
+ */
151
+ public static async getApiKey(): Promise<string> {
152
+ return MapsIndoorsModule.getApiKey();
153
+ }
154
+
155
+ /**
156
+ * Returns a list of the current solution's available languages.
157
+ *
158
+ * @public
159
+ * @static
160
+ * @async
161
+ * @returns {Promise<string[]>}
162
+ */
163
+ public static async getAvailableLanguages(): Promise<string[]> {
164
+ return MapsIndoorsModule.getAvailableLanguages()
165
+ .catch((err: Error) => Promise.reject(MPError.parse(err)));
166
+ }
167
+
168
+ /**
169
+ * Returns the default language for the current solution.
170
+ *
171
+ * @public
172
+ * @static
173
+ * @async
174
+ * @returns {Promise<string>}
175
+ */
176
+ public static async getDefaultLanguage(): Promise<string> {
177
+ return MapsIndoorsModule.getDefaultLanguage();
178
+ }
179
+
180
+ /**
181
+ * Gets the language currently used in the SDK.
182
+ *
183
+ * @public
184
+ * @static
185
+ * @async
186
+ * @returns {Promise<string>}
187
+ */
188
+ public static async getLanguage(): Promise<string> {
189
+ return MapsIndoorsModule.getLanguage();
190
+ }
191
+
192
+ /**
193
+ * Retrieves a {@link MPLocation} by its {@link id}.
194
+ *
195
+ * @public
196
+ * @static
197
+ * @async
198
+ * @param {string} id
199
+ * @returns {Promise<MPLocation | undefined>}
200
+ */
201
+ public static async getLocationById(id: string): Promise<MPLocation | undefined> {
202
+ return MapsIndoorsModule.getLocationById(id).then((locationString: string | undefined | null) => {
203
+ if (locationString) {
204
+ const location: MPLocation = MPLocation.create(JSON.parse(locationString));
205
+ return Promise.resolve(location);
206
+ } else {
207
+ return Promise.resolve(undefined);
208
+ }
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Retrieves a list of {@link MPLocation}s by {@link externalIds}.
214
+ *
215
+ * @public
216
+ * @static
217
+ * @async
218
+ * @param {string[]} externalIds
219
+ * @returns {Promise<MPLocation[]>}
220
+ */
221
+ public static async getLocationsByExternalIds(externalIds: string[]): Promise<MPLocation[]> {
222
+ return MapsIndoorsModule.getLocationsByExternalIds(externalIds).then((locationsString: string) => {
223
+ const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
224
+ return Promise.resolve(locations);
225
+ });
226
+ }
227
+
228
+ /**
229
+ * Gets a collection of available map styles.
230
+ *
231
+ * @public
232
+ * @static
233
+ * @async
234
+ * @returns {Promise<MPMapStyle[]>}
235
+ */
236
+ public static async getMapStyles(): Promise<MPMapStyle[]> {
237
+ return MapsIndoorsModule.getMapStyles().then((mapStylesString: string) => {
238
+ const mapStyles: MPMapStyle[] = JSON.parse(mapStylesString).map((mapStyle: any) => MPMapStyle.create(mapStyle));
239
+ return Promise.resolve(mapStyles);
240
+ });
241
+ }
242
+
243
+ /**
244
+ * Gets the {@link MPSolution} for the current loaded api key.
245
+ *
246
+ * @public
247
+ * @static
248
+ * @async
249
+ * @returns {Promise<MPSolution>}
250
+ */
251
+ public static async getSolution(): Promise<MPSolution> {
252
+ return MapsIndoorsModule.getSolution().then((solutionString: string) => {
253
+ const solution: MPSolution = MPSolution.create(JSON.parse(solutionString));
254
+ return Promise.resolve(solution);
255
+ });
256
+ }
257
+
258
+ /**
259
+ * Run a query on all available locations with a query and filter.
260
+ *
261
+ * @public
262
+ * @static
263
+ * @async
264
+ * @param {MPQuery} query
265
+ * @param {MPFilter} filter
266
+ * @returns {Promise<MPLocation[]>}
267
+ */
268
+ public static async getLocationsAsync(query: MPQuery, filter: MPFilter): Promise<MPLocation[]> {
269
+ return MapsIndoorsModule.getLocationsAsync(JSON.stringify(query), JSON.stringify(filter))
270
+ .then((locationsString: string) => {
271
+ const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) =>
272
+ MPLocation.create(location));
273
+ return Promise.resolve(locations);
274
+ }).catch((err: Error) => Promise.reject(MPError.parse(err)));
275
+ }
276
+
277
+ /**
278
+ * Retrieve the display rule for the given {@link location}.
279
+ *
280
+ * Requires that {@link load} has successfully executed.
281
+ *
282
+ * @public
283
+ * @static
284
+ * @async
285
+ * @param {MPLocation} location
286
+ * @returns {Promise<MPDisplayRule | undefined>}
287
+ */
288
+ public static async getDisplayRuleByLocation(location: MPLocation): Promise<MPDisplayRule | undefined> {
289
+ return MapsIndoorsModule.locationDisplayRuleExists(location.id).then((exists: boolean) => {
290
+ return Promise.resolve(exists ? MPDisplayRule.create({ "id": location.id }) : undefined);
291
+ });
292
+ }
293
+
294
+ /**
295
+ * Retrieve the display rule with a given [@link name}.
296
+ *
297
+ * Requires that {@link load} has successfully executed.
298
+ *
299
+ * @public
300
+ * @static
301
+ * @async
302
+ * @param {string} name The ID of the DisplayRule
303
+ * @returns {Promise<MPDisplayRule>}
304
+ */
305
+ public static async getDisplayRuleByName(name: string): Promise<MPDisplayRule> {
306
+ return MapsIndoorsModule.displayRuleNameExists(name).then((exists: boolean) => {
307
+ return Promise.resolve(exists ? MPDisplayRule.create({ "id": name }) : undefined);
308
+ });
309
+ }
310
+
311
+ /**
312
+ * Retrieve the main display rule (can be configured in the CMS).
313
+ *
314
+ * Requires that {@link load} has successfully executed.
315
+ *
316
+ * @public
317
+ * @static
318
+ * @async
319
+ * @returns {Promise<MPDisplayRule>}
320
+ */
321
+ public static async getMainDisplayRule(): Promise<MPDisplayRule> {
322
+ return Promise.resolve(MPDisplayRule.create({"id": "main"}));
323
+ }
324
+
325
+ /**
326
+ * Retrieve the corresponding display rule for the given {@link MPSolutionDisplayRule}.
327
+ *
328
+ * Requires that {@link load} has successfully executed.
329
+ *
330
+ * @public
331
+ * @static
332
+ * @async
333
+ * @param {MPSolutionDisplayRule} solutionDisplayRule
334
+ * @returns {Promise<MPDisplayRule>}
335
+ */
336
+ public static async getSolutionDisplayRule(solutionDisplayRule: MPSolutionDisplayRule): Promise<MPDisplayRule> {
337
+ return Promise.resolve(MPDisplayRule.create({"id": solutionDisplayRule}));
338
+ }
339
+
340
+ /**
341
+ * Retrieve the default display rule (fallback rule in case the main rule has not loaded/ has errors).
342
+ *
343
+ * @public
344
+ * @static
345
+ * @async
346
+ * @returns {Promise<MPDisplayRule>}
347
+ */
348
+ public static async getDefaultDisplayRule(): Promise<MPDisplayRule> {
349
+ return Promise.resolve(MPDisplayRule.create({"id": "default"}));
350
+ }
351
+
352
+
353
+ /**
354
+ * Set a new position provider, or pass undefined to remove the current one.
355
+ *
356
+ * @public
357
+ * @static
358
+ * @async
359
+ * @param {MPPositionProviderInterface} positonProvider
360
+ * @returns {Promise<void>}
361
+ */
362
+ public static async setPositionProvider(positonProvider?: MPPositionProviderInterface): Promise<void> {
363
+ if (positonProvider) {
364
+ const positionUpdateListener = (position: MPPositionResultInterface) => {
365
+ if (Platform.OS === 'ios') {
366
+ let obj = {
367
+ coordinate: [position.point.longitude, position.point.latitude, position.floorIndex],
368
+ floorIndex: position.floorIndex,
369
+ bearing: position.bearing,
370
+ accuracy: position.accuracy,
371
+ providerName: position.positionProvider
372
+ }
373
+ MapsIndoorsModule.onPositionUpdate(JSON.stringify(obj));
374
+ }else {
375
+ MapsIndoorsModule.onPositionUpdate(JSON.stringify(position));
376
+ }
377
+ };
378
+
379
+ positonProvider.addOnPositionUpdateListener(positionUpdateListener);
380
+ return MapsIndoorsModule.setPositionProvider(positonProvider.name).then(() => { });
381
+ } else {
382
+ return MapsIndoorsModule.removePositionProvider().then(() => { });
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Gets the User Roles for the current solution.
388
+ *
389
+ * Note that role names are localized.
390
+ *
391
+ * @public
392
+ * @static
393
+ * @async
394
+ * @returns {Promise<MPUserRoleCollection>}
395
+ */
396
+ public static async getUserRoles(): Promise<MPUserRoleCollection> {
397
+ return MapsIndoorsModule.getUserRoles().then((userRolesString: string) => {
398
+ const userRoles: MPUserRoleCollection = MPUserRoleCollection.create(JSON.parse(userRolesString));
399
+ return Promise.resolve(userRoles);
400
+ }).catch((err: string) => Promise.reject(MPError.create(JSON.parse(err))));
401
+ }
402
+
403
+ /**
404
+ * Checks if there is on device data (embedded/locally stored) available. For this to return true,
405
+ * data has to be available for all solution data types ({@link MPLocation}, {@link MPBuilding}...).
406
+ *
407
+ * Returns true if data is available, otherwise returns false.
408
+ *
409
+ * @public
410
+ * @static
411
+ * @async
412
+ * @returns {Promise<boolean>}
413
+ */
414
+ public static async checkOfflineDataAvailability(): Promise<boolean> {
415
+ return MapsIndoorsModule.checkOfflineDataAvailability();
416
+ }
417
+
418
+ /**
419
+ * Clears the internal state of MapsIndoors SDK. Any loaded content is purged from memory.
420
+ *
421
+ * Invoke {@link load} to start the SDK anew.
422
+ *
423
+ * @public
424
+ * @static
425
+ * @async
426
+ * @returns {Promise<void>}
427
+ */
428
+ public static async destroy(): Promise<void> {
429
+ return MapsIndoorsModule.destroy().then(() => { });
430
+ }
431
+
432
+ /**
433
+ * Check if the current API key is valid.
434
+ *
435
+ * @public
436
+ * @static
437
+ * @async
438
+ * @returns {Promise<boolean>}
439
+ */
440
+ public static async isApiKeyValid(): Promise<boolean> {
441
+ return MapsIndoorsModule.isApiKeyValid();
442
+ }
443
+
444
+ /**
445
+ * Check if {@link load} has been called.
446
+ *
447
+ * @public
448
+ * @static
449
+ * @async
450
+ * @returns {Promise<boolean>}
451
+ */
452
+ public static async isInitialized(): Promise<boolean> {
453
+ return MapsIndoorsModule.isInitialized();
454
+ }
455
+
456
+ /**
457
+ * Check if the SDK is initialized and ready for use.
458
+ *
459
+ * @public
460
+ * @static
461
+ * @async
462
+ * @returns {Promise<boolean>}
463
+ */
464
+ public static async isReady(): Promise<boolean> {
465
+ return MapsIndoorsModule.isReady();
466
+ }
467
+
468
+ /**
469
+ * Sets the SDK's internal language.
470
+ *
471
+ * By default, the SDK language can be:
472
+ *
473
+ * * the solution's default language ({@link MPSolutionInfo#getDefaultLanguage()}).
474
+ * * the current device language, if the MapsIndoors data isn't available (ie: first app run without network access).
475
+ *
476
+ * @public
477
+ * @static
478
+ * @async
479
+ * @param {string} language
480
+ * @returns {Promise<boolean>}
481
+ */
482
+ public static async setLanguage(language: string): Promise<boolean> {
483
+ return MapsIndoorsModule.setLanguage(language);
484
+ }
485
+
486
+ /**
487
+ * Main data synchronization method.
488
+ *
489
+ * If not manually invoked, [MapControl.create(config, listener)] will invoke it.
490
+ *
491
+ * @public
492
+ * @static
493
+ * @async
494
+ * @returns {Promise<void>}
495
+ */
496
+ public static async synchronizeContent(): Promise<void> {
497
+ return MapsIndoorsModule.synchronizeContent().catch((err: Error) => {
498
+ return Promise.reject(MPError.parse(err));
499
+ });
500
+ }
501
+
502
+ /**
503
+ * Applies a list of {@link MPUserRole}s to the SDK which will get the UserRole specific locations..
504
+ *
505
+ * @public
506
+ * @static
507
+ * @async
508
+ * @param {MPUserRole[]} userRoles
509
+ * @returns {Promise<void>}
510
+ */
511
+ public static async applyUserRoles(userRoles: MPUserRole[]): Promise<void> {
512
+ return MapsIndoorsModule.applyUserRoles(JSON.stringify(userRoles));
513
+ }
514
+
515
+ /**
516
+ * Returns the list of {@link MPUserRole}s that is currently applied.
517
+ *
518
+ * @public
519
+ * @static
520
+ * @async
521
+ * @returns {Promise<MPUserRole[]>}
522
+ */
523
+ public static async getAppliedUserRoles(): Promise<MPUserRole[]> {
524
+ return MapsIndoorsModule.getAppliedUserRoles().then((userRolesString: string) => {
525
+ const userRoles: MPUserRole[] = JSON.parse(userRolesString).map((userRole: any) => MPUserRole.create(userRole));
526
+ return Promise.resolve(userRoles);
527
+ });
528
+ }
529
+
530
+ }