@mapsindoors/react-native-maps-indoors-mapbox 2.8.1-rc.1 → 2.9.0
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.
- package/README.md +84 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
- package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
- package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
- package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
- package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
- package/index.ts +25 -0
- package/ios/.swift-format +79 -0
- package/ios/core/DirectionsRendererBridge.m +11 -0
- package/ios/core/DirectionsRendererModule.swift +162 -1
- package/ios/core/DirectionsRendererOptions.swift +352 -0
- package/ios/core/MapsIndoorsBridge.m +14 -1
- package/ios/core/MapsIndoorsData.swift +1 -0
- package/ios/core/MapsIndoorsModule.swift +180 -21
- package/ios/core/UtilsModule.swift +57 -45
- package/package.json +1 -1
- package/react-native-maps-indoors-mapbox.podspec +2 -2
- package/specs/NativeDirectionsRendererModule.ts +3 -0
- package/specs/NativeMapsIndoorsModule.ts +6 -1
- package/src/core/EventNames.ts +3 -0
- package/src/core/MPDirectionsRenderer.ts +76 -1
- package/src/core/MPDirectionsRendererOptions.ts +287 -0
- package/src/core/MPError.ts +48 -1
- package/src/core/MPLanguageTag.ts +222 -0
- package/src/core/MPLegBoundaryIcons.ts +130 -0
- package/src/core/MPRouteAnimationType.ts +24 -0
- package/src/core/MPRouteArrowStyle.ts +28 -0
- package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
- package/src/core/MPRouteStampType.ts +24 -0
- package/src/core/MPSolution.ts +33 -2
- package/src/core/MPStrokeStyle.ts +22 -0
- package/src/core/MapsIndoors.ts +155 -11
- package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
- package/src/core/__tests__/MPBounds.test.ts +109 -0
- package/src/core/__tests__/MPFilter.test.ts +76 -0
- package/src/core/__tests__/MPLanguageTag.test.ts +168 -0
- package/src/core/__tests__/MPPoint.test.ts +82 -0
- package/src/core/__tests__/MPSolution.test.ts +107 -0
- package/src/core/__tests__/MapsIndoors.language.test.ts +180 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The animation applied to the overlay travelling along the route polyline.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @enum {string}
|
|
6
|
+
*/
|
|
7
|
+
export enum MPRouteAnimationType {
|
|
8
|
+
/**
|
|
9
|
+
* No travelling animation, only the static styled route line is drawn.
|
|
10
|
+
*/
|
|
11
|
+
none = "none",
|
|
12
|
+
/**
|
|
13
|
+
* The overlay is revealed progressively along the route, then repeats.
|
|
14
|
+
*/
|
|
15
|
+
flow = "flow",
|
|
16
|
+
/**
|
|
17
|
+
* The overlay blinks in place, oscillating its opacity.
|
|
18
|
+
*/
|
|
19
|
+
pulse = "pulse",
|
|
20
|
+
/**
|
|
21
|
+
* A short bright segment travels along the route, then repeats.
|
|
22
|
+
*/
|
|
23
|
+
comet = "comet",
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in arrow shape drawn when the stamp type is {@link MPRouteStampType.arrow}.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @enum {string}
|
|
6
|
+
*/
|
|
7
|
+
export enum MPRouteArrowStyle {
|
|
8
|
+
/**
|
|
9
|
+
* A single chevron pointing along the route.
|
|
10
|
+
*/
|
|
11
|
+
chevron = "chevron",
|
|
12
|
+
/**
|
|
13
|
+
* Two stacked chevrons pointing along the route.
|
|
14
|
+
*/
|
|
15
|
+
chevronDouble = "chevronDouble",
|
|
16
|
+
/**
|
|
17
|
+
* A solid triangle pointing along the route.
|
|
18
|
+
*/
|
|
19
|
+
triangle = "triangle",
|
|
20
|
+
/**
|
|
21
|
+
* A shaft with an arrowhead, pointing along the route.
|
|
22
|
+
*/
|
|
23
|
+
arrow = "arrow",
|
|
24
|
+
/**
|
|
25
|
+
* A solid navigation dart pointing along the route.
|
|
26
|
+
*/
|
|
27
|
+
dart = "dart",
|
|
28
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import MPSize from "./MPSize";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Styling for the origin (start) or destination (end) marker of a rendered route.
|
|
5
|
+
*
|
|
6
|
+
* Assigned to {@link MPDirectionsRendererOptionsParams.startDisplayRule} or
|
|
7
|
+
* {@link MPDirectionsRendererOptionsParams.endDisplayRule}.
|
|
8
|
+
*
|
|
9
|
+
* Every property is optional, an omitted property is inherited from the solution
|
|
10
|
+
* configuration, or from the built-in default. There is no built-in icon, so a
|
|
11
|
+
* terminus marker is only drawn when an {@link iconUrl} is configured.
|
|
12
|
+
*
|
|
13
|
+
* @export
|
|
14
|
+
* @class MPRouteMarkerDisplayRule
|
|
15
|
+
* @typedef {MPRouteMarkerDisplayRule}
|
|
16
|
+
*/
|
|
17
|
+
export default class MPRouteMarkerDisplayRule {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of MPRouteMarkerDisplayRule.
|
|
21
|
+
*
|
|
22
|
+
* @constructor
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private constructor(
|
|
26
|
+
public readonly iconUrl?: string,
|
|
27
|
+
public readonly iconVisible?: boolean,
|
|
28
|
+
public readonly iconSize?: MPSize,
|
|
29
|
+
public readonly label?: string,
|
|
30
|
+
public readonly labelVisible?: boolean,
|
|
31
|
+
public readonly labelTextSize?: number,
|
|
32
|
+
public readonly labelTextColor?: string,
|
|
33
|
+
public readonly labelHaloColor?: string,
|
|
34
|
+
public readonly labelHaloWidth?: number,
|
|
35
|
+
public readonly zoomFrom?: number,
|
|
36
|
+
public readonly zoomTo?: number,
|
|
37
|
+
) { }
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creator for MPRouteMarkerDisplayRule.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
* @static
|
|
44
|
+
* @param {MPRouteMarkerDisplayRuleParams} object
|
|
45
|
+
* @returns {MPRouteMarkerDisplayRule}
|
|
46
|
+
*/
|
|
47
|
+
public static create(object: MPRouteMarkerDisplayRuleParams): MPRouteMarkerDisplayRule {
|
|
48
|
+
return new MPRouteMarkerDisplayRule(
|
|
49
|
+
object?.iconUrl,
|
|
50
|
+
object?.iconVisible,
|
|
51
|
+
object?.iconSize,
|
|
52
|
+
object?.label,
|
|
53
|
+
object?.labelVisible,
|
|
54
|
+
object?.labelTextSize,
|
|
55
|
+
object?.labelTextColor,
|
|
56
|
+
object?.labelHaloColor,
|
|
57
|
+
object?.labelHaloWidth,
|
|
58
|
+
object?.zoomFrom,
|
|
59
|
+
object?.zoomTo,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Parameter interface for {@link MPRouteMarkerDisplayRule}.
|
|
66
|
+
*
|
|
67
|
+
* @export
|
|
68
|
+
* @interface MPRouteMarkerDisplayRuleParams
|
|
69
|
+
* @typedef {MPRouteMarkerDisplayRuleParams}
|
|
70
|
+
*/
|
|
71
|
+
export interface MPRouteMarkerDisplayRuleParams {
|
|
72
|
+
/**
|
|
73
|
+
* Media library URL of the marker icon, which the SDK downloads and caches.
|
|
74
|
+
*
|
|
75
|
+
* @type {?string}
|
|
76
|
+
*/
|
|
77
|
+
iconUrl?: string,
|
|
78
|
+
/**
|
|
79
|
+
* Whether the icon is shown. Shown by default when an {@link iconUrl} is set.
|
|
80
|
+
*
|
|
81
|
+
* @type {?boolean}
|
|
82
|
+
*/
|
|
83
|
+
iconVisible?: boolean,
|
|
84
|
+
/**
|
|
85
|
+
* The on screen size of the icon, in density independent units - points on iOS, dp on
|
|
86
|
+
* Android. Not raw pixels: the SDKs scale by the screen's density, so the same value is the
|
|
87
|
+
* same physical size on a 2x or 3x screen. Defaults to the icon's intrinsic size.
|
|
88
|
+
*
|
|
89
|
+
* @type {?MPSize}
|
|
90
|
+
*/
|
|
91
|
+
iconSize?: MPSize,
|
|
92
|
+
/**
|
|
93
|
+
* The text drawn with the marker.
|
|
94
|
+
*
|
|
95
|
+
* @type {?string}
|
|
96
|
+
*/
|
|
97
|
+
label?: string,
|
|
98
|
+
/**
|
|
99
|
+
* Whether the label is shown. Shown by default when a {@link label} is set.
|
|
100
|
+
*
|
|
101
|
+
* @type {?boolean}
|
|
102
|
+
*/
|
|
103
|
+
labelVisible?: boolean,
|
|
104
|
+
/**
|
|
105
|
+
* The label's text size, in density independent units - points on iOS, dp on Android.
|
|
106
|
+
*
|
|
107
|
+
* @type {?number}
|
|
108
|
+
*/
|
|
109
|
+
labelTextSize?: number,
|
|
110
|
+
/**
|
|
111
|
+
* The label's text color, given as a hex string (e.g. "#3071D9").
|
|
112
|
+
*
|
|
113
|
+
* @type {?string}
|
|
114
|
+
*/
|
|
115
|
+
labelTextColor?: string,
|
|
116
|
+
/**
|
|
117
|
+
* The label's halo (outline) color, given as a hex string (e.g. "#FFFFFF").
|
|
118
|
+
*
|
|
119
|
+
* @type {?string}
|
|
120
|
+
*/
|
|
121
|
+
labelHaloColor?: string,
|
|
122
|
+
/**
|
|
123
|
+
* The label's halo (outline) width, in density independent units - points on iOS, dp on Android.
|
|
124
|
+
*
|
|
125
|
+
* @type {?number}
|
|
126
|
+
*/
|
|
127
|
+
labelHaloWidth?: number,
|
|
128
|
+
/**
|
|
129
|
+
* The lowest zoom level at which the marker is shown.
|
|
130
|
+
*
|
|
131
|
+
* @type {?number}
|
|
132
|
+
*/
|
|
133
|
+
zoomFrom?: number,
|
|
134
|
+
/**
|
|
135
|
+
* The highest zoom level at which the marker is shown.
|
|
136
|
+
*
|
|
137
|
+
* @type {?number}
|
|
138
|
+
*/
|
|
139
|
+
zoomTo?: number,
|
|
140
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The repeating marker drawn along the route polyline.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @enum {string}
|
|
6
|
+
*/
|
|
7
|
+
export enum MPRouteStampType {
|
|
8
|
+
/**
|
|
9
|
+
* No stamp, only the route line and any animation is drawn.
|
|
10
|
+
*/
|
|
11
|
+
none = "none",
|
|
12
|
+
/**
|
|
13
|
+
* A built-in direction indicating arrow, repeated along the line.
|
|
14
|
+
*
|
|
15
|
+
* The shape is chosen with {@link MPRouteArrowStyle}.
|
|
16
|
+
*/
|
|
17
|
+
arrow = "arrow",
|
|
18
|
+
/**
|
|
19
|
+
* A custom icon, repeated along the line.
|
|
20
|
+
*
|
|
21
|
+
* The icon is set with {@link MPDirectionsRendererOptionsParams.stampImageUrl}.
|
|
22
|
+
*/
|
|
23
|
+
custom = "custom",
|
|
24
|
+
}
|
package/src/core/MPSolution.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MPSolutionConfig } from "../../index";
|
|
2
|
+
import { resolveLanguageTag } from "./MPLanguageTag";
|
|
2
3
|
import MPPOIType from "./MPPOIType";
|
|
3
4
|
import MPUtils from "./MPUtils";
|
|
4
5
|
|
|
@@ -66,12 +67,42 @@ export default class MPSolution {
|
|
|
66
67
|
/**
|
|
67
68
|
* Check if the solution supports a language.
|
|
68
69
|
*
|
|
70
|
+
* Matching follows BCP-47 / RFC 4647 rather than string equality, so the tag does not have to
|
|
71
|
+
* be spelled exactly the way the CMS spells it. Casing is ignored (`zh-hant` matches
|
|
72
|
+
* `zh-Hant`), the ICU underscore form is accepted (`zh_Hans`), legacy region-only Chinese tags
|
|
73
|
+
* resolve to their script (`zh-CN` matches `zh-Hans`, `zh-TW` matches `zh-Hant`), and a more
|
|
74
|
+
* specific tag falls back to a less specific one (`en-US` matches `en`).
|
|
75
|
+
*
|
|
76
|
+
* Deliberately conservative about ambiguity: bare `zh` does **not** match a solution that
|
|
77
|
+
* advertises only `zh-Hans` and `zh-Hant`, because there is no way to tell which script is
|
|
78
|
+
* wanted. Pass the script explicitly in that case.
|
|
79
|
+
*
|
|
80
|
+
* `true` means the tag is safe to pass to {@link MapsIndoors.setLanguage}. `false` is not a
|
|
81
|
+
* guarantee that `setLanguage` will reject it - see that method for what its boolean means on
|
|
82
|
+
* each platform.
|
|
83
|
+
*
|
|
69
84
|
* @public
|
|
70
|
-
* @param {?string} [language]
|
|
85
|
+
* @param {?string} [language] A BCP-47 language tag, for example `en`, `zh-Hans` or `zh-CN`.
|
|
71
86
|
* @returns {boolean}
|
|
72
87
|
*/
|
|
73
88
|
public hasLanguage(language?: string): boolean {
|
|
74
|
-
return
|
|
89
|
+
return this.resolveLanguage(language) !== undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Resolve a language tag to the exact tag this solution advertises.
|
|
94
|
+
*
|
|
95
|
+
* The companion to {@link hasLanguage}, for when a yes or no is not enough: given a device
|
|
96
|
+
* locale, this returns the tag to hand to {@link MapsIndoors.setLanguage}, spelled the way the
|
|
97
|
+
* CMS spells it. `resolveLanguage("zh-Hant-TW")` returns `"zh-Hant"` for a solution that
|
|
98
|
+
* publishes it.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
* @param {?string} [language] A BCP-47 language tag, for example `en`, `zh-Hans` or `zh-CN`.
|
|
102
|
+
* @returns {(string | undefined)} The matching advertised tag, or undefined if there is none.
|
|
103
|
+
*/
|
|
104
|
+
public resolveLanguage(language?: string): string | undefined {
|
|
105
|
+
return resolveLanguageTag(language, this.availableLanguages);
|
|
75
106
|
}
|
|
76
107
|
|
|
77
108
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the route polyline is drawn.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @enum {string}
|
|
6
|
+
*/
|
|
7
|
+
export enum MPStrokeStyle {
|
|
8
|
+
/**
|
|
9
|
+
* A continuous line. Supported by all map providers.
|
|
10
|
+
*/
|
|
11
|
+
solid = "solid",
|
|
12
|
+
/**
|
|
13
|
+
* A dashed line.
|
|
14
|
+
*
|
|
15
|
+
* Not supported by Google Maps on iOS, where it falls back to {@link MPStrokeStyle.solid}.
|
|
16
|
+
*/
|
|
17
|
+
dashed = "dashed",
|
|
18
|
+
/**
|
|
19
|
+
* A dotted line. Supported by all map providers.
|
|
20
|
+
*/
|
|
21
|
+
dotted = "dotted",
|
|
22
|
+
}
|
package/src/core/MapsIndoors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeModules, Platform } from 'react-native';
|
|
1
|
+
import { EmitterSubscription, NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
2
2
|
import {
|
|
3
3
|
MPMapStyle,
|
|
4
4
|
MPLocation, MPSolution, MPVenue, MPQuery, MPFilter,
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
} from "../../index";
|
|
8
8
|
import MPBuildingCollection from './MPBuildingCollection';
|
|
9
9
|
import MPVenueCollection from './MPVenueCollection';
|
|
10
|
+
import { EventNames } from './EventNames';
|
|
11
|
+
import { OnBaseMapCacheProgressListener } from './OnBaseMapCacheProgressListener';
|
|
10
12
|
|
|
11
13
|
const { MapsIndoorsModule } = NativeModules;
|
|
12
14
|
/**
|
|
@@ -117,7 +119,7 @@ export default class MapsIndoors {
|
|
|
117
119
|
*/
|
|
118
120
|
public static async getLocations(): Promise<MPLocation[]> {
|
|
119
121
|
return MapsIndoorsModule.getLocations()
|
|
120
|
-
.catch((err: Error) =>
|
|
122
|
+
.catch((err: Error) => Promise.reject(MPError.parse(err)))
|
|
121
123
|
.then((locationsString: string) => {
|
|
122
124
|
const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
|
|
123
125
|
return Promise.resolve(locations);
|
|
@@ -175,7 +177,8 @@ export default class MapsIndoors {
|
|
|
175
177
|
* @returns {Promise<string>}
|
|
176
178
|
*/
|
|
177
179
|
public static async getDefaultLanguage(): Promise<string> {
|
|
178
|
-
return MapsIndoorsModule.getDefaultLanguage()
|
|
180
|
+
return MapsIndoorsModule.getDefaultLanguage()
|
|
181
|
+
.catch((err: Error) => Promise.reject(MPError.parse(err)));
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
/**
|
|
@@ -187,6 +190,9 @@ export default class MapsIndoors {
|
|
|
187
190
|
* @returns {Promise<string>}
|
|
188
191
|
*/
|
|
189
192
|
public static async getLanguage(): Promise<string> {
|
|
193
|
+
// No MPError mapping on purpose: neither native has a reject path here. iOS resolves a
|
|
194
|
+
// non-optional String and Android a @NonNull one, both with their own fallback chain, so a
|
|
195
|
+
// catch would be dead code.
|
|
190
196
|
return MapsIndoorsModule.getLanguage();
|
|
191
197
|
}
|
|
192
198
|
|
|
@@ -250,10 +256,12 @@ export default class MapsIndoors {
|
|
|
250
256
|
* @returns {Promise<MPSolution>}
|
|
251
257
|
*/
|
|
252
258
|
public static async getSolution(): Promise<MPSolution> {
|
|
253
|
-
return MapsIndoorsModule.getSolution()
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
return MapsIndoorsModule.getSolution()
|
|
260
|
+
.catch((err: Error) => Promise.reject(MPError.parse(err)))
|
|
261
|
+
.then((solutionString: string) => {
|
|
262
|
+
const solution: MPSolution = MPSolution.create(JSON.parse(solutionString));
|
|
263
|
+
return Promise.resolve(solution);
|
|
264
|
+
});
|
|
257
265
|
}
|
|
258
266
|
|
|
259
267
|
/**
|
|
@@ -469,18 +477,48 @@ export default class MapsIndoors {
|
|
|
469
477
|
/**
|
|
470
478
|
* Sets the SDK's internal language.
|
|
471
479
|
*
|
|
472
|
-
*
|
|
480
|
+
* The tag should be one the solution advertises - see {@link getAvailableLanguages} - and is
|
|
481
|
+
* matched loosely: casing is ignored, and legacy region-only Chinese tags resolve to their
|
|
482
|
+
* script, so `zh-CN` selects `zh-Hans` and `zh-TW` selects `zh-Hant`. Use
|
|
483
|
+
* {@link MPSolution.hasLanguage} to check a tag before calling, or
|
|
484
|
+
* {@link MPSolution.resolveLanguage} to turn a device locale into the exact tag the solution
|
|
485
|
+
* publishes.
|
|
486
|
+
*
|
|
487
|
+
* Until this is called, the SDK language is:
|
|
473
488
|
*
|
|
474
|
-
* * the solution's default language
|
|
475
|
-
* * the current device language, if the MapsIndoors data isn't available (ie: first app run
|
|
489
|
+
* * the solution's default language - see {@link getDefaultLanguage}.
|
|
490
|
+
* * the current device language, if the MapsIndoors data isn't available (ie: first app run
|
|
491
|
+
* without network access).
|
|
492
|
+
*
|
|
493
|
+
* The returned boolean does not mean the same thing on both platforms, and an app should not
|
|
494
|
+
* branch on it without reading this:
|
|
495
|
+
*
|
|
496
|
+
* * On **Android** it is `false` when the tag does not resolve against the solution's
|
|
497
|
+
* available languages, and also when the SDK has no solution yet or is mid-
|
|
498
|
+
* {@link synchronizeContent}. In that second case the change is *queued* and applied once
|
|
499
|
+
* the SDK is ready, so `false` is not "it will never take effect".
|
|
500
|
+
* * On **iOS** it reports only that the tag was accepted; there is no check against the
|
|
501
|
+
* solution's available languages, so in the default configuration it is `true` for any
|
|
502
|
+
* non-empty tag. An unsupported language is reconciled later, on the next solution fetch,
|
|
503
|
+
* which reverts the SDK to the solution's default.
|
|
504
|
+
*
|
|
505
|
+
* A `false` here is therefore a reliable "this did not take effect" signal on Android only. To
|
|
506
|
+
* confirm the language actually changed on either platform, read it back with
|
|
507
|
+
* {@link getLanguage}.
|
|
508
|
+
*
|
|
509
|
+
* An empty or whitespace-only tag resolves `false` without reaching the native SDK, matching
|
|
510
|
+
* Android's own precondition. iOS would otherwise accept it and store an empty language.
|
|
476
511
|
*
|
|
477
512
|
* @public
|
|
478
513
|
* @static
|
|
479
514
|
* @async
|
|
480
|
-
* @param {string} language
|
|
515
|
+
* @param {string} language A BCP-47 language tag, for example `en`, `zh-Hans` or `zh-CN`.
|
|
481
516
|
* @returns {Promise<boolean>}
|
|
482
517
|
*/
|
|
483
518
|
public static async setLanguage(language: string): Promise<boolean> {
|
|
519
|
+
if (!language?.trim()) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
484
522
|
return MapsIndoorsModule.setLanguage(language);
|
|
485
523
|
}
|
|
486
524
|
|
|
@@ -568,4 +606,110 @@ export default class MapsIndoors {
|
|
|
568
606
|
public static async cacheData(apiKey: String): Promise<boolean> {
|
|
569
607
|
return MapsIndoorsModule.cacheData(apiKey);
|
|
570
608
|
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Checks whether the map provider in use can cache base-map tiles at all.
|
|
612
|
+
*
|
|
613
|
+
* Base-map tiles are the outdoor map rendered underneath MapsIndoors, and they live in the map
|
|
614
|
+
* provider's own storage - separate from the MapsIndoors content cached by {@link cacheData}.
|
|
615
|
+
* Only the Mapbox provider can cache them; on the Google Maps provider this returns false and
|
|
616
|
+
* every other base-map caching call rejects with {@link MPError.baseMapCachingNotSupported}.
|
|
617
|
+
*
|
|
618
|
+
* Check this before offering offline base maps in the UI, so an unsupported provider fails fast
|
|
619
|
+
* instead of once per venue.
|
|
620
|
+
*
|
|
621
|
+
* @public
|
|
622
|
+
* @static
|
|
623
|
+
* @async
|
|
624
|
+
* @returns {Promise<boolean>} True if base-map tiles can be cached.
|
|
625
|
+
*/
|
|
626
|
+
public static async isBaseMapCachingSupported(): Promise<boolean> {
|
|
627
|
+
return MapsIndoorsModule.isBaseMapCachingSupported();
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Enables or disables base-map tile caching for the solution matching the given {@link apiKey}.
|
|
632
|
+
*
|
|
633
|
+
* The flag only marks the solution, it downloads nothing - call
|
|
634
|
+
* {@link synchronizeBaseMapTiles} for that. Turning it off does not remove already-cached
|
|
635
|
+
* tiles either; those are reclaimed when the solution's cache is removed.
|
|
636
|
+
*
|
|
637
|
+
* The flag is persisted, so it survives an app restart and only has to be set once.
|
|
638
|
+
*
|
|
639
|
+
* It is a property of the solution, not of the map provider, so it is accepted and stored even
|
|
640
|
+
* where {@link isBaseMapCachingSupported} is false - on Google Maps this resolves successfully
|
|
641
|
+
* and sets a flag nothing can act on, and only {@link synchronizeBaseMapTiles} reports
|
|
642
|
+
* {@link MPError.baseMapCachingNotSupported}. Check {@link isBaseMapCachingSupported} first if
|
|
643
|
+
* you need to know before then. Rejecting here instead would make the same call behave
|
|
644
|
+
* differently per map provider, which is worse for code meant to run against either.
|
|
645
|
+
*
|
|
646
|
+
* @public
|
|
647
|
+
* @static
|
|
648
|
+
* @async
|
|
649
|
+
* @param {boolean} enabled True to cache base-map tiles for this solution.
|
|
650
|
+
* @param {string} apiKey The key to the MapsIndoors solution.
|
|
651
|
+
* @returns {Promise<void>} If the solution is not managed, or the call fails for any other
|
|
652
|
+
* reason, it will reject with a {@link MPError}.
|
|
653
|
+
*/
|
|
654
|
+
public static async setBaseMapTilesEnabled(enabled: boolean, apiKey: string): Promise<void> {
|
|
655
|
+
return MapsIndoorsModule.setBaseMapTilesEnabled(enabled, apiKey)
|
|
656
|
+
.then(() => { })
|
|
657
|
+
.catch((err: Error) => Promise.reject(MPError.parse(err)));
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Downloads and caches base-map tiles so the map can render without a network connection.
|
|
662
|
+
*
|
|
663
|
+
* Covers every solution that base-map tile caching has been enabled for with
|
|
664
|
+
* {@link setBaseMapTilesEnabled}, unless {@link apiKeys} narrows it to a subset. This is a
|
|
665
|
+
* long-running network download that can take minutes - pass {@link onProgress} to follow it.
|
|
666
|
+
*
|
|
667
|
+
* This runs independently of {@link synchronizeContent} and {@link cacheData}, which cache the
|
|
668
|
+
* MapsIndoors content itself. Both are needed for a fully offline map.
|
|
669
|
+
*
|
|
670
|
+
* On iOS, a {@link MapView} has to have been mounted at least once first: the iOS SDK registers
|
|
671
|
+
* its base-map cache when it builds the map provider, and until then this rejects with
|
|
672
|
+
* {@link MPError.baseMapCachingNotSupported} even on Mapbox. Android has no such ordering
|
|
673
|
+
* requirement.
|
|
674
|
+
*
|
|
675
|
+
* Run one call at a time. Progress arrives on a single channel carrying only the fraction, with
|
|
676
|
+
* nothing identifying the call, so two overlapping calls interleave their progress - including
|
|
677
|
+
* into a caller that passed no {@link onProgress} of its own. The default already covers every
|
|
678
|
+
* enabled solution in one call, so there is rarely a reason to fan out.
|
|
679
|
+
*
|
|
680
|
+
* @public
|
|
681
|
+
* @static
|
|
682
|
+
* @async
|
|
683
|
+
* @param {OnBaseMapCacheProgressListener} [onProgress] Optional listener called with the
|
|
684
|
+
* fraction completed, from 0.0 to 1.0. Not every map provider reports progress.
|
|
685
|
+
* @param {string[]} [apiKeys] An optional list of solution API keys to narrow the operation to.
|
|
686
|
+
* Defaults to every solution with base-map tile caching enabled. An empty array narrows it to
|
|
687
|
+
* nothing and caches nothing, which is deliberately not the same as omitting the argument - a
|
|
688
|
+
* filter that matched no solutions should not turn into a download of all of them.
|
|
689
|
+
* @returns {Promise<void>} Rejects with a {@link MPError} if the map provider cannot cache
|
|
690
|
+
* base-map tiles ({@link MPError.baseMapCachingNotSupported}) or a download fails.
|
|
691
|
+
*/
|
|
692
|
+
public static async synchronizeBaseMapTiles(onProgress?: OnBaseMapCacheProgressListener, apiKeys?: string[]): Promise<void> {
|
|
693
|
+
let subscription: EmitterSubscription | undefined;
|
|
694
|
+
if (onProgress) {
|
|
695
|
+
// Subscribed before the call rather than in the module's constructor: the native side only
|
|
696
|
+
// emits while a download is running, and an always-live subscription would keep the JS
|
|
697
|
+
// callback alive for the lifetime of the app.
|
|
698
|
+
subscription = new NativeEventEmitter(MapsIndoorsModule)
|
|
699
|
+
.addListener(EventNames.onBaseMapCacheProgress, (event: { progress: number }) => onProgress(event.progress));
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// try/finally rather than .finally() on the chain: the native method is invoked before the
|
|
703
|
+
// chain exists, so a synchronous throw there - a JS package newer than the native one, whose
|
|
704
|
+
// module has no such method - would otherwise leave the subscription holding onProgress for
|
|
705
|
+
// the lifetime of the app. Only a rejection is parsed as an MPError; a synchronous throw is
|
|
706
|
+
// not ours to reinterpret, so it propagates as it is.
|
|
707
|
+
try {
|
|
708
|
+
return await MapsIndoorsModule.synchronizeBaseMapTiles(apiKeys ? apiKeys : null)
|
|
709
|
+
.then(() => { })
|
|
710
|
+
.catch((err: Error) => Promise.reject(MPError.parse(err)));
|
|
711
|
+
} finally {
|
|
712
|
+
subscription?.remove();
|
|
713
|
+
}
|
|
714
|
+
}
|
|
571
715
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listener that is invoked while base-map tiles are being cached for offline use.
|
|
3
|
+
*
|
|
4
|
+
* Caching base-map tiles is a long-running network download that can take minutes, so progress is
|
|
5
|
+
* reported as it goes. Progress is not guaranteed to reach 1.0 before
|
|
6
|
+
* {@link MapsIndoors.synchronizeBaseMapTiles} resolves, and it is not guaranteed to be reported at
|
|
7
|
+
* all - a map provider that cannot determine progress only reports completion.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @interface OnBaseMapCacheProgressListener
|
|
11
|
+
* @typedef {OnBaseMapCacheProgressListener}
|
|
12
|
+
*/
|
|
13
|
+
export interface OnBaseMapCacheProgressListener {
|
|
14
|
+
/**
|
|
15
|
+
* When the caching operation has progressed.
|
|
16
|
+
*
|
|
17
|
+
* @param {number} progress The fraction of the operation that has completed, from 0.0 to 1.0.
|
|
18
|
+
*/
|
|
19
|
+
(progress: number): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import MPBounds from '../MPBounds';
|
|
2
|
+
import MPPoint from '../MPPoint';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unit tests for MPBounds - centre, containment, the bbox order and the Builder.
|
|
6
|
+
*
|
|
7
|
+
* Like MPPoint, the ordering conventions are the risky part: fromBBox takes a GeoJSON bbox
|
|
8
|
+
* [west, south, east, north].
|
|
9
|
+
*/
|
|
10
|
+
describe('MPBounds', () => {
|
|
11
|
+
const southwest = new MPPoint(57.0, 9.9);
|
|
12
|
+
const northeast = new MPPoint(57.1, 10.0);
|
|
13
|
+
const bounds = new MPBounds(northeast, southwest);
|
|
14
|
+
|
|
15
|
+
describe('center', () => {
|
|
16
|
+
it('is the midpoint of the corners', () => {
|
|
17
|
+
const center = bounds.center;
|
|
18
|
+
|
|
19
|
+
expect(center.latitude).toBeCloseTo(57.05, 10);
|
|
20
|
+
expect(center.longitude).toBeCloseTo(9.95, 10);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('contains', () => {
|
|
25
|
+
it('accepts a point inside', () => {
|
|
26
|
+
expect(bounds.contains(new MPPoint(57.05, 9.95))).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('accepts the corners, so the bounds are inclusive', () => {
|
|
30
|
+
expect(bounds.contains(southwest)).toBe(true);
|
|
31
|
+
expect(bounds.contains(northeast)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it.each([
|
|
35
|
+
['north of', new MPPoint(57.2, 9.95)],
|
|
36
|
+
['south of', new MPPoint(56.9, 9.95)],
|
|
37
|
+
['east of', new MPPoint(57.05, 10.5)],
|
|
38
|
+
['west of', new MPPoint(57.05, 9.5)],
|
|
39
|
+
])('rejects a point %s the bounds', (_label, point) => {
|
|
40
|
+
expect(bounds.contains(point)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('fromBBox', () => {
|
|
45
|
+
it('reads GeoJSON bbox order, [west, south, east, north]', () => {
|
|
46
|
+
const fromBBox = MPBounds.fromBBox([9.9, 57.0, 10.0, 57.1]);
|
|
47
|
+
|
|
48
|
+
expect(fromBBox.southwest.latitude).toBe(57.0);
|
|
49
|
+
expect(fromBBox.southwest.longitude).toBe(9.9);
|
|
50
|
+
expect(fromBBox.northeast.latitude).toBe(57.1);
|
|
51
|
+
expect(fromBBox.northeast.longitude).toBe(10.0);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('create', () => {
|
|
56
|
+
it('keeps the corners it is given', () => {
|
|
57
|
+
const created = MPBounds.create({ southwest, northeast });
|
|
58
|
+
|
|
59
|
+
expect(created.southwest).toBe(southwest);
|
|
60
|
+
expect(created.northeast).toBe(northeast);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('Builder', () => {
|
|
65
|
+
it('grows to enclose every included point', () => {
|
|
66
|
+
const builder = new MPBounds.Builder();
|
|
67
|
+
builder.include(new MPPoint(57.0, 9.9));
|
|
68
|
+
builder.include(new MPPoint(57.1, 10.0));
|
|
69
|
+
builder.include(new MPPoint(57.05, 9.95));
|
|
70
|
+
|
|
71
|
+
const built = builder.build();
|
|
72
|
+
|
|
73
|
+
expect(built.southwest.latitude).toBe(57.0);
|
|
74
|
+
expect(built.southwest.longitude).toBe(9.9);
|
|
75
|
+
expect(built.northeast.latitude).toBe(57.1);
|
|
76
|
+
expect(built.northeast.longitude).toBe(10.0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('encloses a single point as a degenerate box', () => {
|
|
80
|
+
const builder = new MPBounds.Builder();
|
|
81
|
+
builder.include(new MPPoint(57.0, 9.9));
|
|
82
|
+
|
|
83
|
+
const built = builder.build();
|
|
84
|
+
|
|
85
|
+
expect(built.southwest.latitude).toBe(57.0);
|
|
86
|
+
expect(built.northeast.latitude).toBe(57.0);
|
|
87
|
+
expect(built.contains(new MPPoint(57.0, 9.9))).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* build() means to reject an empty builder, but the guard compares `north` against
|
|
92
|
+
* POSITIVE_INFINITY while the field is initialised to NEGATIVE_INFINITY, so it never fires and
|
|
93
|
+
* an all-infinities MPBounds is returned instead.
|
|
94
|
+
*
|
|
95
|
+
* Marked `failing` so the bug is documented and tracked without turning the suite red - the
|
|
96
|
+
* test starts failing (and so demands attention) the moment the guard is fixed.
|
|
97
|
+
*/
|
|
98
|
+
it.failing('rejects building with no coordinates', () => {
|
|
99
|
+
expect(() => new MPBounds.Builder().build()).toThrow('Cannot build bounds with no coordinates');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('currently returns infinite bounds for an empty builder', () => {
|
|
103
|
+
const built = new MPBounds.Builder().build();
|
|
104
|
+
|
|
105
|
+
expect(built.northeast.latitude).toBe(Number.NEGATIVE_INFINITY);
|
|
106
|
+
expect(built.southwest.latitude).toBe(Number.POSITIVE_INFINITY);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|